From 5f0d8e27375dbda62e0d05c500931ffbb79b00de Mon Sep 17 00:00:00 2001 From: hexxa Date: Thu, 25 Nov 2021 16:22:07 +0800 Subject: [PATCH] fix(fe/utests): fix issues in the tests --- .../src/components/__test__/browser.test.tsx | 120 ------------------ .../components/__test__/pane_login.test.tsx | 8 +- .../components/__test__/panel_files.test.tsx | 70 ++++++++++ .../__test__/panel_sharings.test.tsx | 91 +++++++++++++ .../__test__/panel_uploadings.test.tsx | 43 +++++++ .../components/__test__/state_mgr.test.tsx | 20 +-- .../src/components/__test__/topbar.test.tsx | 10 +- 7 files changed, 223 insertions(+), 139 deletions(-) delete mode 100644 src/client/web/src/components/__test__/browser.test.tsx create mode 100644 src/client/web/src/components/__test__/panel_files.test.tsx create mode 100644 src/client/web/src/components/__test__/panel_sharings.test.tsx create mode 100644 src/client/web/src/components/__test__/panel_uploadings.test.tsx diff --git a/src/client/web/src/components/__test__/browser.test.tsx b/src/client/web/src/components/__test__/browser.test.tsx deleted file mode 100644 index f1e4b48..0000000 --- a/src/client/web/src/components/__test__/browser.test.tsx +++ /dev/null @@ -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) -// ); -// }); -// }); diff --git a/src/client/web/src/components/__test__/pane_login.test.tsx b/src/client/web/src/components/__test__/pane_login.test.tsx index c56093b..4b9ab8f 100644 --- a/src/client/web/src/components/__test__/pane_login.test.tsx +++ b/src/client/web/src/components/__test__/pane_login.test.tsx @@ -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( filesResps.listUploadingsMockResp.data.uploadInfos.map( (info: UploadInfo) => { diff --git a/src/client/web/src/components/__test__/panel_files.test.tsx b/src/client/web/src/components/__test__/panel_files.test.tsx new file mode 100644 index 0000000..f9cbb9e --- /dev/null +++ b/src/client/web/src/components/__test__/panel_files.test.tsx @@ -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) + ); + }); +}); diff --git a/src/client/web/src/components/__test__/panel_sharings.test.tsx b/src/client/web/src/components/__test__/panel_sharings.test.tsx new file mode 100644 index 0000000..3457936 --- /dev/null +++ b/src/client/web/src/components/__test__/panel_sharings.test.tsx @@ -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)); + }); +}); diff --git a/src/client/web/src/components/__test__/panel_uploadings.test.tsx b/src/client/web/src/components/__test__/panel_uploadings.test.tsx new file mode 100644 index 0000000..07e9e4c --- /dev/null +++ b/src/client/web/src/components/__test__/panel_uploadings.test.tsx @@ -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 () => {}); +}); diff --git a/src/client/web/src/components/__test__/state_mgr.test.tsx b/src/client/web/src/components/__test__/state_mgr.test.tsx index fe5314c..c655cc7 100644 --- a/src/client/web/src/components/__test__/state_mgr.test.tsx +++ b/src/client/web/src/components/__test__/state_mgr.test.tsx @@ -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( 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([])); - 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([])); // panes expect(coreState.panes).toEqual({ diff --git a/src/client/web/src/components/__test__/topbar.test.tsx b/src/client/web/src/components/__test__/topbar.test.tsx index 765e51f..d72aee8 100644 --- a/src/client/web/src/components/__test__/topbar.test.tsx +++ b/src/client/web/src/components/__test__/topbar.test.tsx @@ -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()); - 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()); // panes expect(coreState.panes).toEqual({