Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: fix workspaces pagination#19448

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
BrunoQuaresma merged 5 commits intomainfrombq/18707
Aug 21, 2025
Merged

fix: fix workspaces pagination#19448

BrunoQuaresma merged 5 commits intomainfrombq/18707
Aug 21, 2025

Conversation

BrunoQuaresma
Copy link
Collaborator

Fixes#18707

Before:

Screen.Recording.2025-08-20.at.10.44.36.mov

After:

Screen.Recording.2025-08-20.at.10.44.52.mov

@BrunoQuaresmaBrunoQuaresma requested review fromParkreiner anda teamAugust 20, 2025 13:47
@BrunoQuaresmaBrunoQuaresma self-assigned thisAug 20, 2025
Copy link
Member

@aslilacaslilac left a comment

Choose a reason for hiding this comment

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

the actual guts of the change are straight forward and good, but the test seems a bit wonky. can we pls clean it up a little more before merging?

BrunoQuaresma reacted with thumbs up emoji
constsecondCallArgs=getWorkspacesSpy.mock.calls[1][0];
expect(firstCallArgs.offset).toBe(0);
expect(secondCallArgs.offset).toBe(25);
expect(firstCallArgs.offset).not.toBe(secondCallArgs.offset);
Copy link
Member

Choose a reason for hiding this comment

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

redundant, we just asserted that it’s0


// Verify the key difference: the offset changed between calls
constfirstCallArgs=getWorkspacesSpy.mock.calls[0][0];
constsecondCallArgs=getWorkspacesSpy.mock.calls[1][0];
Copy link
Member

Choose a reason for hiding this comment

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

we just asserted on this withtoHaveBeenNthCalledWith

constnextPageButton=screen.getByRole("button",{name:/nextpage/i});
awaituser.click(nextPageButton);

// Wait for second page to load
Copy link
Member

Choose a reason for hiding this comment

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

this comment doesn’t add anything imo

constuser=userEvent.setup();
renderWithAuth(<WorkspacesPage/>);

// Wait for first page to load
Copy link
Member

Choose a reason for hiding this comment

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

same here.waitFor is already the name of the function being called.

Comment on lines 324 to 332
getWorkspacesSpy
.mockResolvedValueOnce({
workspaces:workspacesPage1,
count:totalWorkspaces,
})
.mockResolvedValueOnce({
workspaces:workspacesPage2,
count:totalWorkspaces,
});
Copy link
Member

@ParkreinerParkreinerAug 20, 2025
edited
Loading

Choose a reason for hiding this comment

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

I feel like this setup is a little fragile. I've never stacked multiple calls tomockResolvedValueOnce onto the same spy before, but if I'm reading it right, it means that, no matter what we actually call the function with, we'll always get page 1 for the first call, and page 2 for the second call. But then:

  • Any future calls immediately go back to the actual non-mocked version
  • We never check the inputs for the functions to decide what to return out. If we accidentally pass page 3 in, we might get page 1 or we might get page 2
  • If we try to get page 1 multiple times, we can't

I don't know all the details, but I know that MSW has tools to mock out the API response. Maybe that's not needed and we could keep the Jest Spys, but I think I'd rather make it so that we have a mock that stays locked in for the duration of the test, and then checks the page input:

  • A page value of 1 always gives back page 1 content
  • A page value of 2 always gives back page 2 content
  • Any other page values just give back an empty array

Copy link
Member

@ParkreinerParkreinerAug 20, 2025
edited
Loading

Choose a reason for hiding this comment

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

I know you have the checks for the exact inputs a little bit below, but if the React testing tools ever add double-rendering to help check for correctness (like what you get withStrictMode and dev mode), that would immediately cause this test to break

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

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

Not sure if I got it. Let me share what I understood.

The issue with this test is it is using stackedmockResolvedValueOnce to mock the responses for the first and second calls so, if react renders twice in the same page, the test would break. Is that right?

Copy link
Member

@ParkreinerParkreinerAug 20, 2025
edited
Loading

Choose a reason for hiding this comment

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

Yeah, if React ever double-mounts the same hook for the data fetching, this will happen if we start at page 1:

  1. The page component gets mounted, and we trigger the data fetch, using a page value of 1 as input. The function is mocked, so we always get the page 1 data back no matter what
  2. The render completes
  3. React unmounts and re-mounts the component from scratch, which potentially causes a second data fetch, still using a page value of 1 as input
  4. But because we've already popped off the first mock, calling the function with a page value of 1 actually gets us page 2's data, because the mock doesn't actually check what number gets passed in
  5. We get back page 2's data, and render that out. React considers the render "stabilized"
  6. We go back to the testing/assertion logic, and the tests fail because the page 1 content is no longer on screen
  7. If we were to keep going, and try switching the page value to 2 by clicking the UI, we have no more mocks left, and the call goes to the actual API implementation

BrunoQuaresma reacted with thumbs up emoji
Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

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

Updated thespyOn to use themockImplementation, wdyt?

Copy link
Member

@aslilacaslilac left a comment

Choose a reason for hiding this comment

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

thanks bruno! one last suggestion, but this test is looking much better.

Comment on lines 348 to 349
expect(getWorkspacesSpy).toHaveBeenNthCalledWith(
1,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
expect(getWorkspacesSpy).toHaveBeenNthCalledWith(
1,
expect(getWorkspacesSpy).toHaveBeenLastCalledWith(

one last thing, I thinktoHaveBeenLastCalledWith would be better here. to michael's point: how many times this function actually gets called could be considered an implementation detail of react. but we do know we want it to have been called, and that at least the most recent call should match this assertion.

https://jestjs.io/docs/expect#tohavebeenlastcalledwitharg1-arg2-

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

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

Makes sense! 👍

Comment on lines 364 to 365
expect(getWorkspacesSpy).toHaveBeenNthCalledWith(
2,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
expect(getWorkspacesSpy).toHaveBeenNthCalledWith(
2,
expect(getWorkspacesSpy).toHaveBeenLastCalledWith(

same thought here

@BrunoQuaresmaBrunoQuaresma merged commit54440af intomainAug 21, 2025
43 of 46 checks passed
@BrunoQuaresmaBrunoQuaresma deleted the bq/18707 branchAugust 21, 2025 17:59
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsAug 21, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@aslilacaslilacaslilac approved these changes

@ParkreinerParkreinerAwaiting requested review from ParkreinerParkreiner is a code owner

Assignees

@BrunoQuaresmaBrunoQuaresma

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Workspaces list pagination is slow with several hundred workspaces
3 participants
@BrunoQuaresma@aslilac@Parkreiner

[8]ページ先頭

©2009-2025 Movatter.jp