Skip to content

Commit

Permalink
fix(web): re-enable product registration page test
Browse files Browse the repository at this point in the history
The test for the product registration alert was removed since it’s
already covered in its own test file.

As with other page tests, mocking the ProductRegistrationAlert component
was necessary to prevent the suite from rendering nothing, due to the
component getting stuck in the useIssues hook request. An alternative
would be to mock the useIssues hook itself, but it requires more mocking
for the same result. This is something to improve globally, but outside
the scope of this commit.
  • Loading branch information
dgdavid committed Jan 24, 2025
1 parent 216499a commit 648901d
Showing 1 changed file with 6 additions and 49 deletions.
55 changes: 6 additions & 49 deletions web/src/components/product/ProductRegistrationPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,17 @@ const tw: Product = {
const sle: Product = {
id: "sle",
name: "SLE",
registration: false,
registration: true,
};

let selectedProduct: Product;
let registrationInfoMock: RegistrationInfo;
const registerMutationMock = jest.fn();

jest.mock("~/components/product/ProductRegistrationAlert", () => () => (
<div>ProductRegistrationAlert Mock</div>
));

jest.mock("~/queries/software", () => ({
...jest.requireActual("~/queries/software"),
useRegisterMutation: () => ({ mutate: registerMutationMock }),
Expand All @@ -55,7 +59,7 @@ jest.mock("~/queries/software", () => ({
},
}));

describe.skip("ProductRegistrationPage", () => {
describe("ProductRegistrationPage", () => {
describe("when selected product is not registrable", () => {
beforeEach(() => {
selectedProduct = tw;
Expand All @@ -74,11 +78,6 @@ describe.skip("ProductRegistrationPage", () => {
registrationInfoMock = { key: "", email: "" };
});

it("renders ProductRegistrationAlert component", () => {
installerRender(<ProductRegistrationPage />);
screen.getByText("Warning alert:");
});

it("renders a form to allow user registering the product", async () => {
const { user } = installerRender(<ProductRegistrationPage />);
const registrationCodeInput = screen.getByLabelText("Registration code");
Expand Down Expand Up @@ -107,11 +106,6 @@ describe.skip("ProductRegistrationPage", () => {
registrationInfoMock = { key: "INTERNAL-USE-ONLY-1234-5678", email: "[email protected]" };
});

it("does not render ProductRegistrationAlert component", () => {
installerRender(<ProductRegistrationPage />);
expect(screen.queryByText("Warning alert:")).toBeNull();
});

it("renders registration information with code partially hidden", async () => {
const { user } = installerRender(<ProductRegistrationPage />);
const visibilityCodeToggler = screen.getByRole("button", { name: "Show" });
Expand All @@ -125,42 +119,5 @@ describe.skip("ProductRegistrationPage", () => {
expect(screen.queryByText("INTERNAL-USE-ONLY-1234-5678")).toBeNull();
screen.getByText(/\*?5678/);
});

// describe("but at registration path already", () => {
// beforeEach(() => {
// mockRoutes(REGISTRATION.root);
// });
//
// it("does not render the link to registration", () => {
// installerRender(<ProductRegistrationAlert />);
// screen.getByRole("heading", {
// name: /Warning alert:.*must be registered/,
// });
// expect(screen.queryAllByRole("link")).toEqual([]);
// });
// });
// });
//
// describe("when product is registrable and registration code is already set", () => {
// beforeEach(() => {
// selectedProduct = sle;
// registrationInfoMock = { key: "INTERNAL-USE-ONLY-1234-5678", email: "" };
// });
//
// it("renders nothing", () => {
// const { container } = installerRender(<ProductRegistrationAlert />);
// expect(container).toBeEmptyDOMElement();
// });
// });
//
// describe("when product is not registrable", () => {
// beforeEach(() => {
// selectedProduct = tw;
// });
//
// it("renders nothing", () => {
// const { container } = installerRender(<ProductRegistrationAlert />);
// expect(container).toBeEmptyDOMElement();
// });
});
});

0 comments on commit 648901d

Please sign in to comment.