fix(fe/test): fix unit test fail and add ui, preference check

This commit is contained in:
hexxa 2021-10-20 11:10:03 +08:00 committed by Hexxa
parent b64c9093e8
commit dd1279ed2b
6 changed files with 52 additions and 29 deletions

View file

@ -20,10 +20,10 @@ export const resps = {
siteName: "", siteName: "",
siteDesc: "", siteDesc: "",
bg: { bg: {
url: "", url: "clientCfg_bg_url",
repeat: "", repeat: "clientCfg_bg_repeat",
position: "", position: "clientCfg_bg_position",
align: "", align: "clientCfg_bg_align",
}, },
} }
}, },

View file

@ -91,6 +91,7 @@ export const resps = {
}, },
cssURL: "cssURL", cssURL: "cssURL",
lanPackURL: "lanPackURL", lanPackURL: "lanPackURL",
lan: "en_US",
}, },
}, },
}, },

View file

@ -79,6 +79,7 @@ describe("Login", () => {
}, },
cssURL: "cssURL", cssURL: "cssURL",
lanPackURL: "lanPackURL", lanPackURL: "lanPackURL",
lan: "en_US",
}, },
}); });

View file

@ -12,6 +12,7 @@ import {
} from "../../client/settings_mock"; } from "../../client/settings_mock";
import { ICoreState, newState } from "../core_state"; import { ICoreState, newState } from "../core_state";
import { MockWorker, UploadState, UploadEntry } from "../../worker/interface"; import { MockWorker, UploadState, UploadEntry } from "../../worker/interface";
import { MsgPackage } from "../../i18n/msger";
describe("State Manager", () => { describe("State Manager", () => {
test("initUpdater for admin", async () => { test("initUpdater for admin", async () => {
@ -91,6 +92,7 @@ describe("State Manager", () => {
}, },
cssURL: "cssURL", cssURL: "cssURL",
lanPackURL: "lanPackURL", lanPackURL: "lanPackURL",
lan: "en_US",
}, },
}); });
@ -109,9 +111,17 @@ describe("State Manager", () => {
users: usersMap, users: usersMap,
roles: roles, 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 usersCl = new MockUsersClient("");
const filesCl = new MockFilesClient(""); const filesCl = new MockFilesClient("");
const settingsCl = new MockSettingsClient(""); const settingsCl = new MockSettingsClient("");
@ -130,13 +140,14 @@ describe("State Manager", () => {
}, },
preferences: { preferences: {
bg: { bg: {
url: "bgUrl", url: "",
repeat: "bgRepeat", repeat: "",
position: "bgPosition", position: "",
align: "bgAlign", align: "",
}, },
cssURL: "cssURL", cssURL: "",
lanPackURL: "lanPackURL", lanPackURL: "",
lan: "en_US",
}, },
}, },
}; };
@ -148,8 +159,6 @@ describe("State Manager", () => {
}; };
usersCl.setMock(mockUserResps); usersCl.setMock(mockUserResps);
const mockWorkerClass = mock(MockWorker);
const mockWorker = instance(mockWorkerClass);
const coreState = newState(); const coreState = newState();
const mgr = new StateMgr({}); // it will call initUpdater const mgr = new StateMgr({}); // it will call initUpdater
@ -189,13 +198,14 @@ describe("State Manager", () => {
captchaID: "", captchaID: "",
preferences: { preferences: {
bg: { bg: {
url: "bgUrl", url: "",
repeat: "bgRepeat", repeat: "",
position: "bgPosition", position: "",
align: "bgAlign", align: "",
}, },
cssURL: "cssURL", cssURL: "",
lanPackURL: "lanPackURL", lanPackURL: "",
lan: "en_US",
}, },
}); });
@ -204,5 +214,13 @@ describe("State Manager", () => {
users: Map({}), users: Map({}),
roles: Set<string>(), roles: Set<string>(),
}); });
// 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);
}); });
}); });

View file

@ -77,6 +77,7 @@ export function initState(): ICoreState {
}, },
cssURL: "", cssURL: "",
lanPackURL: "", lanPackURL: "",
lan: "en_US",
} }
}, },
admin: { admin: {

View file

@ -383,6 +383,17 @@ export class Updater {
downloadSpeedLimit: 0, downloadSpeedLimit: 0,
spaceLimit: "0", spaceLimit: "0",
}; };
this.props.login.preferences = {
bg: {
url: "",
repeat: "",
position: "",
align: "",
},
cssURL: "",
lanPackURL: "",
lan: "en_US",
};
}; };
self = async (): Promise<boolean> => { self = async (): Promise<boolean> => {
@ -531,13 +542,11 @@ export class Updater {
this.props.msg.lan = "en_US"; this.props.msg.lan = "en_US";
this.props.msg.pkg = MsgPackage.get(lan); this.props.msg.pkg = MsgPackage.get(lan);
this.props.login.preferences.lan = "en_US"; this.props.login.preferences.lan = "en_US";
this.props.login.preferences.lanPackURL = "";
break; break;
case "zh_CN": case "zh_CN":
this.props.msg.lan = "zh_CN"; this.props.msg.lan = "zh_CN";
this.props.msg.pkg = MsgPackage.get(lan); this.props.msg.pkg = MsgPackage.get(lan);
this.props.login.preferences.lan = "zh_CN"; this.props.login.preferences.lan = "zh_CN";
this.props.login.preferences.lanPackURL = "";
break; break;
default: default:
alertMsg("language package not found"); alertMsg("language package not found");
@ -603,12 +612,6 @@ export class Updater {
return resp.status; 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<number> => { fetchLanPack = async (): Promise<number> => {
const url = this.props.login.preferences.lanPackURL; const url = this.props.login.preferences.lanPackURL;
if (url === "") { if (url === "") {
@ -636,7 +639,6 @@ export class Updater {
if (!isValid) { if (!isValid) {
this.props.msg.lan = "en_US"; this.props.msg.lan = "en_US";
this.props.msg.pkg = MsgPackage.get("en_US"); this.props.msg.pkg = MsgPackage.get("en_US");
this.props.login.preferences.lanPackURL = "";
return 400; return 400;
} }
this.props.msg.lan = resp.data.lan; this.props.msg.lan = resp.data.lan;