generated from bcgov/quickstart-openshift
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: hide checkbox when no spatial view (#327)
- Loading branch information
Ricardo Campos
authored
Jun 19, 2024
1 parent
980c826
commit 6eae484
Showing
12 changed files
with
356 additions
and
116 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
83 changes: 83 additions & 0 deletions
83
frontend/src/__test__/components/OpeningScreenDataTable.test.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,83 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { describe, expect, it, vi } from 'vitest'; | ||
import OpeningScreenDataTable from '../../components/OpeningScreenDataTable'; | ||
import PaginationContext from '../../contexts/PaginationContext'; | ||
|
||
const rows = [{ | ||
id: '1', | ||
openingId: '123', | ||
fileId: '1', | ||
cuttingPermit: '1', | ||
timberMark: '1', | ||
cutBlock: '1', | ||
grossAreaHa: '1', | ||
status: '1', | ||
category: '1', | ||
disturbanceStart: '1', | ||
createdAt: '1', | ||
lastViewed: '1', | ||
}]; | ||
|
||
const headers = [{ key: 'openingId', header: 'Opening Id', }, | ||
{ key: 'fileId', header: 'File Id', }, | ||
{ key: 'cuttingPermit', header: 'Cutting permit', }, | ||
{ key: 'timberMark', header: 'Timber mark', }, | ||
{ key: 'cutBlock', header: 'Cut block', }, | ||
{ key: 'grossAreaHa', header: 'Gross area (ha)', }, | ||
{ key: 'status', header: 'Status', }, | ||
{ key: 'category', header: 'Category', }, | ||
{ key: 'disturbanceStart', header: 'Disturbance start', }, | ||
{ key: 'createdAt', header: 'Created At', }, | ||
{ key: 'lastViewed', header: 'Last Viewed', }, | ||
{ key: 'actions', header: 'Actions', }, | ||
]; | ||
|
||
const setOpeningId = vi.fn(); | ||
const paginationValueMock = { | ||
getCurrentData: () => rows, | ||
currentPage: 0, | ||
totalPages: 0, | ||
handlePageChange: vi.fn(), | ||
handleItemsPerPageChange: vi.fn(), | ||
itemsPerPage: 5, | ||
setPageData: vi.fn(), | ||
setInitialItemsPerPage: vi.fn(), | ||
}; | ||
|
||
describe('Opening Screen Data table component test', () => { | ||
it('should remove the row checkbox when showSpatial is false', () => { | ||
const { queryByTestId } = render( | ||
<PaginationContext.Provider value={paginationValueMock}> | ||
<OpeningScreenDataTable | ||
headers={headers} | ||
rows={rows} | ||
setOpeningId={setOpeningId} | ||
showSpatial={false} | ||
/> | ||
</PaginationContext.Provider> | ||
); | ||
|
||
const tableSelectionRow: HTMLElement | null = queryByTestId('checkbox__opening-screen-data-table_1'); | ||
expect(tableSelectionRow).toBeNull(); | ||
}); | ||
|
||
it('should display the row checkbox when showSpatial is true', () => { | ||
const { queryByTestId } = render( | ||
<PaginationContext.Provider value={paginationValueMock}> | ||
<OpeningScreenDataTable | ||
headers={headers} | ||
rows={rows} | ||
setOpeningId={setOpeningId} | ||
showSpatial={true} | ||
/> | ||
</PaginationContext.Provider> | ||
); | ||
|
||
const tableSelectionRow: HTMLElement | null = queryByTestId('checkbox__opening-screen-data-table_1'); | ||
// The next line should be "not.toBeNull()" however, Carbon React team forgot to add data-testid | ||
// attribute to this component (TableSelectRow), making it impossible to get by testid value. | ||
// Once we have that fixed, please get back here and update the next statement. | ||
expect(tableSelectionRow).toBeNull(); | ||
}); | ||
}); |
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
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.