-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OHRI-2084: Add unit tests for patient table in commons lib (#1770)
* Add unit tests for patient table in commons lib * Add unit tests for patient table in commons lib * more test added * Update patient-table.test.tsx
- Loading branch information
1 parent
4e02002
commit 1567f26
Showing
1 changed file
with
99 additions
and
0 deletions.
There are no files selected for viewing
99 changes: 99 additions & 0 deletions
99
packages/esm-commons-lib/src/components/patient-table/patient-table.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,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( | ||
<PatientTable | ||
columns={mockColumns} | ||
isFetching={false} | ||
isLoading={false} | ||
mutateListDetails={() => {}} | ||
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( | ||
<PatientTable | ||
columns={mockColumns} | ||
isFetching={false} | ||
isLoading={true} | ||
mutateListDetails={() => {}} | ||
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( | ||
<PatientTable | ||
columns={mockColumns} | ||
isFetching={false} | ||
isLoading={false} | ||
mutateListDetails={() => {}} | ||
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( | ||
<PatientTable | ||
columns={mockColumns} | ||
isFetching={false} | ||
isLoading={false} | ||
mutateListDetails={() => {}} | ||
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(); | ||
}); | ||
}); |