mirror of
https://github.com/storytold/effectcraft.git
synced 2026-11-15 06:42:31 +00:00
Tests: Match System resolves to English in ui-egui test builds
Fixes #3244. The ui-egui tests look up English labels, but Session::default() keeps the language pref "system", so on a German (or any non-English) system they read translated labels and fail. Match System now resolves to English under cfg(test) (lib tests) and under a new test-only `test-support` feature, which the crate's own dev-dependency on itself turns on for tests/it, examples and workspace test builds. Product builds are unchanged; tests about a translation still set their language explicitly. The Match System test now asserts the English pin explicitly.
This commit is contained in:
1 parent
bb2d2005ce
commit
c54b542274
3 files changed
+34
-7
No files matched your search
Generated
+1
@@ -1988,6 +1988,7 @@ dependencies = [
|
||||
"effectcraft-segment",
|
||||
"effectcraft-text",
|
||||
"effectcraft-time",
|
||||
"effectcraft-ui-egui",
|
||||
"eframe",
|
||||
"egui",
|
||||
"egui_extras",
|
||||
|
||||
@@ -45,7 +45,17 @@ craft-update = { workspace = true }
|
||||
pollster = { workspace = true }
|
||||
sys-locale = { workspace = true }
|
||||
|
||||
[features]
|
||||
# Tests only, never enable in a product: Settings ▸ General ▸ Language ▸ Match System resolves to
|
||||
# English, so English label lookups pass on any system language (#3244). The self dev-dependency
|
||||
# below turns it on wherever dev-dependencies are built: this crate's integration tests, its
|
||||
# examples (`snapshot` shots are deterministic English unless a step sets a language) and
|
||||
# workspace test builds of the apps (`cargo test --workspace`).
|
||||
test-support = []
|
||||
|
||||
[dev-dependencies]
|
||||
# This crate's own integration tests build it with `test-support` (see `[features]`).
|
||||
effectcraft-ui-egui = { workspace = true, features = ["test-support"] }
|
||||
# Fonts for kittest: the workspace `egui` features are what test roots resolve, but stating them
|
||||
# here documents the requirement (kittest's own dev-dependencies do not propagate to consumers).
|
||||
egui = { workspace = true, features = ["default_fonts", "monochrome_emoji_fonts"] }
|
||||
|
||||
@@ -84,7 +84,14 @@ pub(crate) fn swedish(app: &EffectcraftApp) -> bool {
|
||||
/// Settings ▸ General ▸ Language ▸ Match System: the operating system's interface language
|
||||
/// where EffectCraft has it, else English (#229), as After Effects installs in the system's
|
||||
/// language. The browser build follows the locales its page passes in ([`set_system_locales`]).
|
||||
///
|
||||
/// Test builds (this crate's unit tests, and its integration tests through the `test-support`
|
||||
/// feature) resolve Match System to English, so tests that look up English labels pass on any
|
||||
/// system language (#3244); tests about a translation choose their language explicitly.
|
||||
fn system_language() -> &'static str {
|
||||
if cfg!(any(test, feature = "test-support")) {
|
||||
return "en";
|
||||
}
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
{
|
||||
static LANGUAGE: std::sync::OnceLock<&'static str> = std::sync::OnceLock::new();
|
||||
@@ -9169,13 +9176,22 @@ mod tests {
|
||||
}
|
||||
let mut app = EffectcraftApp::new(effectcraft_engine::Session::default());
|
||||
assert_eq!(app.session.prefs.general.language, "system", "the default");
|
||||
assert_eq!(japanese(&app), system_language() == "ja");
|
||||
assert_eq!(simplified(&app), system_language() == "zh-hans");
|
||||
assert_eq!(traditional(&app), system_language() == "zh-hant");
|
||||
assert_eq!(spanish(&app), system_language() == "es");
|
||||
assert_eq!(czech(&app), system_language() == "cs");
|
||||
assert_eq!(polish(&app), system_language() == "pl");
|
||||
assert_eq!(swedish(&app), system_language() == "sv");
|
||||
assert_eq!(system_language(), "en", "test builds pin Match System to English (#3244)");
|
||||
assert_eq!(language(&app), "en");
|
||||
for (flag, name) in [
|
||||
(japanese(&app), "ja"),
|
||||
(simplified(&app), "zh-hans"),
|
||||
(traditional(&app), "zh-hant"),
|
||||
(ukrainian(&app), "uk"),
|
||||
(spanish(&app), "es"),
|
||||
(brazilian_portuguese(&app), "pt-br"),
|
||||
(czech(&app), "cs"),
|
||||
(polish(&app), "pl"),
|
||||
(georgian(&app), "ka"),
|
||||
(swedish(&app), "sv"),
|
||||
] {
|
||||
assert!(!flag, "Match System shows {name} in a test build");
|
||||
}
|
||||
app.session.execute("prefs.set", json!({"key":"general.language", "value":"ja"})).unwrap();
|
||||
assert!(japanese(&app));
|
||||
app.session.execute("prefs.set", json!({"key":"general.language", "value":"zh-hans"})).unwrap();
|
||||
|
||||
Reference in new issue
Block a user