M1.10: light theme, live theme switching, editor tokens
- theme::LIGHT next to DARK with the 10 new tokens (editor selection, active line, cursor, gutter, match, font size, tab active/modified, notice); light fg-muted, accent and error darkened for WCAG AA - theme.list, theme.systemPreference, themeChanged event when the resolved theme changes (settings.set/reset appearance.theme, or the OS preference in system mode) - desktop init script and window background from the stored setting; system mode uses a prefers-color-scheme media query for the first frame - ui/src/theme.ts applies tokens to :root and color-scheme live; editor, tabs and notice drop their var() fallbacks - Vitest WCAG AA contrast check against a Rust-maintained snapshot, DOM tests, headless control-channel test - docs: architecture Themes, parity rows, ui-parity, gaps, roadmaps Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
1ab448de4d
commit
cde6e119c6
29 changed files with 1192 additions and 72 deletions
154
crates/engine/tests/theme.rs
Normal file
154
crates/engine/tests/theme.rs
Normal file
|
|
@ -0,0 +1,154 @@
|
|||
//! Theme commands and `themeChanged`: switching through `settings.set`, the
|
||||
//! "system" mode following the reported OS preference, and the stored theme
|
||||
//! surviving a restart.
|
||||
|
||||
#![allow(
|
||||
clippy::unwrap_used,
|
||||
clippy::expect_used,
|
||||
clippy::panic,
|
||||
clippy::indexing_slicing
|
||||
)]
|
||||
|
||||
use lutra_engine::{Engine, EngineConfig, Event, theme};
|
||||
use serde_json::{Value, json};
|
||||
use tempfile::TempDir;
|
||||
|
||||
fn themes(events: &[Event]) -> Vec<(String, bool)> {
|
||||
events
|
||||
.iter()
|
||||
.filter_map(|e| match e {
|
||||
Event::ThemeChanged { id, dark, .. } => Some((id.clone(), *dark)),
|
||||
_ => None,
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn set_theme(engine: &mut Engine, value: &str) -> Vec<(String, bool)> {
|
||||
let outcome = engine
|
||||
.execute(
|
||||
"settings.set",
|
||||
json!({"key": "appearance.theme", "value": value}),
|
||||
)
|
||||
.unwrap();
|
||||
themes(&outcome.events)
|
||||
}
|
||||
|
||||
fn report(engine: &mut Engine, dark: bool) -> (Value, Vec<(String, bool)>) {
|
||||
let outcome = engine
|
||||
.execute("theme.systemPreference", json!({"dark": dark}))
|
||||
.unwrap();
|
||||
let events = themes(&outcome.events);
|
||||
(outcome.value, events)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn list_names_the_builtin_themes_by_catalog_key() {
|
||||
let mut e = Engine::new().unwrap();
|
||||
let list = e.execute("theme.list", Value::Null).unwrap().value;
|
||||
assert_eq!(
|
||||
list,
|
||||
json!([
|
||||
{"id": "lutra-dark", "label": "theme.lutraDark", "dark": true},
|
||||
{"id": "lutra-light", "label": "theme.lutraLight", "dark": false},
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn switching_the_setting_emits_the_new_tokens() {
|
||||
let mut e = Engine::new().unwrap();
|
||||
let outcome = e
|
||||
.execute(
|
||||
"settings.set",
|
||||
json!({"key": "appearance.theme", "value": "lutra-light"}),
|
||||
)
|
||||
.unwrap();
|
||||
let Some(Event::ThemeChanged { id, dark, tokens }) = outcome
|
||||
.events
|
||||
.iter()
|
||||
.find(|e| matches!(e, Event::ThemeChanged { .. }))
|
||||
else {
|
||||
panic!("no themeChanged in {:?}", outcome.events);
|
||||
};
|
||||
assert_eq!(id, "lutra-light");
|
||||
assert!(!dark);
|
||||
assert_eq!(tokens, &theme::token_map(&theme::LIGHT));
|
||||
assert_eq!(tokens["--lt-bg"], "#f4f1ec");
|
||||
assert_eq!(tokens["--lt-font-size-editor"], "14px");
|
||||
assert!(matches!(
|
||||
outcome.events.first(),
|
||||
Some(Event::SettingsChanged { .. })
|
||||
));
|
||||
|
||||
assert_eq!(set_theme(&mut e, "lutra-light"), []);
|
||||
assert_eq!(
|
||||
set_theme(&mut e, "lutra-dark"),
|
||||
[("lutra-dark".into(), true)]
|
||||
);
|
||||
let reset = e
|
||||
.execute("settings.reset", json!({"key": "appearance.theme"}))
|
||||
.unwrap();
|
||||
assert_eq!(themes(&reset.events), []);
|
||||
let other = e
|
||||
.execute(
|
||||
"settings.set",
|
||||
json!({"key": "editor.fontSize", "value": 18}),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(themes(&other.events), []);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn system_mode_follows_the_reported_preference() {
|
||||
let mut e = Engine::new().unwrap();
|
||||
let (value, events) = report(&mut e, true);
|
||||
assert_eq!(events, []);
|
||||
assert_eq!(value["id"], "lutra-dark");
|
||||
assert_eq!(value["dark"], true);
|
||||
assert_eq!(value["tokens"]["--lt-bg"], "#1f1d1b");
|
||||
assert!(value.get("kind").is_none());
|
||||
|
||||
let (value, events) = report(&mut e, false);
|
||||
assert_eq!(events, [("lutra-light".into(), false)]);
|
||||
assert_eq!(value["id"], "lutra-light");
|
||||
assert_eq!(report(&mut e, false).1, []);
|
||||
|
||||
assert_eq!(
|
||||
set_theme(&mut e, "lutra-dark"),
|
||||
[("lutra-dark".into(), true)]
|
||||
);
|
||||
let (value, events) = report(&mut e, true);
|
||||
assert_eq!(events, []);
|
||||
assert_eq!(report(&mut e, false).1, []);
|
||||
assert_eq!(value["id"], "lutra-dark");
|
||||
|
||||
assert_eq!(set_theme(&mut e, "system"), [("lutra-light".into(), false)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_bad_preference_params() {
|
||||
let mut e = Engine::new().unwrap();
|
||||
for params in [
|
||||
json!({}),
|
||||
json!({"dark": "yes"}),
|
||||
json!({"dark": true, "x": 1}),
|
||||
] {
|
||||
let err = e.execute("theme.systemPreference", params).unwrap_err();
|
||||
assert_eq!(err.code(), "invalid_params");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_stored_theme_survives_a_restart() {
|
||||
let dir = TempDir::new().unwrap();
|
||||
let config = EngineConfig {
|
||||
config_dir: dir.path().join("config"),
|
||||
data_dir: dir.path().join("data"),
|
||||
};
|
||||
let mut e = Engine::with_config(config.clone()).unwrap();
|
||||
set_theme(&mut e, "lutra-light");
|
||||
drop(e);
|
||||
let mut e = Engine::with_config(config).unwrap();
|
||||
let (value, _) = report(&mut e, true);
|
||||
assert_eq!(value["id"], "lutra-light");
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue