-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(j-s): Sort cases by IndictmentAppealDeadline (#15336)
* Checkpoint * Checkpoint * Sort now works * Testing sort now works with existing sorting mechanims * Cleanup * sortableTableColumn now has better types * Fix build errors * Checkpoint * Tests correct * Refactor * Fix lint * Revert RTL update * Revert RTL update * Revert RTL update * Use better types --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
- Loading branch information
1 parent
11e9ede
commit ab2522d
Showing
17 changed files
with
204 additions
and
97 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
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
91 changes: 91 additions & 0 deletions
91
apps/judicial-system/web/src/components/Table/Table.spec.tsx
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 |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import faker from 'faker' | ||
import { act, render, screen } from '@testing-library/react' | ||
import userEvent from '@testing-library/user-event' | ||
|
||
import { CaseListEntry } from '@island.is/judicial-system-web/src/graphql/schema' | ||
import { | ||
ApolloProviderWrapper, | ||
IntlProviderWrapper, | ||
} from '@island.is/judicial-system-web/src/utils/testHelpers' | ||
|
||
import { sortableTableColumn } from '../../types' | ||
import Table from './Table' | ||
|
||
import '@testing-library/react' | ||
|
||
jest.mock('next/router', () => ({ | ||
useRouter() { | ||
return { | ||
pathname: '', | ||
query: { | ||
id: 'test_id', | ||
}, | ||
} | ||
}, | ||
})) | ||
|
||
describe('Table', () => { | ||
it('should sort by deadline', async () => { | ||
const user = userEvent.setup() | ||
|
||
const thead = [ | ||
{ | ||
title: 'Title', | ||
sortable: { | ||
isSortable: true, | ||
key: 'indictmentAppealDeadline' as sortableTableColumn, | ||
}, | ||
}, | ||
] | ||
|
||
const data: CaseListEntry[] = [ | ||
{ | ||
created: '2021-01-01T00:00:00Z', | ||
id: faker.datatype.uuid(), | ||
indictmentAppealDeadline: '2021-01-01T00:00:00Z', | ||
}, | ||
{ | ||
created: '2021-01-02T00:00:00Z', | ||
id: faker.datatype.uuid(), | ||
indictmentAppealDeadline: '2021-01-02T00:00:00Z', | ||
}, | ||
] | ||
|
||
const columns = [ | ||
{ | ||
cell: (row: CaseListEntry) => <p>{row.indictmentAppealDeadline}</p>, | ||
}, | ||
] | ||
|
||
render( | ||
<IntlProviderWrapper> | ||
<ApolloProviderWrapper> | ||
<Table thead={thead} data={data} columns={columns} /> | ||
</ApolloProviderWrapper> | ||
</IntlProviderWrapper>, | ||
) | ||
|
||
await act(async () => { | ||
await user.click( | ||
await screen.findByTestId('indictmentAppealDeadlineSortButton'), | ||
) | ||
}) | ||
|
||
const tableRows = await screen.findAllByTestId('tableRow') | ||
|
||
// The first click sorts by ascending order, so the first row should be the one with the earliest date | ||
expect(tableRows[0]).toHaveTextContent('2021-01-01T00:00:00Z') | ||
expect(tableRows[1]).toHaveTextContent('2021-01-02T00:00:00Z') | ||
|
||
await act(async () => { | ||
await user.click( | ||
await screen.findByTestId('indictmentAppealDeadlineSortButton'), | ||
) | ||
}) | ||
|
||
// The second click sorts by descending order, so the first row should be the one with the latest date | ||
const tableRows2 = await screen.findAllByTestId('tableRow') | ||
expect(tableRows2[0]).toHaveTextContent('2021-01-02T00:00:00Z') | ||
expect(tableRows2[1]).toHaveTextContent('2021-01-01T00:00:00Z') | ||
}) | ||
}) |
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
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
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
Oops, something went wrong.