diff --git a/packages/esm-commons-lib/src/components/patient-table/patient-table.test.tsx b/packages/esm-commons-lib/src/components/patient-table/patient-table.test.tsx new file mode 100644 index 000000000..90fc7636b --- /dev/null +++ b/packages/esm-commons-lib/src/components/patient-table/patient-table.test.tsx @@ -0,0 +1,99 @@ +import React from 'react'; +import { fireEvent, render } from '@testing-library/react'; +import { PatientTable } from './patient-table.component'; +import '@testing-library/jest-dom'; + +describe('PatientTable', () => { + const mockPatients = [{ name: 'John Doe', age: 35 }]; + + const mockColumns = [ + { key: 'name', header: 'Name', getValue: (patient) => patient.name }, + { key: 'age', header: 'Age', getValue: (patient) => patient.age }, + ]; + + const mockPagination = { + usePagination: true, + currentPage: 1, + onChange: jest.fn(), + pageSize: 10, + totalItems: 20, + }; + + it('renders patient table correctly with specific columns and patient', () => { + const { getByText } = render( + {}} + mutateListMembers={() => {}} + pagination={mockPagination} + patients={mockPatients} + />, + ); + + // Test whether the specific patient 'John Doe' and age (35) is rendered in the table + const johnDoeName = getByText('John Doe'); + expect(johnDoeName).toBeInTheDocument(); + const age35 = getByText('35'); + expect(age35).toBeInTheDocument(); + }); + + it('renders loading skeleton when isLoading is true', () => { + const { getByTestId } = render( + {}} + mutateListMembers={() => {}} + pagination={mockPagination} + patients={[]} + />, + ); + + // Test whether the loading skeleton is rendered + const skeleton = getByTestId('data-table-skeleton'); + expect(skeleton).toBeInTheDocument(); + }); + + it('renders empty state when no patients are present', () => { + const { getByText } = render( + {}} + mutateListMembers={() => {}} + pagination={mockPagination} + patients={[]} + />, + ); + + // Test whether the empty state message is rendered + const emptyStateMessage = getByText('There are no patients in this list'); + expect(emptyStateMessage).toBeInTheDocument(); + }); + + it('filters patients based on search term', () => { + const { getByText, getByPlaceholderText } = render( + {}} + mutateListMembers={() => {}} + pagination={mockPagination} + patients={mockPatients} + />, + ); + + // Search for a specific patient + const searchInput = getByPlaceholderText('Search this list'); + fireEvent.change(searchInput, { target: { value: 'John' } }); + + // Check if the filtered patient is displayed + const johnDoeName = getByText('John Doe'); + expect(johnDoeName).toBeInTheDocument(); + }); +});