test(fe): use jest mock
This commit is contained in:
parent
40c1d81d58
commit
8165c70bcb
6 changed files with 98 additions and 62 deletions
|
@ -6,13 +6,16 @@ import { AuthPane } from "../pane_login";
|
|||
import { ICoreState, newState } from "../core_state";
|
||||
import { updater } from "../state_updater";
|
||||
import { UploadState, UploadEntry } 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 {
|
||||
NewMockUsersClient,
|
||||
resps as usersResps,
|
||||
} from "../../client/users_mock";
|
||||
import {
|
||||
NewMockFilesClient,
|
||||
resps as filesResps,
|
||||
} from "../../client/files_mock";
|
||||
import { NewMockSettingsClient } from "../../client/settings_mock";
|
||||
import { controlName as panelTabs } from "../root_frame";
|
||||
import {} from "../layers";
|
||||
import {} from "../dialog_settings";
|
||||
import {} from "../panel_files";
|
||||
import {
|
||||
sharingCtrl,
|
||||
ctrlOn,
|
||||
|
@ -33,9 +36,9 @@ describe("Login", () => {
|
|||
update: (updater: (prevState: ICoreState) => ICoreState) => {},
|
||||
});
|
||||
|
||||
const usersCl = new MockUsersClient("");
|
||||
const filesCl = new MockFilesClient("");
|
||||
const settingsCl = new MockSettingsClient("");
|
||||
const usersCl = NewMockUsersClient("");
|
||||
const filesCl = NewMockFilesClient("");
|
||||
const settingsCl = NewMockSettingsClient("");
|
||||
updater().init(coreState);
|
||||
updater().setClients(usersCl, filesCl, settingsCl);
|
||||
|
||||
|
|
|
@ -5,12 +5,15 @@ import { initMockWorker } from "../../test/helpers";
|
|||
import { FilesPanel } from "../panel_files";
|
||||
import { ICoreState, newState } from "../core_state";
|
||||
import { updater } from "../state_updater";
|
||||
import { MockUsersClient, resps as usersResps } from "../../client/users_mock";
|
||||
import {
|
||||
NewMockUsersClient,
|
||||
resps as usersResps,
|
||||
} from "../../client/users_mock";
|
||||
import {
|
||||
NewMockFilesClient,
|
||||
resps as filesResps,
|
||||
} from "../../client/files_mock";
|
||||
import { MockSettingsClient } from "../../client/settings_mock";
|
||||
import { NewMockSettingsClient } from "../../client/settings_mock";
|
||||
import { makePromise } from "../../test/helpers";
|
||||
|
||||
describe("FilesPanel", () => {
|
||||
|
@ -18,9 +21,9 @@ describe("FilesPanel", () => {
|
|||
initMockWorker();
|
||||
|
||||
const coreState = newState();
|
||||
const usersCl = new MockUsersClient("");
|
||||
const usersCl = NewMockUsersClient("");
|
||||
const filesCl = NewMockFilesClient("");
|
||||
const settingsCl = new MockSettingsClient("");
|
||||
const settingsCl = NewMockSettingsClient("");
|
||||
|
||||
updater().init(coreState);
|
||||
updater().setClients(usersCl, filesCl, settingsCl);
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
import { mock, instance, verify, when, anything } from "ts-mockito";
|
||||
import { List, Map } from "immutable";
|
||||
import { Map } from "immutable";
|
||||
|
||||
import { SharingsPanel } from "../panel_sharings";
|
||||
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 { NewMockUsersClient } from "../../client/users_mock";
|
||||
import { NewMockFilesClient } from "../../client/files_mock";
|
||||
import { NewMockSettingsClient } from "../../client/settings_mock";
|
||||
import { makePromise } from "../../test/helpers";
|
||||
|
||||
describe("SharingsPanel", () => {
|
||||
const initSharingsPanel = (): any => {
|
||||
|
@ -17,9 +18,9 @@ describe("SharingsPanel", () => {
|
|||
initUploadMgr(mockWorker);
|
||||
|
||||
const coreState = newState();
|
||||
const usersCl = new MockUsersClient("");
|
||||
const filesCl = new MockFilesClient("");
|
||||
const settingsCl = new MockSettingsClient("");
|
||||
const usersCl = NewMockUsersClient("");
|
||||
const filesCl = NewMockFilesClient("");
|
||||
const settingsCl = NewMockSettingsClient("");
|
||||
|
||||
updater().init(coreState);
|
||||
updater().setClients(usersCl, filesCl, settingsCl);
|
||||
|
@ -43,21 +44,20 @@ describe("SharingsPanel", () => {
|
|||
const { sharingsPanel, usersCl, filesCl } = initSharingsPanel();
|
||||
|
||||
const newSharings = Map<string, string>({
|
||||
"mock_sharingfolder1": "f123456",
|
||||
"mock_sharingfolder2": "f123456",
|
||||
})
|
||||
mock_sharingfolder1: "f123456",
|
||||
mock_sharingfolder2: "f123456",
|
||||
});
|
||||
|
||||
filesCl.setMock({
|
||||
...filesResps,
|
||||
listSharingIDsMockResp: {
|
||||
filesCl.listSharingIDs = jest.fn().mockReturnValueOnce(
|
||||
makePromise({
|
||||
status: 200,
|
||||
statusText: "",
|
||||
data: {
|
||||
// it seems immutable map will be converted into built-in map automatically
|
||||
IDs: newSharings,
|
||||
IDs: newSharings,
|
||||
},
|
||||
},
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
await sharingsPanel.deleteSharing();
|
||||
|
||||
|
|
|
@ -5,9 +5,9 @@ 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 { NewMockUsersClient, resps as usersResps } from "../../client/users_mock";
|
||||
import { NewMockFilesClient, resps as filesResps } from "../../client/files_mock";
|
||||
import { NewMockSettingsClient } from "../../client/settings_mock";
|
||||
|
||||
describe("UploadingsPanel", () => {
|
||||
const initUploadingsPanel = (): any => {
|
||||
|
@ -16,9 +16,9 @@ describe("UploadingsPanel", () => {
|
|||
initUploadMgr(mockWorker);
|
||||
|
||||
const coreState = newState();
|
||||
const usersCl = new MockUsersClient("");
|
||||
const filesCl = new MockFilesClient("");
|
||||
const settingsCl = new MockSettingsClient("");
|
||||
const usersCl = NewMockUsersClient("");
|
||||
const filesCl = NewMockFilesClient("");
|
||||
const settingsCl = NewMockSettingsClient("");
|
||||
|
||||
updater().init(coreState);
|
||||
updater().setClients(usersCl, filesCl, settingsCl);
|
||||
|
|
|
@ -1,12 +1,19 @@
|
|||
import { List, Set, Map } from "immutable";
|
||||
|
||||
import { initMockWorker } from "../../test/helpers";
|
||||
import { initMockWorker, makePromise } from "../../test/helpers";
|
||||
import { StateMgr } from "../state_mgr";
|
||||
import { User, UploadInfo } from "../../client";
|
||||
import { MockFilesClient, resps as filesResps } from "../../client/files_mock";
|
||||
import { MockUsersClient, resps as usersResps } from "../../client/users_mock";
|
||||
import {
|
||||
MockSettingsClient,
|
||||
NewMockFilesClient,
|
||||
resps as filesResps,
|
||||
} from "../../client/files_mock";
|
||||
import { shareDirQuery } from "../../client/files";
|
||||
import {
|
||||
NewMockUsersClient,
|
||||
resps as usersResps,
|
||||
} from "../../client/users_mock";
|
||||
import {
|
||||
NewMockSettingsClient,
|
||||
resps as settingsResps,
|
||||
} from "../../client/settings_mock";
|
||||
import { ICoreState, newState } from "../core_state";
|
||||
|
@ -22,9 +29,9 @@ describe("State Manager", () => {
|
|||
// };
|
||||
|
||||
test("initUpdater for admin", async () => {
|
||||
const usersCl = new MockUsersClient("");
|
||||
const filesCl = new MockFilesClient("");
|
||||
const settingsCl = new MockSettingsClient("");
|
||||
const usersCl = NewMockUsersClient("");
|
||||
const filesCl = NewMockFilesClient("");
|
||||
const settingsCl = NewMockSettingsClient("");
|
||||
|
||||
const mgr = new StateMgr({}); // it will call initUpdater
|
||||
mgr.setUsersClient(usersCl);
|
||||
|
@ -122,9 +129,10 @@ describe("State Manager", () => {
|
|||
});
|
||||
|
||||
test("initUpdater for visitor in sharing mode", async () => {
|
||||
const usersCl = new MockUsersClient("");
|
||||
const filesCl = new MockFilesClient("");
|
||||
const settingsCl = new MockSettingsClient("");
|
||||
const usersCl = NewMockUsersClient("");
|
||||
const filesCl = NewMockFilesClient("");
|
||||
const settingsCl = NewMockSettingsClient("");
|
||||
|
||||
const mockSelfResp = {
|
||||
status: 200,
|
||||
statusText: "",
|
||||
|
@ -151,13 +159,12 @@ describe("State Manager", () => {
|
|||
},
|
||||
},
|
||||
};
|
||||
const mockIsAuthedResp = { status: 401, statusText: "", data: {} };
|
||||
const mockUserResps = {
|
||||
...usersResps,
|
||||
isAuthedMockResp: mockIsAuthedResp,
|
||||
selfMockResp: mockSelfResp,
|
||||
};
|
||||
usersCl.setMock(mockUserResps);
|
||||
usersCl.isAuthed = jest
|
||||
.fn()
|
||||
.mockReturnValue(
|
||||
makePromise({ status: 401, statusText: "", data: {} })
|
||||
);
|
||||
usersCl.self = jest.fn().mockReturnValue(makePromise(mockSelfResp));
|
||||
|
||||
const coreState = newState();
|
||||
|
||||
|
@ -171,7 +178,8 @@ describe("State Manager", () => {
|
|||
};
|
||||
|
||||
const sharingPath = "sharingPath/files";
|
||||
const query = new URLSearchParams(`?dir=${sharingPath}`);
|
||||
const query = new URLSearchParams(`?${shareDirQuery}=${sharingPath}`);
|
||||
|
||||
await mgr.initUpdater(coreState, query);
|
||||
|
||||
// browser
|
||||
|
|
|
@ -1,12 +1,18 @@
|
|||
import { List, Set, Map } from "immutable";
|
||||
|
||||
import { initMockWorker } from "../../test/helpers";
|
||||
import { initMockWorker, makePromise } from "../../test/helpers";
|
||||
import { TopBar } from "../topbar";
|
||||
import { ICoreState, newState } from "../core_state";
|
||||
import { updater } from "../state_updater";
|
||||
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 {
|
||||
NewMockUsersClient,
|
||||
resps as usersResps,
|
||||
} from "../../client/users_mock";
|
||||
import {
|
||||
NewMockFilesClient,
|
||||
resps as filesResps,
|
||||
} from "../../client/files_mock";
|
||||
import { NewMockSettingsClient } from "../../client/settings_mock";
|
||||
|
||||
import { UploadInfo, visitorID, roleVisitor, MetadataResp } from "../../client";
|
||||
import { UploadEntry, UploadState } from "../../worker/interface";
|
||||
|
@ -69,11 +75,27 @@ describe("TopBar", () => {
|
|||
isAuthedMockResp,
|
||||
};
|
||||
|
||||
const filesCl = new MockFilesClient("");
|
||||
filesCl.setMock(mockFileResps);
|
||||
const usersCl = new MockUsersClient("");
|
||||
usersCl.setMock(mockUserResps);
|
||||
const settingsCl = new MockSettingsClient("");
|
||||
const filesCl = NewMockFilesClient("");
|
||||
filesCl.listHome = jest
|
||||
.fn()
|
||||
.mockReturnValueOnce(makePromise(listHomeMockResp));
|
||||
filesCl.isSharing = jest
|
||||
.fn()
|
||||
.mockReturnValueOnce(makePromise(isSharingMockResp));
|
||||
filesCl.listSharings = jest
|
||||
.fn()
|
||||
.mockReturnValueOnce(makePromise(listSharingsMockResp));
|
||||
filesCl.listUploadings = jest
|
||||
.fn()
|
||||
.mockReturnValueOnce(makePromise(listUploadingsMockResp));
|
||||
|
||||
const usersCl = NewMockUsersClient("");
|
||||
usersCl.self = jest.fn().mockReturnValueOnce(makePromise(selfMockResp));
|
||||
usersCl.isAuthed = jest
|
||||
.fn()
|
||||
.mockReturnValueOnce(makePromise(isAuthedMockResp));
|
||||
|
||||
const settingsCl = NewMockSettingsClient("");
|
||||
|
||||
updater().init(coreState);
|
||||
updater().setClients(usersCl, filesCl, settingsCl);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue