Skip to content

Commit

Permalink
test(web): fix issues-related tests
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Jul 17, 2024
1 parent b821241 commit e45a059
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 76 deletions.
6 changes: 6 additions & 0 deletions web/src/App.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { STARTUP, CONFIG, INSTALL } from "~/client/phase";
import { IDLE, BUSY } from "~/client/status";
import { useL10nConfigChanges } from "./queries/l10n";
import { useProductChanges } from "./queries/software";
import { useIssuesChanges } from "./queries/issues";

jest.mock("~/client");

Expand All @@ -52,6 +53,11 @@ jest.mock("~/queries/l10n", () => ({
useL10nConfigChanges: () => jest.fn(),
}));

jest.mock("~/queries/issues", () => ({
...jest.requireActual("~/queries/issues"),
useIssuesChanges: () => jest.fn(),
}));

const mockClientStatus = {
connected: true,
error: false,
Expand Down
72 changes: 0 additions & 72 deletions web/src/client/storage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1346,78 +1346,6 @@ describe.skip("#onDeprecate", () => {
});
});

describe("#getIssues", () => {
beforeEach(() => {
client = new StorageClient(http);
});

describe("if there are no issues", () => {
beforeEach(() => {
mockJsonFn.mockResolvedValue([]);
});

it("returns an empty list", async () => {
const issues = await client.getIssues();
expect(issues).toEqual([]);
});
});

describe("if there are issues", () => {
beforeEach(() => {
mockJsonFn.mockResolvedValue(contexts.withIssues());
});

it("returns the list of issues", async () => {
const issues = await client.getIssues();
expect(issues).toEqual(
expect.arrayContaining([
{ description: "Issue 1", details: "", source: "system", severity: "error" },
{ description: "Issue 2", details: "", source: "system", severity: "warn" },
{ description: "Issue 3", details: "", source: "config", severity: "error" },
]),
);
});
});
});

describe("#getErrors", () => {
beforeEach(() => {
client = new StorageClient(http);
mockJsonFn.mockResolvedValue(contexts.withIssues());
});

it("returns the issues with error severity", async () => {
const errors = await client.getErrors();
expect(errors.map((e) => e.description)).toEqual(
expect.arrayContaining(["Issue 1", "Issue 3"]),
);
});
});

// @fixme See note at the test of onDeprecate about mocking signals
describe.skip("#onIssuesChange", () => {
it("runs the handler when the issues change", async () => {
client = new StorageClient();

const handler = jest.fn();
client.onIssuesChange(handler);

emitSignal("/org/opensuse/Agama/Storage1", "org.opensuse.Agama1.Issues", {
All: {
v: [
["Issue 1", "", 1, 0],
["Issue 2", "", 2, 1],
],
},
});

expect(handler).toHaveBeenCalledWith([
{ description: "Issue 1", details: "", source: "system", severity: "warn" },
{ description: "Issue 2", details: "", source: "config", severity: "error" },
]);
});
});

describe("#system", () => {
describe("#getDevices", () => {
beforeEach(() => {
Expand Down
14 changes: 10 additions & 4 deletions web/src/components/overview/OverviewPage.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ import { screen } from "@testing-library/react";
import { installerRender } from "~/test-utils";
import { createClient } from "~/client";
import { OverviewPage } from "~/components/overview";
import { IssuesList } from "~/types/issues";

const startInstallationFn = jest.fn();
let mockSelectedProduct = { id: "Tumbleweed" };
const mockIssuesList = new IssuesList([], [], [], []);

jest.mock("~/client");
jest.mock("~/queries/software", () => ({
Expand All @@ -35,6 +37,11 @@ jest.mock("~/queries/software", () => ({
useProductChanges: () => jest.fn(),
}));

jest.mock("~/queries/issues", () => ({
...jest.requireActual("~/queries/issues"),
useIssuesChanges: () => jest.fn().mockResolvedValue(mockIssuesList),
}));

jest.mock("~/components/overview/L10nSection", () => () => <div>Localization Section</div>);
jest.mock("~/components/overview/StorageSection", () => () => <div>Storage Section</div>);
jest.mock("~/components/overview/SoftwareSection", () => () => <div>Software Section</div>);
Expand All @@ -46,7 +53,6 @@ beforeEach(() => {
manager: {
startInstallation: startInstallationFn,
},
issues: jest.fn().mockResolvedValue({ isEmpty: true }),
};
});
});
Expand All @@ -58,9 +64,9 @@ describe("when a product is selected", () => {

it("renders the overview page content and the Install button", async () => {
installerRender(<OverviewPage />);
screen.getByText("Localization Section");
screen.getByText("Storage Section");
screen.getByText("Software Section");
screen.findByText("Localization Section");
screen.findByText("Storage Section");
screen.findByText("Software Section");
screen.findByText("Install Button");
});
});

0 comments on commit e45a059

Please sign in to comment.