Skip to content

Commit

Permalink
Added unit test for the format dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed Sep 19, 2024
1 parent f47fa8a commit 895f0c7
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 5 deletions.
71 changes: 69 additions & 2 deletions web/src/components/storage/dasd/DASDTable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,40 @@ import DASDTable from "./DASDTable";

let mockDASDDevices: DASDDevice[] = [];

let consoleErrorSpy;
jest.mock("~/queries/storage/dasd", () => ({
useDASDDevices: () => mockDASDDevices,
useDASDMutation: () => jest.fn(),
useFormatDASDMutation: () => jest.fn(),
}));

describe("DASDTable", () => {
beforeAll(() => {
consoleErrorSpy = jest.spyOn(console, "error");
consoleErrorSpy.mockImplementation();
});

afterAll(() => {
consoleErrorSpy.mockRestore();
});
describe("when there is some DASD devices available", () => {
beforeEach(() => {
mockDASDDevices = [
{
id: "0.0.0200",
id: "0.0.0160",
enabled: false,
deviceName: "",
deviceType: "",
formatted: false,
diag: false,
status: "offline",
accessType: "",
partitionInfo: "",
hexId: 0x160,
},
{
id: "0.0.0200",
enabled: true,
deviceName: "dasda",
deviceType: "eckd",
formatted: false,
Expand All @@ -53,8 +74,54 @@ describe("DASDTable", () => {
});

it("renders those devices", () => {
installerRender(<DASDTable />);
installerRender(<DASDTable aria-label="DASDs table" />);
screen.getByText("active");
});

it("does not allow to perform any action if not selected any device", () => {
installerRender(<DASDTable aria-label="DASDs table" />);
const button = screen.getByRole("button", { name: "Perform an action" });
expect(button).toHaveAttribute("disabled");
});

describe("when there are some DASD selected", () => {
it("allows to perform a set of actions over them", async () => {
const { user } = installerRender(<DASDTable aria-label="DASDs table" />);
const selection = screen.getByRole("checkbox", { name: "Select row 0" });
await user.click(selection);
const button = screen.getByRole("button", { name: "Perform an action" });
expect(button).not.toHaveAttribute("disabled");
await user.click(button);
screen.getByRole("menuitem", { name: "Format" });
});

describe("and the user click on format", () => {
it("shows a confirmation dialog if all the devices are online", async () => {
const { user } = installerRender(<DASDTable aria-label="DASDs table" />);
const selection = screen.getByRole("checkbox", { name: "Select row 1" });
await user.click(selection);
const button = screen.getByRole("button", { name: "Perform an action" });
expect(button).not.toHaveAttribute("disabled");
await user.click(button);
const format = screen.getByRole("menuitem", { name: "Format" });
await user.click(format);
screen.getByRole("dialog", { name: "DASD format confirmation dialog" });
});

it("shows a warning dialog if some device is offline", async () => {
const { user } = installerRender(<DASDTable aria-label="DASDs table" />);
let selection = screen.getByRole("checkbox", { name: "Select row 0" });
await user.click(selection);
selection = screen.getByRole("checkbox", { name: "Select row 1" });
await user.click(selection);
const button = screen.getByRole("button", { name: "Perform an action" });
expect(button).not.toHaveAttribute("disabled");
await user.click(button);
const format = screen.getByRole("menuitem", { name: "Format" });
await user.click(format);
screen.getByRole("dialog", { name: "DASD format offline warning dialog" });
});
});
});
});
});
6 changes: 3 additions & 3 deletions web/src/components/storage/dasd/DASDTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const ConfirmFormat = ({ devices, isOpen, toggle, action }) => {

if (offline.length > 0) {
return (
<Popup isOpen={isOpen}>
<Popup isOpen={isOpen} aria-label="DASD format offline warning dialog">
<Text>
{_(
"The DASD devices listed below are offline and cannot be formatted, please unselect or activate them in order to continue",
Expand All @@ -101,7 +101,7 @@ const ConfirmFormat = ({ devices, isOpen, toggle, action }) => {
}

return (
<Popup isOpen={isOpen}>
<Popup isOpen={isOpen} aria-label="DASD format confirmation dialog">
<Text>
{_("The DASD devices listed below are going to be formatted, do you want to proceed?")}
</Text>
Expand Down Expand Up @@ -371,7 +371,7 @@ export default function DASDTable() {
</ToolbarContent>
</Toolbar>

<Page.Section>
<Page.Section aria-label="DASDs table section">
<Content />
</Page.Section>
</>
Expand Down

0 comments on commit 895f0c7

Please sign in to comment.