fix(fe/utests): fix issues in the tests
This commit is contained in:
parent
f84a99de26
commit
5f0d8e2737
7 changed files with 223 additions and 139 deletions
|
@ -1,120 +0,0 @@
|
|||
// import { mock, instance, verify, when, anything } from "ts-mockito";
|
||||
// import { List } from "immutable";
|
||||
|
||||
// import { Browser } from "../browser";
|
||||
// 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";
|
||||
|
||||
// describe("Browser", () => {
|
||||
// const initBrowser = (): any => {
|
||||
// const mockWorkerClass = mock(MockWorker);
|
||||
// const mockWorker = instance(mockWorkerClass);
|
||||
// initUploadMgr(mockWorker);
|
||||
|
||||
// const coreState = newState();
|
||||
// const usersCl = new MockUsersClient("");
|
||||
// const filesCl = new MockFilesClient("");
|
||||
// const settingsCl = new MockSettingsClient("");
|
||||
|
||||
// updater().init(coreState);
|
||||
// updater().setClients(usersCl, filesCl, settingsCl);
|
||||
|
||||
// const browser = new Browser({
|
||||
// browser: coreState.browser,
|
||||
// msg: coreState.msg,
|
||||
// login: coreState.login,
|
||||
// ui: coreState.ui,
|
||||
// update: (updater: (prevState: ICoreState) => ICoreState) => {},
|
||||
// });
|
||||
|
||||
// return {
|
||||
// browser,
|
||||
// usersCl,
|
||||
// filesCl,
|
||||
// };
|
||||
// };
|
||||
|
||||
// test("addUploads", async () => {
|
||||
// const { browser, usersCl, filesCl } = initBrowser();
|
||||
|
||||
// const newSharings = [
|
||||
// "mock_sharingfolder1",
|
||||
// "mock_sharingfolder2",
|
||||
// "newSharing",
|
||||
// ];
|
||||
|
||||
// filesCl.setMock({
|
||||
// ...filesResps,
|
||||
// listSharingsMockResp: {
|
||||
// status: 200,
|
||||
// statusText: "",
|
||||
// data: {
|
||||
// sharingDirs: newSharings,
|
||||
// },
|
||||
// },
|
||||
// });
|
||||
|
||||
// await browser.addSharing();
|
||||
|
||||
// // TODO: check addSharing's input
|
||||
// expect(updater().props.browser.isSharing).toEqual(true);
|
||||
// expect(updater().props.browser.sharings).toEqual(List(newSharings));
|
||||
// });
|
||||
|
||||
// test("deleteUploads", async () => {
|
||||
// const { browser, usersCl, filesCl } = initBrowser();
|
||||
|
||||
// const newSharings = ["mock_sharingfolder1", "mock_sharingfolder2"];
|
||||
|
||||
// filesCl.setMock({
|
||||
// ...filesResps,
|
||||
// listSharingsMockResp: {
|
||||
// status: 200,
|
||||
// statusText: "",
|
||||
// data: {
|
||||
// sharingDirs: newSharings,
|
||||
// },
|
||||
// },
|
||||
// });
|
||||
|
||||
// await browser.deleteSharing();
|
||||
|
||||
// // TODO: check delSharing's input
|
||||
// expect(updater().props.browser.isSharing).toEqual(false);
|
||||
// expect(updater().props.browser.sharings).toEqual(List(newSharings));
|
||||
// });
|
||||
|
||||
// test("chdir", async () => {
|
||||
// const { browser, usersCl, filesCl } = initBrowser();
|
||||
|
||||
// const newSharings = ["mock_sharingfolder1", "mock_sharingfolder2"];
|
||||
// const newCwd = List(["newPos", "subFolder"]);
|
||||
|
||||
// filesCl.setMock({
|
||||
// ...filesResps,
|
||||
// listSharingsMockResp: {
|
||||
// status: 200,
|
||||
// statusText: "",
|
||||
// data: {
|
||||
// sharingDirs: newSharings,
|
||||
// },
|
||||
// },
|
||||
// });
|
||||
|
||||
// await browser.chdir(newCwd);
|
||||
|
||||
// expect(updater().props.browser.dirPath).toEqual(newCwd);
|
||||
// expect(updater().props.browser.isSharing).toEqual(true);
|
||||
// expect(updater().props.browser.sharings).toEqual(
|
||||
// List(filesResps.listSharingsMockResp.data.sharingDirs)
|
||||
// );
|
||||
// expect(updater().props.browser.items).toEqual(
|
||||
// List(filesResps.listHomeMockResp.data.metadatas)
|
||||
// );
|
||||
// });
|
||||
// });
|
|
@ -35,12 +35,12 @@ describe("Login", () => {
|
|||
// TODO: state is not checked
|
||||
|
||||
// browser
|
||||
expect(coreState.browser.dirPath.join("/")).toEqual("mock_home/files");
|
||||
expect(coreState.browser.isSharing).toEqual(true);
|
||||
expect(coreState.browser.sharings).toEqual(
|
||||
expect(coreState.filesInfo.dirPath.join("/")).toEqual("mock_home/files");
|
||||
expect(coreState.filesInfo.isSharing).toEqual(true);
|
||||
expect(coreState.sharingsInfo.sharings).toEqual(
|
||||
List(filesResps.listSharingsMockResp.data.sharingDirs)
|
||||
);
|
||||
expect(coreState.browser.uploadings).toEqual(
|
||||
expect(coreState.uploadingsInfo.uploadings).toEqual(
|
||||
List<UploadEntry>(
|
||||
filesResps.listUploadingsMockResp.data.uploadInfos.map(
|
||||
(info: UploadInfo) => {
|
||||
|
|
70
src/client/web/src/components/__test__/panel_files.test.tsx
Normal file
70
src/client/web/src/components/__test__/panel_files.test.tsx
Normal file
|
@ -0,0 +1,70 @@
|
|||
import { mock, instance, verify, when, anything } from "ts-mockito";
|
||||
import { List } from "immutable";
|
||||
|
||||
import { FilesPanel } from "../panel_files";
|
||||
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";
|
||||
|
||||
describe("FilesPanel", () => {
|
||||
const initFilesPanel = (): any => {
|
||||
const mockWorkerClass = mock(MockWorker);
|
||||
const mockWorker = instance(mockWorkerClass);
|
||||
initUploadMgr(mockWorker);
|
||||
|
||||
const coreState = newState();
|
||||
const usersCl = new MockUsersClient("");
|
||||
const filesCl = new MockFilesClient("");
|
||||
const settingsCl = new MockSettingsClient("");
|
||||
|
||||
updater().init(coreState);
|
||||
updater().setClients(usersCl, filesCl, settingsCl);
|
||||
|
||||
const filesPanel = new FilesPanel({
|
||||
filesInfo: coreState.filesInfo,
|
||||
msg: coreState.msg,
|
||||
login: coreState.login,
|
||||
ui: coreState.ui,
|
||||
update: (updater: (prevState: ICoreState) => ICoreState) => {},
|
||||
});
|
||||
|
||||
return {
|
||||
filesPanel,
|
||||
usersCl,
|
||||
filesCl,
|
||||
};
|
||||
};
|
||||
|
||||
test("chdir", async () => {
|
||||
const { filesPanel, usersCl, filesCl } = initFilesPanel();
|
||||
|
||||
const newSharings = ["mock_sharingfolder1", "mock_sharingfolder2"];
|
||||
const newCwd = List(["newPos", "subFolder"]);
|
||||
|
||||
filesCl.setMock({
|
||||
...filesResps,
|
||||
listSharingsMockResp: {
|
||||
status: 200,
|
||||
statusText: "",
|
||||
data: {
|
||||
sharingDirs: newSharings,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await filesPanel.chdir(newCwd);
|
||||
|
||||
expect(updater().props.filesInfo.dirPath).toEqual(newCwd);
|
||||
expect(updater().props.filesInfo.isSharing).toEqual(true);
|
||||
expect(updater().props.filesInfo.items).toEqual(
|
||||
List(filesResps.listHomeMockResp.data.metadatas)
|
||||
);
|
||||
expect(updater().props.sharingsInfo.sharings).toEqual(
|
||||
List(filesResps.listSharingsMockResp.data.sharingDirs)
|
||||
);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,91 @@
|
|||
import { mock, instance, verify, when, anything } from "ts-mockito";
|
||||
import { List } 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";
|
||||
|
||||
describe("SharingsPanel", () => {
|
||||
const initSharingsPanel = (): any => {
|
||||
const mockWorkerClass = mock(MockWorker);
|
||||
const mockWorker = instance(mockWorkerClass);
|
||||
initUploadMgr(mockWorker);
|
||||
|
||||
const coreState = newState();
|
||||
const usersCl = new MockUsersClient("");
|
||||
const filesCl = new MockFilesClient("");
|
||||
const settingsCl = new MockSettingsClient("");
|
||||
|
||||
updater().init(coreState);
|
||||
updater().setClients(usersCl, filesCl, settingsCl);
|
||||
|
||||
const sharingsPanel = new SharingsPanel({
|
||||
sharingsInfo: coreState.sharingsInfo,
|
||||
msg: coreState.msg,
|
||||
login: coreState.login,
|
||||
ui: coreState.ui,
|
||||
update: (updater: (prevState: ICoreState) => ICoreState) => {},
|
||||
});
|
||||
|
||||
return {
|
||||
sharingsPanel,
|
||||
usersCl,
|
||||
filesCl,
|
||||
};
|
||||
};
|
||||
|
||||
test("add sharing", async () => {
|
||||
const { sharingsPanel, usersCl, filesCl } = initSharingsPanel();
|
||||
|
||||
const newSharings = [
|
||||
"mock_sharingfolder1",
|
||||
"mock_sharingfolder2",
|
||||
"newSharing",
|
||||
];
|
||||
|
||||
filesCl.setMock({
|
||||
...filesResps,
|
||||
listSharingsMockResp: {
|
||||
status: 200,
|
||||
statusText: "",
|
||||
data: {
|
||||
sharingDirs: newSharings,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await sharingsPanel.addSharing();
|
||||
|
||||
// TODO: check addSharing's input
|
||||
expect(updater().props.filesInfo.isSharing).toEqual(true);
|
||||
expect(updater().props.sharingsInfo.sharings).toEqual(List(newSharings));
|
||||
});
|
||||
|
||||
test("delete sharing", async () => {
|
||||
const { sharingsPanel, usersCl, filesCl } = initSharingsPanel();
|
||||
|
||||
const newSharings = ["mock_sharingfolder1", "mock_sharingfolder2"];
|
||||
|
||||
filesCl.setMock({
|
||||
...filesResps,
|
||||
listSharingsMockResp: {
|
||||
status: 200,
|
||||
statusText: "",
|
||||
data: {
|
||||
sharingDirs: newSharings,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await sharingsPanel.deleteSharing();
|
||||
|
||||
// TODO: check delSharing's input
|
||||
expect(updater().props.filesInfo.isSharing).toEqual(false);
|
||||
expect(updater().props.sharingsInfo.sharings).toEqual(List(newSharings));
|
||||
});
|
||||
});
|
|
@ -0,0 +1,43 @@
|
|||
import { mock, instance, verify, when, anything } from "ts-mockito";
|
||||
import { List } from "immutable";
|
||||
|
||||
import { UploadingsPanel } from "../panel_uploadings";
|
||||
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";
|
||||
|
||||
describe("UploadingsPanel", () => {
|
||||
const initUploadingsPanel = (): any => {
|
||||
const mockWorkerClass = mock(MockWorker);
|
||||
const mockWorker = instance(mockWorkerClass);
|
||||
initUploadMgr(mockWorker);
|
||||
|
||||
const coreState = newState();
|
||||
const usersCl = new MockUsersClient("");
|
||||
const filesCl = new MockFilesClient("");
|
||||
const settingsCl = new MockSettingsClient("");
|
||||
|
||||
updater().init(coreState);
|
||||
updater().setClients(usersCl, filesCl, settingsCl);
|
||||
|
||||
const uploadingsPanel = new UploadingsPanel({
|
||||
uploadingsInfo: coreState.uploadingsInfo,
|
||||
msg: coreState.msg,
|
||||
login: coreState.login,
|
||||
ui: coreState.ui,
|
||||
update: (updater: (prevState: ICoreState) => ICoreState) => {},
|
||||
});
|
||||
|
||||
return {
|
||||
uploadingsPanel,
|
||||
usersCl,
|
||||
filesCl,
|
||||
};
|
||||
};
|
||||
|
||||
test("todo", async () => {});
|
||||
});
|
|
@ -38,12 +38,12 @@ describe("State Manager", () => {
|
|||
await mgr.initUpdater(coreState);
|
||||
|
||||
// browser
|
||||
expect(coreState.browser.dirPath.join("/")).toEqual("mock_home/files");
|
||||
expect(coreState.browser.isSharing).toEqual(true);
|
||||
expect(coreState.browser.sharings).toEqual(
|
||||
expect(coreState.filesInfo.dirPath.join("/")).toEqual("mock_home/files");
|
||||
expect(coreState.filesInfo.isSharing).toEqual(true);
|
||||
expect(coreState.sharingsInfo.sharings).toEqual(
|
||||
List(filesResps.listSharingsMockResp.data.sharingDirs)
|
||||
);
|
||||
expect(coreState.browser.uploadings).toEqual(
|
||||
expect(coreState.uploadingsInfo.uploadings).toEqual(
|
||||
List<UploadEntry>(
|
||||
filesResps.listUploadingsMockResp.data.uploadInfos.map(
|
||||
(info: UploadInfo) => {
|
||||
|
@ -60,7 +60,7 @@ describe("State Manager", () => {
|
|||
)
|
||||
);
|
||||
|
||||
expect(coreState.browser.items).toEqual(
|
||||
expect(coreState.filesInfo.items).toEqual(
|
||||
List(filesResps.listHomeMockResp.data.metadatas)
|
||||
);
|
||||
|
||||
|
@ -173,13 +173,13 @@ describe("State Manager", () => {
|
|||
|
||||
// browser
|
||||
// TODO: mock query to get dir parm
|
||||
expect(coreState.browser.dirPath.join("/")).toEqual("mock_home/files");
|
||||
expect(coreState.browser.isSharing).toEqual(true);
|
||||
expect(coreState.browser.sharings).toEqual(List([]));
|
||||
expect(coreState.browser.uploadings).toEqual(List<UploadEntry>([]));
|
||||
expect(coreState.browser.items).toEqual(
|
||||
expect(coreState.filesInfo.dirPath.join("/")).toEqual("mock_home/files");
|
||||
expect(coreState.filesInfo.isSharing).toEqual(true);
|
||||
expect(coreState.filesInfo.items).toEqual(
|
||||
List(filesResps.listHomeMockResp.data.metadatas)
|
||||
);
|
||||
expect(coreState.sharingsInfo.sharings).toEqual(List([]));
|
||||
expect(coreState.uploadingsInfo.uploadings).toEqual(List<UploadEntry>([]));
|
||||
|
||||
// panes
|
||||
expect(coreState.panes).toEqual({
|
||||
|
|
|
@ -93,11 +93,11 @@ describe("TopBar", () => {
|
|||
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());
|
||||
expect(coreState.filesInfo.dirPath.join("/")).toEqual(mockFileResps.listHomeMockResp.data.cwd);
|
||||
expect(coreState.filesInfo.isSharing).toEqual(false);
|
||||
expect(coreState.filesInfo.items).toEqual(List());
|
||||
expect(coreState.sharingsInfo.sharings).toEqual(List());
|
||||
expect(coreState.uploadingsInfo.uploadings).toEqual(List<UploadEntry>());
|
||||
|
||||
// panes
|
||||
expect(coreState.panes).toEqual({
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue