Skip to content

Commit

Permalink
Simplify DBusError tests
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Jun 8, 2022
1 parent 10eef07 commit 3386c6f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
18 changes: 10 additions & 8 deletions web/src/DBusError.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,27 @@
import React from "react";

import { screen } from "@testing-library/react";
import { installerRender } from "./test-utils";
import { installerRender, plainRender } from "./test-utils";

import DBusError from "./DBusError";

describe("DBusError", () => {
it("includes a generic D-Bus connection problem message", async () => {
installerRender(<DBusError />);
it("includes a generic D-Bus connection problem message", () => {
plainRender(<DBusError />);

await screen.findByText(/Could not connect to the D-Bus service/i);
expect(screen.getByText(/Could not connect to the D-Bus service/i))
.toBeInTheDocument()
});

it("includes a button for reloading", async () => {
installerRender(<DBusError />);
it("includes a button for reloading", () => {
plainRender(<DBusError />);

await screen.findByRole("button", { name: /Reload/i });
expect(screen.getByText(/Could not connect to the D-Bus service/i))
.toBeInTheDocument()
});

it("calls location.reload when user clicks on 'Reload'", async () => {
const { user } = installerRender(<DBusError />);
const { user } = plainRender(<DBusError />);

const reloadButton = await screen.findByRole("button", { name: /Reload/i });

Expand Down
7 changes: 6 additions & 1 deletion web/src/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,9 @@ const installerRender = (ui, options = {}) => ({
...render(ui, { wrapper: InstallerProvider, ...options })
});

export { installerRender };
const plainRender = (ui, options = {}) => ({
user: userEvent.setup(),
...render(ui, options)
});

export { installerRender, plainRender };

0 comments on commit 3386c6f

Please sign in to comment.