test(topbar): add test for topbar
This commit is contained in:
parent
9a526736bb
commit
e4e53b15f2
5 changed files with 148 additions and 3 deletions
|
@ -7,5 +7,10 @@ export function alertMsg(msg: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function confirmMsg(msg: string): boolean {
|
export function confirmMsg(msg: string): boolean {
|
||||||
return confirm(msg);
|
try {
|
||||||
|
return confirm(msg);
|
||||||
|
} catch (e) {
|
||||||
|
console.log(`${msg}: yes (confirm is not implemented)`);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
139
src/client/web/src/components/__test__/topbar.test.tsx
Normal file
139
src/client/web/src/components/__test__/topbar.test.tsx
Normal file
|
@ -0,0 +1,139 @@
|
||||||
|
import { List, Set, Map } from "immutable";
|
||||||
|
import { mock, instance } from "ts-mockito";
|
||||||
|
|
||||||
|
import { TopBar } from "../topbar";
|
||||||
|
import { initUploadMgr } from "../../worker/upload_mgr";
|
||||||
|
import { ICoreState, newState } from "../core_state";
|
||||||
|
import { updater } from "../state_updater";
|
||||||
|
import { MockWorker } from "../../worker/interface";
|
||||||
|
import { MockUsersClient, resps as usersResps } from "../../client/users_mock";
|
||||||
|
import { MockFilesClient, resps as filesResps } from "../../client/files_mock";
|
||||||
|
import { MockSettingsClient } from "../../client/settings_mock";
|
||||||
|
|
||||||
|
import { UploadInfo, visitorID, roleVisitor, MetadataResp } from "../../client";
|
||||||
|
import { UploadEntry, UploadState } from "../../worker/interface";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
describe("TopBar", () => {
|
||||||
|
test("logout as visitor without sharing", async () => {
|
||||||
|
const mockWorkerClass = mock(MockWorker);
|
||||||
|
const mockWorker = instance(mockWorkerClass);
|
||||||
|
initUploadMgr(mockWorker);
|
||||||
|
|
||||||
|
const coreState = newState();
|
||||||
|
|
||||||
|
const isSharingMockResp = { status: 404, statusText: "", data: {} };
|
||||||
|
const listSharingsMockResp = {
|
||||||
|
status: 401,
|
||||||
|
statusText: "",
|
||||||
|
data: {
|
||||||
|
sharingDirs: new Array<string>(),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const listUploadingsMockResp = {
|
||||||
|
status: 401,
|
||||||
|
statusText: "",
|
||||||
|
data: { uploadInfos: new Array<UploadInfo>() },
|
||||||
|
};
|
||||||
|
const listHomeMockResp = {
|
||||||
|
status: 401,
|
||||||
|
statusText: "",
|
||||||
|
data: { cwd: "", metadatas: new Array<MetadataResp>() }
|
||||||
|
};
|
||||||
|
const mockFileResps = {
|
||||||
|
...filesResps,
|
||||||
|
listHomeMockResp,
|
||||||
|
isSharingMockResp,
|
||||||
|
listSharingsMockResp,
|
||||||
|
listUploadingsMockResp,
|
||||||
|
}
|
||||||
|
|
||||||
|
const selfMockResp = {
|
||||||
|
status: 401,
|
||||||
|
statusText: "",
|
||||||
|
data: {
|
||||||
|
id: visitorID,
|
||||||
|
name: "visitor",
|
||||||
|
role: roleVisitor,
|
||||||
|
usedSpace: "0",
|
||||||
|
quota: {
|
||||||
|
spaceLimit: "0",
|
||||||
|
uploadSpeedLimit: 0,
|
||||||
|
downloadSpeedLimit: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
const isAuthedMockResp = { status: 401, statusText: "", data: {} };
|
||||||
|
const mockUserResps = {
|
||||||
|
...usersResps,
|
||||||
|
selfMockResp,
|
||||||
|
isAuthedMockResp,
|
||||||
|
};
|
||||||
|
|
||||||
|
const filesCl = new MockFilesClient("");
|
||||||
|
filesCl.setMock(mockFileResps);
|
||||||
|
const usersCl = new MockUsersClient("");
|
||||||
|
usersCl.setMock(mockUserResps);
|
||||||
|
const settingsCl = new MockSettingsClient("");
|
||||||
|
|
||||||
|
updater().init(coreState);
|
||||||
|
updater().setClients(usersCl, filesCl, settingsCl);
|
||||||
|
|
||||||
|
const topbar = new TopBar({
|
||||||
|
login: coreState.login,
|
||||||
|
panes: coreState.panes,
|
||||||
|
msg: coreState.msg,
|
||||||
|
update: (updater: (prevState: ICoreState) => ICoreState) => { },
|
||||||
|
});
|
||||||
|
|
||||||
|
await topbar.logout();
|
||||||
|
|
||||||
|
// browser
|
||||||
|
expect(coreState.browser.dirPath.join("/")).toEqual(mockFileResps.listHomeMockResp.data.cwd);
|
||||||
|
expect(coreState.browser.isSharing).toEqual(false);
|
||||||
|
expect(coreState.browser.sharings).toEqual(List());
|
||||||
|
expect(coreState.browser.uploadings).toEqual(List<UploadEntry>());
|
||||||
|
expect(coreState.browser.items).toEqual(List());
|
||||||
|
|
||||||
|
// panes
|
||||||
|
expect(coreState.panes).toEqual({
|
||||||
|
displaying: "login",
|
||||||
|
paneNames: Set(["login"]),
|
||||||
|
});
|
||||||
|
|
||||||
|
// login
|
||||||
|
expect(coreState.login).toEqual({
|
||||||
|
userID: visitorID,
|
||||||
|
userName: "visitor",
|
||||||
|
userRole: roleVisitor,
|
||||||
|
usedSpace: "0",
|
||||||
|
quota: {
|
||||||
|
spaceLimit: "0",
|
||||||
|
uploadSpeedLimit: 0,
|
||||||
|
downloadSpeedLimit: 0,
|
||||||
|
},
|
||||||
|
authed: false,
|
||||||
|
captchaID: "mockCaptchaID",
|
||||||
|
preferences: {
|
||||||
|
bg: {
|
||||||
|
url: "",
|
||||||
|
repeat: "",
|
||||||
|
position: "",
|
||||||
|
align: "",
|
||||||
|
},
|
||||||
|
cssURL: "",
|
||||||
|
lanPackURL: "",
|
||||||
|
lan: "en_US",
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// admin
|
||||||
|
let usersMap = Map({});
|
||||||
|
let roles = Set<string>();
|
||||||
|
expect(coreState.admin).toEqual({
|
||||||
|
users: usersMap,
|
||||||
|
roles: roles,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -41,7 +41,7 @@ export function newState(): ICoreState {
|
||||||
export function initState(): ICoreState {
|
export function initState(): ICoreState {
|
||||||
return {
|
return {
|
||||||
browser: {
|
browser: {
|
||||||
dirPath: List<string>(["."]),
|
dirPath: List<string>([]),
|
||||||
items: List<MetadataResp>([]),
|
items: List<MetadataResp>([]),
|
||||||
sharings: List<string>([]),
|
sharings: List<string>([]),
|
||||||
isSharing: false,
|
isSharing: false,
|
||||||
|
|
|
@ -314,12 +314,14 @@ export class Updater {
|
||||||
return Promise.all([]);
|
return Promise.all([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// redirect to login
|
// redirect to login
|
||||||
this.setPanes(Set<string>(["login"]));
|
this.setPanes(Set<string>(["login"]));
|
||||||
this.displayPane("login");
|
this.displayPane("login");
|
||||||
return Promise.all([this.getCaptchaID()]);
|
return Promise.all([this.getCaptchaID()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (this.props.login.userRole === roleAdmin) {
|
if (this.props.login.userRole === roleAdmin) {
|
||||||
this.setPanes(Set<string>(["login", "settings", "admin"]));
|
this.setPanes(Set<string>(["login", "settings", "admin"]));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -646,7 +646,6 @@ func (h *MultiUsersSvc) Self(c *gin.Context) {
|
||||||
c.JSON(q.ErrResp(c, 500, err))
|
c.JSON(q.ErrResp(c, 500, err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fmt.Println(user.Preferences)
|
|
||||||
|
|
||||||
c.JSON(200, &SelfResp{
|
c.JSON(200, &SelfResp{
|
||||||
ID: claims[q.UserIDParam],
|
ID: claims[q.UserIDParam],
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue