Skip to content

Commit 15414dd

Browse files
committed
chore: Add tests for register name dispute component
1 parent c9b364c commit 15414dd

1 file changed

Lines changed: 66 additions & 8 deletions

File tree

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,83 @@
11
import { BrowserRouter } from "react-router-dom";
2+
import { QueryClient, QueryClientProvider, useQuery } from "react-query";
23
import { render, screen } from "@testing-library/react";
4+
import userEvent from "@testing-library/user-event";
35
import "@testing-library/jest-dom";
46

5-
import RegisterNameDisputeSuccess from "../RegisterNameDisputeSuccess";
7+
import RegisterNameDispute from "../RegisterNameDispute";
8+
9+
jest.mock("react-router-dom", () => {
10+
return {
11+
...jest.requireActual("react-router-dom"),
12+
useSearchParams: () => [
13+
new URLSearchParams({ "snap-name": "test-snap-id", store: "ubuntu" }),
14+
],
15+
};
16+
});
17+
18+
jest.mock("react-query", () => ({
19+
...jest.requireActual("react-query"),
20+
useQuery: jest.fn().mockReturnValue({
21+
data: [
22+
{
23+
id: "ubuntu",
24+
name: "Global",
25+
roles: ["view", "access"],
26+
},
27+
],
28+
isLoading: false,
29+
}),
30+
}));
31+
32+
const queryClient = new QueryClient();
633

734
function renderComponent() {
835
return render(
936
<BrowserRouter>
10-
<RegisterNameDisputeSuccess snapName="test-snap" />
37+
<QueryClientProvider client={queryClient}>
38+
<RegisterNameDispute />
39+
</QueryClientProvider>
1140
</BrowserRouter>,
1241
);
1342
}
1443

15-
describe("RegisterNameDisputeSuccess", () => {
44+
describe("RegisterNameDispute", () => {
1645
test("the snap name is shown", () => {
1746
renderComponent();
47+
const el = screen.getByText("Claim the name", { exact: false });
48+
expect(el.textContent).toEqual("Claim the name test-snap-id");
49+
});
50+
51+
test("store field shows correct store", () => {
52+
renderComponent();
53+
expect(screen.getByLabelText("Store")).toHaveValue("Global");
54+
});
55+
56+
test("snap name field show correct snap", () => {
57+
renderComponent();
58+
expect(screen.getByLabelText("Snap name")).toHaveValue("test-snap-id");
59+
});
60+
61+
test("'Register a new name' link is on page", () => {
62+
renderComponent();
63+
expect(
64+
screen.getByRole("link", { name: "Register a new name" }),
65+
).toHaveAttribute("href", "/register-snap");
66+
});
67+
68+
test("'Submit name claim' button is disabled", () => {
69+
renderComponent();
70+
expect(
71+
screen.getByRole("button", { name: "Submit name claim" }),
72+
).toHaveAttribute("aria-disabled", "true");
73+
});
74+
75+
test("'adding comment enables 'Submit name claim' button", async () => {
76+
const user = userEvent.setup();
77+
renderComponent();
78+
await user.type(screen.getByLabelText("Comment"), "Test comment");
1879
expect(
19-
screen.getByRole("heading", {
20-
level: 1,
21-
name: /Thank you for requesting the name test-snap/,
22-
}),
23-
);
80+
screen.getByRole("button", { name: "Submit name claim" }),
81+
).not.toHaveAttribute("aria-disabled");
2482
});
2583
});

0 commit comments

Comments
 (0)