This repository has been archived by the owner on Jan 9, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into IncidentsCSV
- Loading branch information
Showing
23 changed files
with
506 additions
and
634 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
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,32 @@ | ||
import { renderHook, act } from '@testing-library/react-hooks' | ||
|
||
import useImagingRequest from '../../../imagings/hooks/useImagingRequest' | ||
import ImagingRepository from '../../../shared/db/ImagingRepository' | ||
import Imaging from '../../../shared/model/Imaging' | ||
import waitUntilQueryIsSuccessful from '../../test-utils/wait-for-query.util' | ||
|
||
describe('useImagingRequest', () => { | ||
it('should get an imaging request by id', async () => { | ||
const expectedImagingId = 'some id' | ||
const expectedImagingRequest = { | ||
id: expectedImagingId, | ||
patient: 'some patient', | ||
visitId: 'visit id', | ||
status: 'requested', | ||
type: 'some type', | ||
} as Imaging | ||
jest.spyOn(ImagingRepository, 'find').mockResolvedValue(expectedImagingRequest) | ||
|
||
let actualData: any | ||
await act(async () => { | ||
const renderHookResult = renderHook(() => useImagingRequest(expectedImagingId)) | ||
const { result } = renderHookResult | ||
await waitUntilQueryIsSuccessful(renderHookResult) | ||
actualData = result.current.data | ||
}) | ||
|
||
expect(ImagingRepository.find).toHaveBeenCalledTimes(1) | ||
expect(ImagingRepository.find).toBeCalledWith(expectedImagingId) | ||
expect(actualData).toEqual(expectedImagingRequest) | ||
}) | ||
}) |
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,43 @@ | ||
import { act, renderHook } from '@testing-library/react-hooks' | ||
|
||
import useImagingSearch from '../../../imagings/hooks/useImagingSearch' | ||
import ImagingSearchRequest from '../../../imagings/model/ImagingSearchRequest' | ||
import ImagingRepository from '../../../shared/db/ImagingRepository' | ||
import SortRequest from '../../../shared/db/SortRequest' | ||
import Imaging from '../../../shared/model/Imaging' | ||
import waitUntilQueryIsSuccessful from '../../test-utils/wait-for-query.util' | ||
|
||
const defaultSortRequest: SortRequest = { | ||
sorts: [ | ||
{ | ||
field: 'requestedOn', | ||
direction: 'desc', | ||
}, | ||
], | ||
} | ||
|
||
describe('useImagingSearch', () => { | ||
it('it should search imaging requests', async () => { | ||
const expectedSearchRequest: ImagingSearchRequest = { | ||
status: 'completed', | ||
text: 'some search request', | ||
} | ||
const expectedImagingRequests = [{ id: 'some id' }] as Imaging[] | ||
jest.spyOn(ImagingRepository, 'search').mockResolvedValue(expectedImagingRequests) | ||
|
||
let actualData: any | ||
await act(async () => { | ||
const renderHookResult = renderHook(() => useImagingSearch(expectedSearchRequest)) | ||
const { result } = renderHookResult | ||
await waitUntilQueryIsSuccessful(renderHookResult) | ||
actualData = result.current.data | ||
}) | ||
|
||
expect(ImagingRepository.search).toHaveBeenCalledTimes(1) | ||
expect(ImagingRepository.search).toBeCalledWith({ | ||
...expectedSearchRequest, | ||
defaultSortRequest, | ||
}) | ||
expect(actualData).toEqual(expectedImagingRequests) | ||
}) | ||
}) |
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,55 @@ | ||
/* eslint-disable no-console */ | ||
|
||
import useRequestImaging from '../../../imagings/hooks/useRequestImaging' | ||
import { ImagingRequestError } from '../../../imagings/util/validate-imaging-request' | ||
import * as imagingRequestValidator from '../../../imagings/util/validate-imaging-request' | ||
import ImagingRepository from '../../../shared/db/ImagingRepository' | ||
import Imaging from '../../../shared/model/Imaging' | ||
import executeMutation from '../../test-utils/use-mutation.util' | ||
|
||
describe('useReportIncident', () => { | ||
beforeEach(() => { | ||
jest.restoreAllMocks() | ||
console.error = jest.fn() | ||
}) | ||
|
||
it('should save the imaging request with correct data', async () => { | ||
const expectedDate = new Date(Date.now()) | ||
Date.now = jest.fn().mockReturnValue(expectedDate) | ||
const givenImagingRequest = { | ||
patient: 'some patient', | ||
fullName: 'some full name', | ||
status: 'requested', | ||
type: 'some type', | ||
notes: 'some notes', | ||
visitId: 'some visit id', | ||
} as Imaging | ||
|
||
const expectedImagingRequest = { | ||
...givenImagingRequest, | ||
requestedOn: expectedDate.toISOString(), | ||
requestedBy: 'test', | ||
} as Imaging | ||
jest.spyOn(ImagingRepository, 'save').mockResolvedValue(expectedImagingRequest) | ||
|
||
await executeMutation(() => useRequestImaging(), givenImagingRequest) | ||
expect(ImagingRepository.save).toHaveBeenCalledTimes(1) | ||
expect(ImagingRepository.save).toBeCalledWith(expectedImagingRequest) | ||
}) | ||
|
||
it('should throw an error if validation fails', async () => { | ||
const expectedImagingRequestError = { | ||
patient: 'some patient error', | ||
} as ImagingRequestError | ||
|
||
jest.spyOn(imagingRequestValidator, 'default').mockReturnValue(expectedImagingRequestError) | ||
jest.spyOn(ImagingRepository, 'save').mockResolvedValue({} as Imaging) | ||
|
||
try { | ||
await executeMutation(() => useRequestImaging(), {}) | ||
} catch (e) { | ||
expect(e).toEqual(expectedImagingRequestError) | ||
expect(ImagingRepository.save).not.toHaveBeenCalled() | ||
} | ||
}) | ||
}) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.