Skip to content

Commit d33de6c

Browse files
authored
fix: Address code coverage warnings in store from TiCS dashboard (#5097)
1 parent c821f3e commit d33de6c

8 files changed

Lines changed: 479 additions & 9 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { BrowserRouter } from "react-router-dom";
2+
import { render, screen } from "@testing-library/react";
3+
import "@testing-library/jest-dom";
4+
5+
import EmptyResultSection from "../EmptyResultSection";
6+
7+
const testSearchQuery = "Test search query";
8+
9+
function renderComponent() {
10+
render(
11+
<BrowserRouter>
12+
<EmptyResultSection searchTerm={testSearchQuery} isFetching={false} />
13+
</BrowserRouter>,
14+
);
15+
}
16+
17+
jest.mock("react-router-dom", () => {
18+
return {
19+
...jest.requireActual("react-router-dom"),
20+
useSearchParams: () => [new URLSearchParams({ q: testSearchQuery })],
21+
};
22+
});
23+
24+
describe("EmptyResultSection", () => {
25+
test("displays search query on the page", () => {
26+
renderComponent();
27+
expect(
28+
screen.getByRole("heading", {
29+
name: `Search results for "${testSearchQuery}"`,
30+
}),
31+
).toBeInTheDocument();
32+
});
33+
34+
test("search input shows search query", () => {
35+
renderComponent();
36+
expect(screen.getByRole("searchbox")).toHaveValue(testSearchQuery);
37+
});
38+
39+
test("links to explore featured snaps", () => {
40+
renderComponent();
41+
expect(
42+
screen.getByRole("link", {
43+
name: "Explore featured snaps",
44+
}),
45+
).toBeInTheDocument();
46+
});
47+
48+
test("links to contact page", () => {
49+
renderComponent();
50+
expect(
51+
screen.getByRole("link", {
52+
name: "Contact us",
53+
}),
54+
).toBeInTheDocument();
55+
});
56+
});

static/js/store/components/PackageFilter/PackageFilter.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { Button } from "@canonical/react-components";
22
import { useState } from "react";
3-
import type { Category, Packages } from "../../types";
43
import { Filters } from "@canonical/store-components";
54
import { useSearchParams } from "react-router-dom";
65
import { getArchitectures, getCategoryOrder } from "../../utils";
76

7+
import type { Category, Packages } from "../../types";
8+
89
export type ICategoryList =
910
| {
1011
display_name: string;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { BrowserRouter } from "react-router-dom";
2+
import { render, screen } from "@testing-library/react";
3+
import "@testing-library/jest-dom";
4+
5+
import { PackageFilter } from "../PackageFilter";
6+
7+
import { testPackageData } from "../../../test-utils";
8+
9+
const testCategoriesQueryString = "music-and-audio,productivity";
10+
11+
function renderComponent(isDisabled?: boolean) {
12+
render(
13+
<BrowserRouter>
14+
<PackageFilter data={testPackageData} disabled={isDisabled || false} />
15+
</BrowserRouter>,
16+
);
17+
}
18+
19+
jest.mock("react-router-dom", () => {
20+
return {
21+
...jest.requireActual("react-router-dom"),
22+
useSearchParams: () => [
23+
new URLSearchParams({ categories: testCategoriesQueryString }),
24+
],
25+
};
26+
});
27+
28+
describe("PackageFilter", () => {
29+
test("disabled if fetching data", () => {
30+
renderComponent(true);
31+
expect(screen.getByLabelText("Games")).toBeDisabled();
32+
});
33+
34+
test("selects categories from query string", () => {
35+
renderComponent();
36+
expect(screen.getByLabelText("Music and Audio")).toBeChecked();
37+
expect(screen.getByLabelText("Productivity")).toBeChecked();
38+
});
39+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { testPackageData } from "./testPackageData";
2+
3+
export { testPackageData };

0 commit comments

Comments
 (0)