-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We are displaying all team's members in a datagrid. This propose to enable sorting on columns, to easily find members. Please note that few issues were faced when activating the sorting on the Cunningham components. First, custom columns can not be sorted (yet), a PR has been merged on Cunningham's side. We're waiting for the next release. Second, when sorting data rows, if any of the column has some null values, the datagrid sorting state becomes inconsistent. Thx @AntoLC for spotting the issue. It's work in progress on Cunningham's side to fix the issue. Finally, Cunningham export only the SortModel type, which is an array, and doesn't export its items' type. I might have miss something but it feels weird to redefine its items type. Columns wiggle on sorting, because they data is set to undefined while fetching the next batch. it's visually weird, but not a major pain. Next release of Cunningham will allow us to set the column to a fixed size.
- Loading branch information
1 parent
7c488a9
commit a106503
Showing
3 changed files
with
200 additions
and
15 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import '@testing-library/jest-dom'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { render, screen, waitFor } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import fetchMock from 'fetch-mock'; | ||
|
||
|
@@ -215,4 +215,132 @@ describe('MemberGrid', () => { | |
screen.queryByLabelText('Add members to the team'), | ||
).not.toBeInTheDocument(); | ||
}); | ||
|
||
it.each([ | ||
['name', 'Names'], | ||
['email', 'Emails'], | ||
['role', 'Roles'], | ||
])('checks the sorting', async (ordering, header_name) => { | ||
const mockedData = [ | ||
{ | ||
id: '123', | ||
role: Role.ADMIN, | ||
user: { | ||
id: '123', | ||
name: 'albert', | ||
email: '[email protected]', | ||
}, | ||
abilities: {} as any, | ||
}, | ||
{ | ||
id: '789', | ||
role: Role.OWNER, | ||
user: { | ||
id: '456', | ||
name: 'philipp', | ||
email: '[email protected]', | ||
}, | ||
abilities: {} as any, | ||
}, | ||
{ | ||
id: '456', | ||
role: Role.MEMBER, | ||
user: { | ||
id: '789', | ||
name: 'fany', | ||
email: '[email protected]', | ||
}, | ||
abilities: {} as any, | ||
}, | ||
]; | ||
|
||
const sortedMockedData = [...mockedData].sort((a, b) => | ||
a.id > b.id ? 1 : -1, | ||
); | ||
const reversedMockedData = [...sortedMockedData].reverse(); | ||
|
||
fetchMock.get(`/api/teams/123456/accesses/?page=1`, { | ||
count: 3, | ||
results: mockedData, | ||
}); | ||
|
||
fetchMock.get(`/api/teams/123456/accesses/?page=1&ordering=${ordering}`, { | ||
count: 3, | ||
results: sortedMockedData, | ||
}); | ||
|
||
fetchMock.get(`/api/teams/123456/accesses/?page=1&ordering=-${ordering}`, { | ||
count: 3, | ||
results: reversedMockedData, | ||
}); | ||
|
||
render(<MemberGrid team={team} currentRole={Role.ADMIN} />, { | ||
wrapper: AppWrapper, | ||
}); | ||
|
||
expect(screen.getByRole('status')).toBeInTheDocument(); | ||
|
||
expect(fetchMock.lastUrl()).toBe(`/api/teams/123456/accesses/?page=1`); | ||
|
||
await waitFor(() => { | ||
expect(screen.queryByRole('status')).not.toBeInTheDocument(); | ||
}); | ||
|
||
let rows = screen.getAllByRole('row'); | ||
expect(rows[1]).toHaveTextContent('albert'); | ||
expect(rows[2]).toHaveTextContent('philipp'); | ||
expect(rows[3]).toHaveTextContent('fany'); | ||
|
||
expect(screen.queryByLabelText('arrow_drop_down')).not.toBeInTheDocument(); | ||
expect(screen.queryByLabelText('arrow_drop_up')).not.toBeInTheDocument(); | ||
|
||
await userEvent.click(screen.getByText(header_name)); | ||
|
||
expect(fetchMock.lastUrl()).toBe( | ||
`/api/teams/123456/accesses/?page=1&ordering=${ordering}`, | ||
); | ||
|
||
await waitFor(() => { | ||
expect(screen.queryByRole('status')).not.toBeInTheDocument(); | ||
}); | ||
|
||
rows = screen.getAllByRole('row'); | ||
expect(rows[1]).toHaveTextContent('albert'); | ||
expect(rows[2]).toHaveTextContent('fany'); | ||
expect(rows[3]).toHaveTextContent('philipp'); | ||
|
||
expect(await screen.findByText('arrow_drop_up')).toBeInTheDocument(); | ||
|
||
await userEvent.click(screen.getByText(header_name)); | ||
|
||
expect(fetchMock.lastUrl()).toBe( | ||
`/api/teams/123456/accesses/?page=1&ordering=-${ordering}`, | ||
); | ||
await waitFor(() => { | ||
expect(screen.queryByRole('status')).not.toBeInTheDocument(); | ||
}); | ||
|
||
rows = screen.getAllByRole('row'); | ||
expect(rows[1]).toHaveTextContent('philipp'); | ||
expect(rows[2]).toHaveTextContent('fany'); | ||
expect(rows[3]).toHaveTextContent('albert'); | ||
|
||
expect(await screen.findByText('arrow_drop_down')).toBeInTheDocument(); | ||
|
||
await userEvent.click(screen.getByText(header_name)); | ||
|
||
expect(fetchMock.lastUrl()).toBe('/api/teams/123456/accesses/?page=1'); | ||
|
||
await waitFor(() => { | ||
expect(screen.queryByRole('status')).not.toBeInTheDocument(); | ||
}); | ||
|
||
rows = screen.getAllByRole('row'); | ||
expect(rows[1]).toHaveTextContent('albert'); | ||
expect(rows[2]).toHaveTextContent('philipp'); | ||
expect(rows[3]).toHaveTextContent('fany'); | ||
|
||
expect(screen.queryByLabelText('arrow_drop_down')).not.toBeInTheDocument(); | ||
expect(screen.queryByLabelText('arrow_drop_up')).not.toBeInTheDocument(); | ||
}); | ||
}); |
This file contains 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 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