-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(tests) O3-4156 Add tests for grouped timeline component
- Loading branch information
1 parent
d17d51d
commit cd5cec1
Showing
2 changed files
with
377 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,308 @@ | ||
export const mockGroupedResults = { | ||
timelineData: { | ||
data: { | ||
parsedTime: { | ||
yearColumns: [ | ||
{ | ||
year: '2024', | ||
size: 1, | ||
}, | ||
{ | ||
year: '2023', | ||
size: 1, | ||
}, | ||
], | ||
dayColumns: [ | ||
{ | ||
day: '31 — May', | ||
year: '2024', | ||
size: 1, | ||
}, | ||
{ | ||
day: '09 — Nov', | ||
year: '2023', | ||
size: 1, | ||
}, | ||
], | ||
timeColumns: ['01:39 AM', '11:15 PM'], | ||
sortedTimes: ['2024-05-31 01:39:03.0', '2023-11-09 23:15:03.0'], | ||
}, | ||
rowData: [ | ||
{ | ||
obs: [ | ||
{ | ||
obsDatetime: '2024-05-31 01:39:03.0', | ||
value: '261.9', | ||
interpretation: 'NORMAL' as OBSERVATION_INTERPRETATION, | ||
}, | ||
{ | ||
obsDatetime: '2023-11-09 23:15:03.0', | ||
value: '21.5', | ||
interpretation: 'NORMAL' as OBSERVATION_INTERPRETATION, | ||
}, | ||
], | ||
datatype: 'Numeric', | ||
lowAbsolute: 0, | ||
display: 'Total bilirubin', | ||
conceptUuid: '655AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', | ||
units: 'umol/L', | ||
flatName: 'Bloodwork-Chemistry-Serum chemistry panel-Total bilirubin', | ||
hasData: true, | ||
entries: [ | ||
{ | ||
obsDatetime: '2024-05-31 01:39:03.0', | ||
value: '261.9', | ||
interpretation: 'NORMAL' as OBSERVATION_INTERPRETATION, | ||
}, | ||
{ | ||
obsDatetime: '2023-11-09 23:15:03.0', | ||
value: '21.5', | ||
interpretation: 'NORMAL' as OBSERVATION_INTERPRETATION, | ||
}, | ||
], | ||
}, | ||
{ | ||
obs: [ | ||
{ | ||
obsDatetime: '2024-05-31 01:39:03.0', | ||
value: '3.8', | ||
interpretation: 'NORMAL' as OBSERVATION_INTERPRETATION, | ||
}, | ||
{ | ||
obsDatetime: '2023-11-09 23:15:03.0', | ||
value: '2.9', | ||
interpretation: 'NORMAL' as OBSERVATION_INTERPRETATION, | ||
}, | ||
], | ||
datatype: 'Numeric', | ||
lowAbsolute: 0, | ||
display: 'Serum glutamic-pyruvic transaminase', | ||
conceptUuid: '654AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', | ||
lowNormal: 0, | ||
units: 'IU/L', | ||
hiNormal: 35, | ||
flatName: 'Bloodwork-Chemistry-Serum chemistry panel-Serum glutamic-pyruvic transaminase', | ||
hasData: true, | ||
range: '0 – 35', | ||
entries: [ | ||
{ | ||
obsDatetime: '2024-05-31 01:39:03.0', | ||
value: '3.8', | ||
interpretation: 'NORMAL' as OBSERVATION_INTERPRETATION, | ||
}, | ||
{ | ||
obsDatetime: '2023-11-09 23:15:03.0', | ||
value: '2.9', | ||
interpretation: 'NORMAL' as OBSERVATION_INTERPRETATION, | ||
}, | ||
], | ||
}, | ||
{ | ||
obs: [ | ||
{ | ||
obsDatetime: '2024-05-31 01:39:03.0', | ||
value: '27.0', | ||
interpretation: 'NORMAL' as OBSERVATION_INTERPRETATION, | ||
}, | ||
{ | ||
obsDatetime: '2023-11-09 23:15:03.0', | ||
value: '27.0', | ||
interpretation: 'NORMAL' as OBSERVATION_INTERPRETATION, | ||
}, | ||
], | ||
datatype: 'Numeric', | ||
lowAbsolute: 0, | ||
display: 'Serum glutamic-oxaloacetic transaminase', | ||
conceptUuid: '653AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', | ||
lowNormal: 25, | ||
units: 'IU/L', | ||
hiNormal: 45, | ||
flatName: 'Bloodwork-Chemistry-Serum chemistry panel-Serum glutamic-oxaloacetic transaminase', | ||
hasData: true, | ||
range: '25 – 45', | ||
entries: [ | ||
{ | ||
obsDatetime: '2024-05-31 01:39:03.0', | ||
value: '27.0', | ||
interpretation: 'NORMAL' as OBSERVATION_INTERPRETATION, | ||
}, | ||
{ | ||
obsDatetime: '2023-11-09 23:15:03.0', | ||
value: '27.0', | ||
interpretation: 'NORMAL' as OBSERVATION_INTERPRETATION, | ||
}, | ||
], | ||
}, | ||
{ | ||
obs: [ | ||
{ | ||
obsDatetime: '2024-05-31 01:39:03.0', | ||
value: '19.0', | ||
interpretation: 'NORMAL' as OBSERVATION_INTERPRETATION, | ||
}, | ||
{ | ||
obsDatetime: '2023-11-09 23:15:03.0', | ||
value: '40.0', | ||
interpretation: 'NORMAL' as OBSERVATION_INTERPRETATION, | ||
}, | ||
], | ||
datatype: 'Numeric', | ||
display: 'Alkaline phosphatase', | ||
conceptUuid: '785AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', | ||
lowNormal: 0, | ||
units: 'U/L', | ||
hiNormal: 270, | ||
hiCritical: 541, | ||
flatName: 'Bloodwork-Chemistry-Serum chemistry panel-Alkaline phosphatase', | ||
hasData: true, | ||
range: '0 – 270', | ||
entries: [ | ||
{ | ||
obsDatetime: '2024-05-31 01:39:03.0', | ||
value: '19.0', | ||
interpretation: 'NORMAL' as OBSERVATION_INTERPRETATION, | ||
}, | ||
{ | ||
obsDatetime: '2023-11-09 23:15:03.0', | ||
value: '40.0', | ||
interpretation: 'NORMAL' as OBSERVATION_INTERPRETATION, | ||
}, | ||
], | ||
}, | ||
{ | ||
obs: [ | ||
{ | ||
obsDatetime: '2024-05-31 01:39:03.0', | ||
value: '240.0', | ||
interpretation: 'NORMAL' as OBSERVATION_INTERPRETATION, | ||
}, | ||
{ | ||
obsDatetime: '2023-11-09 23:15:03.0', | ||
value: '23.0', | ||
interpretation: 'NORMAL' as OBSERVATION_INTERPRETATION, | ||
}, | ||
], | ||
datatype: 'Numeric', | ||
lowAbsolute: 0, | ||
display: 'Total protein', | ||
conceptUuid: '717AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', | ||
units: 'g/dL', | ||
flatName: 'Bloodwork-Chemistry-Serum chemistry panel-Total protein', | ||
hasData: true, | ||
entries: [ | ||
{ | ||
obsDatetime: '2024-05-31 01:39:03.0', | ||
value: '240.0', | ||
interpretation: 'NORMAL' as OBSERVATION_INTERPRETATION, | ||
}, | ||
{ | ||
obsDatetime: '2023-11-09 23:15:03.0', | ||
value: '23.0', | ||
interpretation: 'NORMAL' as OBSERVATION_INTERPRETATION, | ||
}, | ||
], | ||
}, | ||
], | ||
panelName: 'timeline', | ||
}, | ||
loaded: true, | ||
}, | ||
parents: { | ||
'Hematology-Complete blood count': [], | ||
'Hematology-Prothrombin Time (with INR)': [], | ||
'Hematology-Sickling test only': [], | ||
'Hematology-Lipid panel': [], | ||
Hematology: [], | ||
'Bloodwork-Hematology-Complete blood count': [], | ||
'Bloodwork-Hematology-Prothrombin Time (with INR)': [], | ||
'Bloodwork-Hematology-Sickling test only': [], | ||
'Bloodwork-Hematology-Lipid panel': [], | ||
'Bloodwork-Hematology': [], | ||
'Bloodwork-Chemistry-Serum chemistry panel': [ | ||
'Bloodwork-Chemistry-Serum chemistry panel-Total bilirubin', | ||
'Bloodwork-Chemistry-Serum chemistry panel-Serum glutamic-pyruvic transaminase', | ||
'Bloodwork-Chemistry-Serum chemistry panel-Serum glutamic-oxaloacetic transaminase', | ||
'Bloodwork-Chemistry-Serum chemistry panel-Alkaline phosphatase', | ||
'Bloodwork-Chemistry-Serum chemistry panel-Total protein', | ||
], | ||
'Bloodwork-Chemistry-Comprehensive metabolic panel': [], | ||
'Bloodwork-Chemistry-Renal function panel': [], | ||
'Bloodwork-Chemistry-Basic metabolic panel': [], | ||
'Bloodwork-Chemistry': [ | ||
'Bloodwork-Chemistry-Serum chemistry panel-Total bilirubin', | ||
'Bloodwork-Chemistry-Serum chemistry panel-Serum glutamic-pyruvic transaminase', | ||
'Bloodwork-Chemistry-Serum chemistry panel-Serum glutamic-oxaloacetic transaminase', | ||
'Bloodwork-Chemistry-Serum chemistry panel-Alkaline phosphatase', | ||
'Bloodwork-Chemistry-Serum chemistry panel-Total protein', | ||
], | ||
Bloodwork: [ | ||
'Bloodwork-Chemistry-Serum chemistry panel-Total bilirubin', | ||
'Bloodwork-Chemistry-Serum chemistry panel-Serum glutamic-pyruvic transaminase', | ||
'Bloodwork-Chemistry-Serum chemistry panel-Serum glutamic-oxaloacetic transaminase', | ||
'Bloodwork-Chemistry-Serum chemistry panel-Alkaline phosphatase', | ||
'Bloodwork-Chemistry-Serum chemistry panel-Total protein', | ||
], | ||
'HIV viral load': [], | ||
}, | ||
activeTests: [], | ||
lowestParents: [ | ||
{ | ||
flatName: 'Hematology-Complete blood count', | ||
display: 'Complete blood count', | ||
}, | ||
{ | ||
flatName: 'Hematology-Prothrombin Time (with INR)', | ||
display: 'Prothrombin Time (with INR)', | ||
}, | ||
{ | ||
flatName: 'Hematology-Sickling test only', | ||
display: 'Sickling test only', | ||
}, | ||
{ | ||
flatName: 'Hematology-Lipid panel', | ||
display: 'Lipid panel', | ||
}, | ||
{ | ||
flatName: 'Bloodwork-Hematology-Complete blood count', | ||
display: 'Complete blood count', | ||
}, | ||
{ | ||
flatName: 'Bloodwork-Hematology-Prothrombin Time (with INR)', | ||
display: 'Prothrombin Time (with INR)', | ||
}, | ||
{ | ||
flatName: 'Bloodwork-Hematology-Sickling test only', | ||
display: 'Sickling test only', | ||
}, | ||
{ | ||
flatName: 'Bloodwork-Hematology-Lipid panel', | ||
display: 'Lipid panel', | ||
}, | ||
{ | ||
flatName: 'Bloodwork-Chemistry-Serum chemistry panel', | ||
display: 'Serum chemistry panel', | ||
}, | ||
{ | ||
flatName: 'Bloodwork-Chemistry-Renal function panel', | ||
display: 'Renal function panel', | ||
}, | ||
{ | ||
flatName: 'Bloodwork-Chemistry-Basic metabolic panel', | ||
display: 'Basic metabolic panel', | ||
}, | ||
{ | ||
flatName: 'HIV viral load', | ||
display: 'HIV viral load', | ||
}, | ||
], | ||
}; | ||
|
||
export type OBSERVATION_INTERPRETATION = | ||
| 'NORMAL' | ||
| 'HIGH' | ||
| 'CRITICALLY_HIGH' | ||
| 'OFF_SCALE_HIGH' | ||
| 'LOW' | ||
| 'CRITICALLY_LOW' | ||
| 'OFF_SCALE_LOW' | ||
| '--'; |
69 changes: 69 additions & 0 deletions
69
packages/esm-patient-tests-app/src/test-results/grouped-timeline/grouped-timeline.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,69 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import React from 'react'; | ||
import GroupedTimeline from './grouped-timeline.component'; | ||
import { mockGroupedResults } from '../../../../../__mocks__/grouped-results.mock'; | ||
import FilterContext from '../filter/filter-context'; | ||
import { type FilterContextProps } from '../filter/filter-types'; | ||
|
||
jest.mock('react-i18next', () => ({ | ||
useTranslation: () => ({ t: (key: string) => key }), | ||
})); | ||
|
||
describe('GroupedTimeline', () => { | ||
const mockFilterContext: FilterContextProps = { | ||
activeTests: ['Bloodwork-Chemistry', 'Bloodwork'], | ||
timelineData: mockGroupedResults.timelineData, | ||
parents: mockGroupedResults.parents, | ||
checkboxes: { Chemistry: true, Bloodwork: false }, | ||
someChecked: false, | ||
lowestParents: mockGroupedResults['lowestParents'], | ||
totalResultsCount: 0, | ||
initialize: jest.fn(), | ||
toggleVal: jest.fn(), | ||
updateParent: jest.fn(), | ||
resetTree: jest.fn(), | ||
roots: [], | ||
tests: {}, | ||
}; | ||
|
||
const renderComponent = (contextValue = mockFilterContext) => | ||
render( | ||
<FilterContext.Provider value={contextValue}> | ||
<GroupedTimeline patientUuid="some-test-uuid" /> | ||
</FilterContext.Provider>, | ||
); | ||
|
||
it('renders EmptyState when rowData is empty', () => { | ||
renderComponent({ | ||
...mockFilterContext, | ||
timelineData: { | ||
...mockFilterContext.timelineData, | ||
data: { ...mockFilterContext.timelineData.data, rowData: [] }, | ||
}, | ||
}); | ||
|
||
expect(screen.getByText('dataTimelineText')).toBeInTheDocument(); | ||
expect(screen.getByText('emptyStateText')).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders timeline header and data when activeTests, timelineData, and loaded are present', () => { | ||
renderComponent(); | ||
|
||
expect(screen.getByText('2024')).toBeInTheDocument(); | ||
expect(screen.getByText('2023')).toBeInTheDocument(); | ||
|
||
expect(screen.getByText('31 — May')).toBeInTheDocument(); | ||
expect(screen.getByText('09 — Nov')).toBeInTheDocument(); | ||
|
||
expect(screen.getByText('01:39 AM')).toBeInTheDocument(); | ||
expect(screen.getByText('Serum chemistry panel')).toBeInTheDocument(); | ||
expect(screen.getByText('Total bilirubin')).toBeInTheDocument(); | ||
expect(screen.getByText('umol/L')).toBeInTheDocument(); | ||
expect(screen.getByText('261.9')).toBeInTheDocument(); | ||
expect(screen.getByText('21.5')).toBeInTheDocument(); | ||
expect(screen.getByText('Serum glutamic-pyruvic transaminase')).toBeInTheDocument(); | ||
expect(screen.getByText('0 – 35 IU/L')).toBeInTheDocument(); | ||
expect(screen.getByText('3.8')).toBeInTheDocument(); | ||
expect(screen.getByText('2.9')).toBeInTheDocument(); | ||
}); | ||
}); |