Skip to content

Commit

Permalink
test: update bulk actions missing tests
Browse files Browse the repository at this point in the history
driveby: add missing props
  • Loading branch information
Jay-Topher committed Jan 15, 2024
1 parent 8fb7692 commit 87f6c4a
Show file tree
Hide file tree
Showing 4 changed files with 201 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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({
Expand Down Expand Up @@ -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(
<BulkActions
selected={[selected]}
setBulkAction={jest.fn()}
systemId="abc123"
/>,
{ 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(
<BulkActions
selected={selected}
setBulkAction={jest.fn()}
systemId="abc123"
/>,
{ 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(
<BulkActions
selected={selected}
setBulkAction={jest.fn()}
systemId="abc123"
/>,
{ 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(
<BulkActions
selected={[selected]}
setBulkAction={jest.fn()}
systemId="abc123"
/>,
{ state }
);

await userEvent.click(
screen.getByRole("button", { name: "Add to existing datastore" })
);
expect(setSidePanelContent).toHaveBeenCalledWith(
expect.objectContaining({
view: MachineSidePanelViews.UPDATE_DATASTORE,
})
);
});
});
1 change: 1 addition & 0 deletions src/app/tags/views/TagList/TagList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ it("renders", () => {
currentPage={1}
filter={TagSearchFilter.All}
onDelete={jest.fn()}
onUpdate={jest.fn()}
searchText=""
setCurrentPage={jest.fn()}
tableId="test-table"
Expand Down
19 changes: 19 additions & 0 deletions src/app/tags/views/TagList/TagTable/TagTable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ it("displays tags", () => {
currentPage={1}
filter={TagSearchFilter.All}
onDelete={jest.fn()}
onUpdate={jest.fn()}
searchText=""
setCurrentPage={jest.fn()}
tags={tags}
Expand All @@ -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}
Expand All @@ -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}
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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}
Expand All @@ -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}
Expand All @@ -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}
Expand All @@ -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}
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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={[]}
Expand All @@ -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={[]}
Expand All @@ -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={[]}
Expand All @@ -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={[]}
Expand All @@ -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={[]}
Expand All @@ -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={[]}
Expand All @@ -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={[]}
Expand All @@ -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={[]}
Expand All @@ -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={[]}
Expand Down Expand Up @@ -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}
Expand Down
Loading

0 comments on commit 87f6c4a

Please sign in to comment.