Repository navigation
fix(tasks): apply ID sorting on the first click #483
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
Open
WiseShrestha
wants to merge
1
commit into
CCExtractor:main
Choose a base branch
from
WiseShrestha:gsoc/ccsync-id-sort-first-click
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2091,30 +2091,42 @@ describe('Tasks Component', () => { | |
| }); | ||
|
|
||
| describe('Column sorting', () => { | ||
| test('clicking the ID header toggles ID sort order', async () => { | ||
| const visibleTaskIds = () => | ||
| screen | ||
| .getAllByTestId(/^task-row-/) | ||
| .map((row) => Number(row.id.replace('task-row-', ''))); | ||
|
|
||
| test('the first ID click sorts ascending and the next restores descending order', async () => { | ||
| render(<Tasks {...mockProps} />); | ||
| await screen.findByText('Task 12'); | ||
|
|
||
| const idHeader = screen.getByText('ID').closest('th') as HTMLElement; | ||
| // State starts as 'asc' while the loaded list is already desc, so the first | ||
| // click re-applies desc. The second click sorts ascending and reverses rows. | ||
| await act(async () => { | ||
| fireEvent.click(idHeader); | ||
| }); | ||
| const afterFirst = screen | ||
| .getAllByTestId(/task-row-/) | ||
| .map((row) => row.getAttribute('data-testid')); | ||
| const idHeader = screen.getByRole('columnheader', { name: 'ID' }); | ||
| const initialOrder = visibleTaskIds(); | ||
| expect(initialOrder).toEqual([1, 17, 16, 15, 14, 13, 12, 11, 10, 9]); | ||
|
|
||
| await act(async () => { | ||
| fireEvent.click(idHeader); | ||
| }); | ||
| fireEvent.click(idHeader); | ||
| expect(visibleTaskIds()).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); | ||
|
|
||
| fireEvent.click(idHeader); | ||
| expect(visibleTaskIds()).toEqual(initialOrder); | ||
| }); | ||
|
|
||
| test('the first ID click after sync sorts ascending again', async () => { | ||
| render(<Tasks {...mockProps} />); | ||
| await screen.findByText('Task 12'); | ||
|
|
||
| const idHeader = screen.getByRole('columnheader', { name: 'ID' }); | ||
| const initialOrder = visibleTaskIds(); | ||
| fireEvent.click(idHeader); | ||
| expect(visibleTaskIds()).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); | ||
|
|
||
| fireEvent.click(screen.getAllByText('Sync')[0]); | ||
| await waitFor(() => { | ||
| const afterSecond = screen | ||
| .getAllByTestId(/task-row-/) | ||
| .map((row) => row.getAttribute('data-testid')); | ||
| expect(afterSecond).not.toEqual(afterFirst); | ||
| expect(visibleTaskIds()).toEqual(initialOrder); | ||
| }); | ||
|
|
||
| fireEvent.click(idHeader); | ||
| expect(visibleTaskIds()).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test sorts ascending before syncing so it exercises the stale-state case. It then checks the visible row order after sync and after one click. That catches the extra-click bug, which a test that only checks whether the rows eventually change would miss. |
||
| }); | ||
|
|
||
| test('clicking the Status header reorders tasks by status', async () => { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sync reloads the rows in descending ID order. If I had sorted ascending before syncing, the stored direction would still be
ascso the next click would apply descending order again and look like it did nothing. Resetting the direction here keeps it aligned with the rows on screen.