Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: add count endpoint for users, enabling better pagination #4848

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Nov 8, 2022
Merged
Prev Previous commit
Next Next commit
Add to frontend test
  • Loading branch information
presleyp committed Nov 1, 2022
commit 97027d23aebf7ad5cb090c49188ca4fe31709922
10 changes: 8 additions & 2 deletions site/src/pages/UsersPage/UsersPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -240,27 +240,33 @@ describe("UsersPage", () => {

describe("pagination", () => {
it("goes to next and previous page", async () => {
renderPage()
const { container } = renderPage()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love that we have tests and I'm happy to keep these in there. I'm curious if we should just add tests for the pagination widget itself, rather than tests for each time it's implemented.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I added a bit to the widget in a previous PR but I think there's also value in making sure the page is using the widget properly

const user = userEvent.setup()

const mock = jest
.spyOn(API, "getUsers")
.mockResolvedValueOnce([MockUser, MockUser2])

const nextButton = await screen.findByLabelText("Next page")
expect(nextButton).toBeEnabled()
const previousButton = await screen.findByLabelText("Previous page")
expect(previousButton).toBeDisabled()
await user.click(nextButton)

await waitFor(() =>
expect(API.getUsers).toBeCalledWith({ offset: 25, limit: 25, q: "" }),
)

mock.mockClear()
const previousButton = await screen.findByLabelText("Previous page")
await user.click(previousButton)

await waitFor(() =>
expect(API.getUsers).toBeCalledWith({ offset: 0, limit: 25, q: "" }),
)

const pageButtons = await container.querySelectorAll(`button[name="Page button"]`)
// count handler says there are 2 pages of results
expect(pageButtons.length).toBe(2)
})
})

Expand Down