Skip to content

Commit

Permalink
web: add tests for storage proposal result section
Browse files Browse the repository at this point in the history
  • Loading branch information
dgdavid committed Mar 12, 2024
1 parent ba3b508 commit 4a7754a
Show file tree
Hide file tree
Showing 4 changed files with 1,534 additions and 7 deletions.
1 change: 1 addition & 0 deletions web/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/*
src/lib/*
src/**/test-data/*
3 changes: 2 additions & 1 deletion web/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"ignorePaths": [
"src/lib/cockpit.js",
"src/lib/cockpit-po-plugin.js",
"src/manifest.json"
"src/manifest.json",
"src/**/test-data/*"
],
"import": [
"@cspell/dict-css/cspell-ext.json",
Expand Down
88 changes: 82 additions & 6 deletions web/src/components/storage/ProposalResultSection.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,87 @@
* find current contact information at www.suse.com.
*/

import React from "react";
import { screen, within } from "@testing-library/react";
import { plainRender } from "~/test-utils";
import { ProposalResultSection } from "~/components/storage";
import { settings, devices, actions } from "./test-data/full-result-example";

const errorMessage = "Something went wrong, proposal not possible";
const errors = [{ severity: 0, message: errorMessage }];
const defaultProps = { settings, actions, devices };

describe("ProposalResultSection", () => {
it.todo("check that it shows a warning when there are deletion actions");
it.todo("check that it shows a tree table with the proposal result");
it.todo("check that 'New' label is included when proceed");
it.todo("check that 'Shrank' label is included when proceed");
it.todo("check that filesystem label is shown if present");
it.todo("check that there is a working link for checking all actions");
describe("when there are errors (proposal was not possible)", () => {
it("renders given errors", () => {
plainRender(<ProposalResultSection {...defaultProps} errors={errors} />);
expect(screen.queryByText(errorMessage)).toBeInTheDocument();
});

it("does not render an warning for delete actions", () => {
plainRender(<ProposalResultSection {...defaultProps} errors={errors} />);
expect(screen.queryByText(/Warning alert:/)).toBeNull();
});

it("does not render a treegrid node", () => {
plainRender(<ProposalResultSection {...defaultProps} errors={errors} />);
expect(screen.queryByRole("treegrid")).toBeNull();
});

it("does not render the link for opening the planned actions dialog", () => {
plainRender(<ProposalResultSection {...defaultProps} errors={errors} />);
expect(screen.queryByRole("button", { name: /planned actions/ })).toBeNull();
});
});

describe("when there are no errors (proposal was possible)", () => {
it("does not render a warning when there are not delete actions", () => {
const props = {
...defaultProps,
actions: defaultProps.actions.filter(a => !a.delete)
};

plainRender(<ProposalResultSection {...props} />);
expect(screen.queryByText(/Warning alert:/)).toBeNull();
});

it("renders a warning when when there are delete", () => {
plainRender(<ProposalResultSection {...defaultProps} />);
screen.getByText(/Warning alert:/);
});

it("renders a treegrid including all relevant information about final result", () => {
plainRender(<ProposalResultSection {...defaultProps} />);
const treegrid = screen.getByRole("treegrid");
/**
* Expected rows for full-result-example
* --------------------------------------------------
* "/dev/vdc Disk GPT 30 GiB"
* "vdc1 New BIOS Boot Partition 8 MiB"
* "vdc3 swap New Swap Partition 1.5 GiB"
* "Unused space 3.49 GiB"
* "vdc2 openSUSE Leap 15.2, Fedora 10.30 5 GiB"
* "Unused space 1 GiB"
* "vdc4 Linux Resized 514 MiB 1.5 GiB"
* "vdc5 / New Btrfs Partition 17.5 GiB"
*/
within(treegrid).getByRole("row", { name: "/dev/vdc Disk GPT 30 GiB" });
within(treegrid).getByRole("row", { name: "vdc1 New BIOS Boot Partition 8 MiB" });
within(treegrid).getByRole("row", { name: "vdc3 swap New Swap Partition 1.5 GiB" });
within(treegrid).getByRole("row", { name: "Unused space 3.49 GiB" });
within(treegrid).getByRole("row", { name: "vdc2 openSUSE Leap 15.2, Fedora 10.30 5 GiB" });
within(treegrid).getByRole("row", { name: "Unused space 1 GiB" });
within(treegrid).getByRole("row", { name: "vdc4 Linux Resized 514 MiB 1.5 GiB" });
within(treegrid).getByRole("row", { name: "vdc5 / New Btrfs Partition 17.5 GiB" });
});

it("renders a button for opening the planned actions dialog", async () => {
const { user } = plainRender(<ProposalResultSection {...defaultProps} />);
const button = screen.getByRole("button", { name: /planned actions/ });

await user.click(button);

screen.getByRole("dialog", { name: "Planned Actions" });
});
});
});
Loading

0 comments on commit 4a7754a

Please sign in to comment.