-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(feat) Support offline in forms dashboard (#1437)
- Loading branch information
1 parent
1b819bc
commit 881258a
Showing
11 changed files
with
189 additions
and
69 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
18 changes: 18 additions & 0 deletions
18
packages/esm-patient-chart-app/src/visit/hooks/useOfflineVisitType.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,18 @@ | ||
import { VisitType, useConfig } from '@openmrs/esm-framework'; | ||
import { ChartConfig } from '../../config-schema'; | ||
import { useEffect, useState } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
export const useOfflineVisitType = () => { | ||
const config = useConfig() as ChartConfig; | ||
const { t } = useTranslation(); | ||
const [visitTypes, setVisitTypes] = useState<Array<VisitType>>([]); | ||
|
||
useEffect(() => { | ||
setVisitTypes([ | ||
{ uuid: config.offlineVisitTypeUuid, name: 'Offline Visit', display: t('offlineVisit', 'Offline Visit') }, | ||
]); | ||
}, []); | ||
|
||
return visitTypes; | ||
}; |
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
15 changes: 15 additions & 0 deletions
15
packages/esm-patient-forms-app/src/forms/forms-dashboard.scss
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
57 changes: 57 additions & 0 deletions
57
packages/esm-patient-forms-app/src/forms/forms-dashboard.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,57 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { useConfig } from '@openmrs/esm-framework'; | ||
import { useVisitOrOfflineVisit } from '@openmrs/esm-patient-common-lib'; | ||
import { mockCurrentVisit } from '../__mocks__/visits.mock'; | ||
import FormsDashboard from './forms-dashboard.component'; | ||
import { useForms } from '../hooks/use-forms'; | ||
|
||
const mockUseConfig = useConfig as jest.Mock; | ||
const mockUseVisitOrOfflineVisit = useVisitOrOfflineVisit as jest.Mock; | ||
|
||
jest.mock('../hooks/use-forms', () => ({ | ||
useForms: jest.fn().mockReturnValueOnce({ | ||
data: [], | ||
error: null, | ||
isValidating: false, | ||
allForms: [], | ||
}), | ||
})); | ||
|
||
jest.mock('@openmrs/esm-framework', () => { | ||
const originalModule = jest.requireActual('@openmrs/esm-framework'); | ||
|
||
return { | ||
...originalModule, | ||
useConfig: jest.fn(), | ||
}; | ||
}); | ||
|
||
jest.mock('@openmrs/esm-patient-common-lib', () => { | ||
const originalModule = jest.requireActual('@openmrs/esm-patient-common-lib'); | ||
|
||
return { | ||
...originalModule, | ||
launchPatientWorkspace: jest.fn(), | ||
useVisitOrOfflineVisit: jest.fn(), | ||
}; | ||
}); | ||
|
||
describe('FormsDashboard', () => { | ||
test('renders an empty state if there are no forms persisted on the server', async () => { | ||
mockUseConfig.mockReturnValue({ htmlFormEntryForms: [] }); | ||
|
||
mockUseVisitOrOfflineVisit.mockReturnValue({ | ||
currentVisit: mockCurrentVisit, | ||
error: null, | ||
}); | ||
|
||
renderFormDashboard(); | ||
|
||
expect(screen.getByText(/there are no forms to display/i)).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
function renderFormDashboard() { | ||
render(<FormsDashboard />); | ||
} |
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.