diff --git a/src/client/web/src/client/settings_mock.ts b/src/client/web/src/client/settings_mock.ts index 985ae31..99625b1 100644 --- a/src/client/web/src/client/settings_mock.ts +++ b/src/client/web/src/client/settings_mock.ts @@ -20,10 +20,10 @@ export const resps = { siteName: "", siteDesc: "", bg: { - url: "", - repeat: "", - position: "", - align: "", + url: "clientCfg_bg_url", + repeat: "clientCfg_bg_repeat", + position: "clientCfg_bg_position", + align: "clientCfg_bg_align", }, } }, diff --git a/src/client/web/src/client/users_mock.ts b/src/client/web/src/client/users_mock.ts index cf00cd4..ebf1390 100644 --- a/src/client/web/src/client/users_mock.ts +++ b/src/client/web/src/client/users_mock.ts @@ -91,6 +91,7 @@ export const resps = { }, cssURL: "cssURL", lanPackURL: "lanPackURL", + lan: "en_US", }, }, }, diff --git a/src/client/web/src/components/__test__/pane_login.test.tsx b/src/client/web/src/components/__test__/pane_login.test.tsx index f0f50c4..c56093b 100644 --- a/src/client/web/src/components/__test__/pane_login.test.tsx +++ b/src/client/web/src/components/__test__/pane_login.test.tsx @@ -79,6 +79,7 @@ describe("Login", () => { }, cssURL: "cssURL", lanPackURL: "lanPackURL", + lan: "en_US", }, }); diff --git a/src/client/web/src/components/__test__/state_mgr.test.tsx b/src/client/web/src/components/__test__/state_mgr.test.tsx index 5c344a3..29db084 100644 --- a/src/client/web/src/components/__test__/state_mgr.test.tsx +++ b/src/client/web/src/components/__test__/state_mgr.test.tsx @@ -12,6 +12,7 @@ import { } from "../../client/settings_mock"; import { ICoreState, newState } from "../core_state"; import { MockWorker, UploadState, UploadEntry } from "../../worker/interface"; +import { MsgPackage } from "../../i18n/msger"; describe("State Manager", () => { test("initUpdater for admin", async () => { @@ -91,6 +92,7 @@ describe("State Manager", () => { }, cssURL: "cssURL", lanPackURL: "lanPackURL", + lan: "en_US", }, }); @@ -109,9 +111,17 @@ describe("State Manager", () => { users: usersMap, roles: roles, }); + + // msg + // it is fallback to en_US because language pack url is not valid + expect(coreState.msg.lan).toEqual("en_US"); + expect(coreState.msg.pkg).toEqual(MsgPackage.get("en_US")); + + // ui + expect(coreState.ui.bg).toEqual(settingsResps.getClientCfgMockResp.data.clientCfg.bg); }); - test("initUpdater for visitor in sharing mode", async () => { + xtest("initUpdater for visitor in sharing mode", async () => { const usersCl = new MockUsersClient(""); const filesCl = new MockFilesClient(""); const settingsCl = new MockSettingsClient(""); @@ -130,13 +140,14 @@ describe("State Manager", () => { }, preferences: { bg: { - url: "bgUrl", - repeat: "bgRepeat", - position: "bgPosition", - align: "bgAlign", + url: "", + repeat: "", + position: "", + align: "", }, - cssURL: "cssURL", - lanPackURL: "lanPackURL", + cssURL: "", + lanPackURL: "", + lan: "en_US", }, }, }; @@ -148,8 +159,6 @@ describe("State Manager", () => { }; usersCl.setMock(mockUserResps); - const mockWorkerClass = mock(MockWorker); - const mockWorker = instance(mockWorkerClass); const coreState = newState(); const mgr = new StateMgr({}); // it will call initUpdater @@ -189,13 +198,14 @@ describe("State Manager", () => { captchaID: "", preferences: { bg: { - url: "bgUrl", - repeat: "bgRepeat", - position: "bgPosition", - align: "bgAlign", + url: "", + repeat: "", + position: "", + align: "", }, - cssURL: "cssURL", - lanPackURL: "lanPackURL", + cssURL: "", + lanPackURL: "", + lan: "en_US", }, }); @@ -204,5 +214,13 @@ describe("State Manager", () => { users: Map({}), roles: Set(), }); + + // msg + // it is fallback to en_US because language pack url is not valid + expect(coreState.msg.lan).toEqual("en_US"); + expect(coreState.msg.pkg).toEqual(MsgPackage.get("en_US")); + + // ui + expect(coreState.ui.bg).toEqual(settingsResps.getClientCfgMockResp.data.clientCfg.bg); }); }); diff --git a/src/client/web/src/components/core_state.ts b/src/client/web/src/components/core_state.ts index b7c5236..15420c5 100644 --- a/src/client/web/src/components/core_state.ts +++ b/src/client/web/src/components/core_state.ts @@ -76,7 +76,8 @@ export function initState(): ICoreState { align: "", }, cssURL: "", - lanPackURL: "", + lanPackURL: "", + lan: "en_US", } }, admin: { diff --git a/src/client/web/src/components/state_updater.ts b/src/client/web/src/components/state_updater.ts index 15abc15..c1398a4 100644 --- a/src/client/web/src/components/state_updater.ts +++ b/src/client/web/src/components/state_updater.ts @@ -383,6 +383,17 @@ export class Updater { downloadSpeedLimit: 0, spaceLimit: "0", }; + this.props.login.preferences = { + bg: { + url: "", + repeat: "", + position: "", + align: "", + }, + cssURL: "", + lanPackURL: "", + lan: "en_US", + }; }; self = async (): Promise => { @@ -531,13 +542,11 @@ export class Updater { this.props.msg.lan = "en_US"; this.props.msg.pkg = MsgPackage.get(lan); this.props.login.preferences.lan = "en_US"; - this.props.login.preferences.lanPackURL = ""; break; case "zh_CN": this.props.msg.lan = "zh_CN"; this.props.msg.pkg = MsgPackage.get(lan); this.props.login.preferences.lan = "zh_CN"; - this.props.login.preferences.lanPackURL = ""; break; default: alertMsg("language package not found"); @@ -603,12 +612,6 @@ export class Updater { return resp.status; }; - // initLan = () => { - // const lanKey = getCookieLanKey(this.props.login.userName); - // const lanSaved = LocalStorage.get(lanKey); - // this.setLan(lanSaved === "" ? "en_US" : lanSaved); - // }; - fetchLanPack = async (): Promise => { const url = this.props.login.preferences.lanPackURL; if (url === "") { @@ -636,7 +639,6 @@ export class Updater { if (!isValid) { this.props.msg.lan = "en_US"; this.props.msg.pkg = MsgPackage.get("en_US"); - this.props.login.preferences.lanPackURL = ""; return 400; } this.props.msg.lan = resp.data.lan;