From 87f6c4a0142a6bb0e7ea139cccf2916a26aebd2d Mon Sep 17 00:00:00 2001 From: Jones Ogolo Date: Mon, 15 Jan 2024 10:37:14 +0100 Subject: [PATCH] test: update bulk actions missing tests driveby: add missing props --- .../BulkActions/BulkActions.test.tsx | 175 ++++++++++++++++++ src/app/tags/views/TagList/TagList.test.tsx | 1 + .../views/TagList/TagTable/TagTable.test.tsx | 19 ++ .../tags/views/TagUpdate/TagUpdate.test.tsx | 12 +- 4 files changed, 201 insertions(+), 6 deletions(-) diff --git a/src/app/base/components/node/StorageTables/AvailableStorageTable/BulkActions/BulkActions.test.tsx b/src/app/base/components/node/StorageTables/AvailableStorageTable/BulkActions/BulkActions.test.tsx index bfa907df9c1..db141b87429 100644 --- a/src/app/base/components/node/StorageTables/AvailableStorageTable/BulkActions/BulkActions.test.tsx +++ b/src/app/base/components/node/StorageTables/AvailableStorageTable/BulkActions/BulkActions.test.tsx @@ -1,5 +1,7 @@ import BulkActions from "./BulkActions"; +import * as sidePanelHooks from "app/base/side-panel-context"; +import { MachineSidePanelViews } from "app/machines/constants"; import { DiskTypes, StorageLayout } from "app/store/types/enum"; import { machineDetails as machineDetailsFactory, @@ -15,9 +17,19 @@ import { expectTooltipOnHover, renderWithBrowserRouter, screen, + userEvent, } from "testing/utils"; describe("BulkActions", () => { + const setSidePanelContent = jest.fn(); + beforeAll(() => { + jest.spyOn(sidePanelHooks, "useSidePanel").mockReturnValue({ + setSidePanelContent, + sidePanelContent: null, + setSidePanelSize: jest.fn(), + sidePanelSize: "regular", + }); + }); it("disables create volume group button with tooltip if selected devices are not eligible", async () => { const selected = [ diskFactory({ @@ -174,4 +186,167 @@ describe("BulkActions", () => { screen.getByRole("button", { name: "Add to existing datastore" }) ).not.toBeDisabled(); }); + + it("can trigger the create datastore sidepanel", async () => { + const datastore = diskFactory({ + filesystem: fsFactory({ fstype: "vmfs6" }), + }); + const selected = diskFactory({ filesystem: null, partitions: null }); + const state = rootStateFactory({ + machine: machineStateFactory({ + items: [ + machineDetailsFactory({ + detected_storage_layout: StorageLayout.VMFS6, + disks: [datastore, selected], + system_id: "abc123", + }), + ], + statuses: machineStatusesFactory({ + abc123: machineStatusFactory(), + }), + }), + }); + renderWithBrowserRouter( + , + { state } + ); + + await userEvent.click( + screen.getByRole("button", { name: "Create datastore" }) + ); + expect(setSidePanelContent).toHaveBeenCalledWith( + expect.objectContaining({ + view: MachineSidePanelViews.CREATE_DATASTORE, + }) + ); + }); + + it("can trigger the create RAID sidepanel", async () => { + const selected = [ + diskFactory({ + filesystem: null, + type: DiskTypes.VIRTUAL, + }), + diskFactory({ + filesystem: null, + type: DiskTypes.VIRTUAL, + }), + ]; + const state = rootStateFactory({ + machine: machineStateFactory({ + items: [ + machineDetailsFactory({ + detected_storage_layout: StorageLayout.FLAT, + disks: selected, + system_id: "abc123", + }), + ], + statuses: machineStatusesFactory({ + abc123: machineStatusFactory(), + }), + }), + }); + renderWithBrowserRouter( + , + { state } + ); + + await userEvent.click(screen.getByRole("button", { name: "Create RAID" })); + expect(setSidePanelContent).toHaveBeenCalledWith( + expect.objectContaining({ + view: MachineSidePanelViews.CREATE_RAID, + }) + ); + }); + + it("can trigger the create volume group sidepanel", async () => { + const selected = [ + diskFactory({ + filesystem: null, + type: DiskTypes.VIRTUAL, + }), + diskFactory({ + filesystem: null, + type: DiskTypes.VIRTUAL, + }), + ]; + const state = rootStateFactory({ + machine: machineStateFactory({ + items: [ + machineDetailsFactory({ + detected_storage_layout: StorageLayout.FLAT, + disks: selected, + system_id: "abc123", + }), + ], + statuses: machineStatusesFactory({ + abc123: machineStatusFactory(), + }), + }), + }); + renderWithBrowserRouter( + , + { state } + ); + + await userEvent.click( + screen.getByRole("button", { name: "Create volume group" }) + ); + expect(setSidePanelContent).toHaveBeenCalledWith( + expect.objectContaining({ + view: MachineSidePanelViews.CREATE_VOLUME_GROUP, + }) + ); + }); + + it("can trigger the update datastore sidepanel", async () => { + const datastore = diskFactory({ + filesystem: fsFactory({ fstype: "vmfs6" }), + }); + const selected = diskFactory({ filesystem: null, partitions: null }); + const state = rootStateFactory({ + machine: machineStateFactory({ + items: [ + machineDetailsFactory({ + detected_storage_layout: StorageLayout.VMFS6, + disks: [datastore, selected], + system_id: "abc123", + }), + ], + statuses: machineStatusesFactory({ + abc123: machineStatusFactory(), + }), + }), + }); + + renderWithBrowserRouter( + , + { state } + ); + + await userEvent.click( + screen.getByRole("button", { name: "Add to existing datastore" }) + ); + expect(setSidePanelContent).toHaveBeenCalledWith( + expect.objectContaining({ + view: MachineSidePanelViews.UPDATE_DATASTORE, + }) + ); + }); }); diff --git a/src/app/tags/views/TagList/TagList.test.tsx b/src/app/tags/views/TagList/TagList.test.tsx index cf254c678fb..21bd63c9686 100644 --- a/src/app/tags/views/TagList/TagList.test.tsx +++ b/src/app/tags/views/TagList/TagList.test.tsx @@ -42,6 +42,7 @@ it("renders", () => { currentPage={1} filter={TagSearchFilter.All} onDelete={jest.fn()} + onUpdate={jest.fn()} searchText="" setCurrentPage={jest.fn()} tableId="test-table" diff --git a/src/app/tags/views/TagList/TagTable/TagTable.test.tsx b/src/app/tags/views/TagList/TagTable/TagTable.test.tsx index 377e870ec95..5b1909fd851 100644 --- a/src/app/tags/views/TagList/TagTable/TagTable.test.tsx +++ b/src/app/tags/views/TagList/TagTable/TagTable.test.tsx @@ -60,6 +60,7 @@ it("displays tags", () => { currentPage={1} filter={TagSearchFilter.All} onDelete={jest.fn()} + onUpdate={jest.fn()} searchText="" setCurrentPage={jest.fn()} tags={tags} @@ -86,6 +87,7 @@ it("displays the tags in order", () => { currentPage={1} filter={TagSearchFilter.All} onDelete={jest.fn()} + onUpdate={jest.fn()} searchText="" setCurrentPage={jest.fn()} tags={tags} @@ -111,6 +113,7 @@ it("can change the sort order", async () => { currentPage={1} filter={TagSearchFilter.All} onDelete={jest.fn()} + onUpdate={jest.fn()} searchText="" setCurrentPage={jest.fn()} tags={tags} @@ -159,6 +162,7 @@ it("displays the tags for the current page", () => { currentPage={2} filter={TagSearchFilter.All} onDelete={jest.fn()} + onUpdate={jest.fn()} searchText="" setCurrentPage={jest.fn()} tags={tags} @@ -186,6 +190,7 @@ it("shows an icon for automatic tags", () => { currentPage={1} filter={TagSearchFilter.All} onDelete={jest.fn()} + onUpdate={jest.fn()} searchText="" setCurrentPage={jest.fn()} tags={tags} @@ -212,6 +217,7 @@ it("does not show an icon for manual tags", () => { currentPage={1} filter={TagSearchFilter.All} onDelete={jest.fn()} + onUpdate={jest.fn()} searchText="" setCurrentPage={jest.fn()} tags={tags} @@ -238,6 +244,7 @@ it("shows an icon for kernel options", () => { currentPage={1} filter={TagSearchFilter.All} onDelete={jest.fn()} + onUpdate={jest.fn()} searchText="" setCurrentPage={jest.fn()} tags={tags} @@ -264,6 +271,7 @@ it("does not show an icon for tags without kernel options", () => { currentPage={1} filter={TagSearchFilter.All} onDelete={jest.fn()} + onUpdate={jest.fn()} searchText="" setCurrentPage={jest.fn()} tags={tags} @@ -298,6 +306,7 @@ it("can link to nodes", () => { currentPage={1} filter={TagSearchFilter.All} onDelete={jest.fn()} + onUpdate={jest.fn()} searchText="" setCurrentPage={jest.fn()} tags={tags} @@ -346,6 +355,7 @@ it("does not display a message if there are tags", () => { currentPage={1} filter={TagSearchFilter.All} onDelete={jest.fn()} + onUpdate={jest.fn()} searchText="" setCurrentPage={jest.fn()} tags={[]} @@ -367,6 +377,7 @@ it("displays a message if there are no automatic tags", () => { currentPage={1} filter={TagSearchFilter.Auto} onDelete={jest.fn()} + onUpdate={jest.fn()} searchText="" setCurrentPage={jest.fn()} tags={[]} @@ -390,6 +401,7 @@ it("displays a message if there are no manual tags", () => { currentPage={1} filter={TagSearchFilter.Manual} onDelete={jest.fn()} + onUpdate={jest.fn()} searchText="" setCurrentPage={jest.fn()} tags={[]} @@ -413,6 +425,7 @@ it("displays a message if none match the search terms", () => { currentPage={1} filter={TagSearchFilter.All} onDelete={jest.fn()} + onUpdate={jest.fn()} searchText="nothing" setCurrentPage={jest.fn()} tags={[]} @@ -436,6 +449,7 @@ it("displays a message if none match the filter and search terms", () => { currentPage={1} filter={TagSearchFilter.Auto} onDelete={jest.fn()} + onUpdate={jest.fn()} searchText="nothing" setCurrentPage={jest.fn()} tags={[]} @@ -460,6 +474,7 @@ it("returns to the first page if the search changes", () => { currentPage={1} filter={TagSearchFilter.Auto} onDelete={jest.fn()} + onUpdate={jest.fn()} searchText="" setCurrentPage={setCurrentPage} tags={[]} @@ -476,6 +491,7 @@ it("returns to the first page if the search changes", () => { currentPage={1} filter={TagSearchFilter.Auto} onDelete={jest.fn()} + onUpdate={jest.fn()} searchText="new" setCurrentPage={setCurrentPage} tags={[]} @@ -498,6 +514,7 @@ it("returns to the first page if the filter changes", () => { currentPage={1} filter={TagSearchFilter.All} onDelete={jest.fn()} + onUpdate={jest.fn()} searchText="" setCurrentPage={setCurrentPage} tags={[]} @@ -514,6 +531,7 @@ it("returns to the first page if the filter changes", () => { currentPage={1} filter={TagSearchFilter.Manual} onDelete={jest.fn()} + onUpdate={jest.fn()} searchText="" setCurrentPage={setCurrentPage} tags={[]} @@ -541,6 +559,7 @@ it("can go to the tag edit page", async () => { currentPage={1} filter={TagSearchFilter.All} onDelete={jest.fn()} + onUpdate={jest.fn()} searchText="" setCurrentPage={jest.fn()} tags={tags} diff --git a/src/app/tags/views/TagUpdate/TagUpdate.test.tsx b/src/app/tags/views/TagUpdate/TagUpdate.test.tsx index 7a0829973a6..6d4c93fc36c 100644 --- a/src/app/tags/views/TagUpdate/TagUpdate.test.tsx +++ b/src/app/tags/views/TagUpdate/TagUpdate.test.tsx @@ -45,7 +45,7 @@ it("dispatches actions to fetch necessary data", () => { > } + component={() => } exact path={urls.tags.tag.index(null)} /> @@ -80,7 +80,7 @@ it("shows a spinner if the tag has not loaded yet", () => { > } + component={() => } exact path={urls.tags.tag.index(null)} /> @@ -98,7 +98,7 @@ it("can update the tag", async () => { - + @@ -143,7 +143,7 @@ it("can return to the previous page on save", async () => { } + component={() => } exact path={urls.tags.tag.update(null)} /> @@ -175,7 +175,7 @@ it("goes to the tag details page if it can't go back", async () => { } + component={() => } exact path={urls.tags.tag.update(null)} /> @@ -203,7 +203,7 @@ it("shows a confirmation when a tag's definition is updated", async () => { - +