test(i18n): cover language preference persistence
This commit is contained in:
1 parent
ca116d6cce
commit
9c571b5f9c
1 file changed
+15
@@ -72,10 +72,25 @@ assert.equal(localeContext.LifeI18n.language(), "zh", "cloud settings cannot ove
|
|||||||
localeContext.setLanguage("en");
|
localeContext.setLanguage("en");
|
||||||
assert.equal(localeContext.LifeI18n.language(), "en", "manual English choice overrides browser language");
|
assert.equal(localeContext.LifeI18n.language(), "en", "manual English choice overrides browser language");
|
||||||
assert.equal(localeContext.LifeI18n.t("app.today"), "TODAY");
|
assert.equal(localeContext.LifeI18n.t("app.today"), "TODAY");
|
||||||
|
const reloadedManualContext = vm.createContext({
|
||||||
|
navigator: { languages: ["en-US"] }, localStorage: makeStorage(),
|
||||||
|
LifeOSLocales: { en: assets.localeEn, "zh-CN": assets.localeZh },
|
||||||
|
});
|
||||||
|
reloadedManualContext.window = reloadedManualContext;
|
||||||
|
vm.runInContext(assets.i18nJs, reloadedManualContext);
|
||||||
|
assert.equal(reloadedManualContext.LifeI18n.language(), "en", "a reloaded page starts in automatic mode when no manual choice was saved");
|
||||||
localeContext.navigator.languages = ["zh-CN"];
|
localeContext.navigator.languages = ["zh-CN"];
|
||||||
localeContext.setLanguage("auto");
|
localeContext.setLanguage("auto");
|
||||||
assert.equal(localeContext.LifeI18n.preference(), "auto");
|
assert.equal(localeContext.LifeI18n.preference(), "auto");
|
||||||
assert.equal(localeContext.LifeI18n.language(), "zh", "auto mode ignores stale cloud preference and follows this device");
|
assert.equal(localeContext.LifeI18n.language(), "zh", "auto mode ignores stale cloud preference and follows this device");
|
||||||
|
localeContext.setLanguage("en");
|
||||||
|
const persistedManualContext = vm.createContext({
|
||||||
|
navigator: { languages: ["zh-CN"] }, localStorage,
|
||||||
|
LifeOSLocales: { en: assets.localeEn, "zh-CN": assets.localeZh },
|
||||||
|
});
|
||||||
|
persistedManualContext.window = persistedManualContext;
|
||||||
|
vm.runInContext(assets.i18nJs, persistedManualContext);
|
||||||
|
assert.equal(persistedManualContext.LifeI18n.language(), "en", "a manually selected language persists across reloads");
|
||||||
const migratedStorage = makeStorage({ lifeos_settings: JSON.stringify({ language: "zh" }) });
|
const migratedStorage = makeStorage({ lifeos_settings: JSON.stringify({ language: "zh" }) });
|
||||||
const migratedContext = vm.createContext({
|
const migratedContext = vm.createContext({
|
||||||
navigator: { languages: ["en-US"] }, localStorage: migratedStorage,
|
navigator: { languages: ["en-US"] }, localStorage: migratedStorage,
|
||||||
|
|||||||
Reference in new issue
Block a user