Skip to content

Commit e005aaf

Browse files
committed
Add tests
1 parent 86cda48 commit e005aaf

File tree

2 files changed

+49
-7
lines changed

2 files changed

+49
-7
lines changed

site/src/components/PaginationWidget/PaginationWidget.test.tsx

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,13 @@ describe("PaginatedList", () => {
99
<PaginationWidget
1010
prevLabel="Previous"
1111
nextLabel="Next"
12-
paginationRef={createPaginationRef({ page: 1, limit: 12 })}
12+
paginationRef={createPaginationRef({ page: 2, limit: 12 })}
1313
numRecords={200}
1414
/>,
1515
)
1616

17-
expect(
18-
screen.getByRole("button", { name: "Previous page" }),
19-
).toBeInTheDocument()
20-
expect(
21-
screen.getByRole("button", { name: "Next page" }),
22-
).toBeInTheDocument()
17+
expect(screen.getByRole("button", { name: "Previous page" })).toBeEnabled()
18+
expect(screen.getByRole("button", { name: "Next page" })).toBeEnabled()
2319
})
2420

2521
it("displays the expected number of pages with one ellipsis tile", () => {
@@ -53,4 +49,26 @@ describe("PaginatedList", () => {
5349
container.querySelectorAll(`button[name="Page button"]`),
5450
).toHaveLength(5)
5551
})
52+
53+
it("disables the previous button on the first page", () => {
54+
render(
55+
<PaginationWidget
56+
numRecords={100}
57+
paginationRef={createPaginationRef({ page: 1, limit: 25 })}
58+
/>,
59+
)
60+
const prevButton = screen.getByLabelText("Previous page")
61+
expect(prevButton).toBeDisabled()
62+
})
63+
64+
it("disables the next button on the last page", () => {
65+
render(
66+
<PaginationWidget
67+
numRecords={100}
68+
paginationRef={createPaginationRef({ page: 4, limit: 25 })}
69+
/>,
70+
)
71+
const nextButton = screen.getByLabelText("Next page")
72+
expect(nextButton).toBeDisabled()
73+
})
5674
})

site/src/pages/AuditPage/AuditPage.test.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,29 @@ describe("AuditPage", () => {
6565

6666
expect(getAuditLogsSpy).toBeCalledWith({ limit: 25, offset: 0, q: query })
6767
})
68+
69+
it("resets page to 1 when filter is changed", async () => {
70+
const getAuditLogsSpy = jest
71+
.spyOn(API, "getAuditLogs")
72+
.mockResolvedValue({ audit_logs: [MockAuditLog] })
73+
74+
history.push(`/audit?page=2`)
75+
render(<AuditPage />)
76+
77+
await waitForLoaderToBeRemoved()
78+
getAuditLogsSpy.mockReset()
79+
80+
const filterField = screen.getByLabelText("Filter")
81+
const query = "resource_type:workspace action:create"
82+
await userEvent.type(filterField, query)
83+
84+
await waitFor(() =>
85+
expect(getAuditLogsSpy).toBeCalledWith({
86+
limit: 25,
87+
offset: 0,
88+
q: query,
89+
}),
90+
)
91+
})
6892
})
6993
})

0 commit comments

Comments
 (0)