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: "",
siteDesc: "",
bg: {
url: "",
repeat: "",
position: "",
align: "",
url: "clientCfg_bg_url",
repeat: "clientCfg_bg_repeat",
position: "clientCfg_bg_position",
align: "clientCfg_bg_align",
},
}
},

View file

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

View file

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

View file

@ -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<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: "",
lanPackURL: "",
lan: "en_US",
}
},
admin: {

View file

@ -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<boolean> => {
@ -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<number> => {
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;