diff --git a/frontend/src/__test__/components/SilvicultureSearch/Openings/SearchScreenDataTable.test.tsx b/frontend/src/__test__/components/SilvicultureSearch/Openings/SearchScreenDataTable.test.tsx index 7b8108dc..7bd3adfe 100644 --- a/frontend/src/__test__/components/SilvicultureSearch/Openings/SearchScreenDataTable.test.tsx +++ b/frontend/src/__test__/components/SilvicultureSearch/Openings/SearchScreenDataTable.test.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { render, screen } from '@testing-library/react'; +import { render, screen, fireEvent } from '@testing-library/react'; import { describe, expect, it, vi } from 'vitest'; import SearchScreenDataTable from '../../../../components/SilvicultureSearch/Openings/SearchScreenDataTable'; import { columns } from '../../../../components/SilvicultureSearch/Openings/SearchScreenDataTable/headerData'; @@ -11,6 +11,7 @@ import { OpeningsSearchProvider } from '../../../../contexts/search/OpeningsSear const handleCheckboxChange = vi.fn(); const toggleSpatial = vi.fn(); +const setOpeningIds = vi.fn((openingIds: number[]) => {}); const queryClient = new QueryClient(); export const rows:any = [ @@ -259,6 +260,7 @@ describe('Search Screen Data table test', () => { handleCheckboxChange={handleCheckboxChange} toggleSpatial={toggleSpatial} totalItems={rows.length} + setOpeningIds={setOpeningIds} /> @@ -289,6 +291,7 @@ describe('Search Screen Data table test', () => { handleCheckboxChange={handleCheckboxChange} toggleSpatial={toggleSpatial} totalItems={0} + setOpeningIds={setOpeningIds} /> @@ -303,7 +306,7 @@ describe('Search Screen Data table test', () => { expect(container.querySelector('.total-search-results')).toContainHTML('0'); }); - it('should render the checkbox for showSPatial being true', () => { + it('should render the checkbox for showSpatial being true', () => { render( @@ -318,6 +321,7 @@ describe('Search Screen Data table test', () => { handleCheckboxChange={handleCheckboxChange} toggleSpatial={toggleSpatial} totalItems={0} + setOpeningIds={setOpeningIds} /> @@ -329,6 +333,40 @@ describe('Search Screen Data table test', () => { expect(checkbox).toBeInTheDocument(); }); + + it('should check the checkbox for showSpatial', () => { + render( + + + + + + + + + + + + ); + const checkboxGroup = document.querySelector('.cds--checkbox-group'); + expect(checkboxGroup).toBeInTheDocument(); + + expect(screen.getByTestId(`checkbox-${rows[0].openingId}`)).toBeInTheDocument(); + const checkbox = screen.getByTestId(`checkbox-${rows[0].openingId}`); + fireEvent.click(checkbox); + expect(checkbox).toBeChecked(); + expect(setOpeningIds).toHaveBeenCalledWith([parseFloat(rows[0].openingId)]); + + }); }); \ No newline at end of file diff --git a/frontend/src/components/SilvicultureSearch/Openings/SearchScreenDataTable/index.tsx b/frontend/src/components/SilvicultureSearch/Openings/SearchScreenDataTable/index.tsx index b4735f88..4e9d6de9 100644 --- a/frontend/src/components/SilvicultureSearch/Openings/SearchScreenDataTable/index.tsx +++ b/frontend/src/components/SilvicultureSearch/Openings/SearchScreenDataTable/index.tsx @@ -358,6 +358,7 @@ const SearchScreenDataTable: React.FC = ({