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
feat(imaging): create basic imaging module #2250
Merged
Merged
Changes from 11 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
611bbca
feat(navbar): add feature to display currently logged in user name in…
69b2c8a
Merge branch 'master' into display-user-in-profile-dropdown
jackcmeyer bc5b903
fix(navbar): add test for rendering username and rename signed-in tra…
9e03b81
Merge branch 'display-user-in-profile-dropdown' of https://github.com…
4aac392
Merge branch 'master' of https://github.com/HospitalRun/hospitalrun-f…
a7db0eb
feat(imaging): create basic imaging module
7b7ca4c
Merge branch 'master' into imaging
matteovivona 4b49f72
feat(imaging): add imagings unit tests and removed unused component
58a2114
Merge branch 'master' of https://github.com/HospitalRun/hospitalrun-f…
c5175aa
Merge branch 'imaging' of https://github.com/AlexTan331/hospitalrun-f…
c6c18cc
fix(imaging): remove unused component
4a0d909
Merge branch 'master' into imaging
matteovivona f811cb9
feat(imaging): create setup function for the whole test suiteand repl…
6dcc1ce
Merge branch 'master' of https://github.com/HospitalRun/hospitalrun-f…
8857373
Merge branch 'imaging' of https://github.com/AlexTan331/hospitalrun-f…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,74 @@ | ||
import { mount } from 'enzyme' | ||
import React from 'react' | ||
import { Provider } from 'react-redux' | ||
import { MemoryRouter } from 'react-router-dom' | ||
import createMockStore from 'redux-mock-store' | ||
import thunk from 'redux-thunk' | ||
|
||
import Imagings from '../../imagings/Imagings' | ||
import NewImagingRequest from '../../imagings/requests/NewImagingRequest' | ||
import ImagingRepository from '../../shared/db/ImagingRepository' | ||
import PatientRepository from '../../shared/db/PatientRepository' | ||
import Imaging from '../../shared/model/Imaging' | ||
import Patient from '../../shared/model/Patient' | ||
import Permissions from '../../shared/model/Permissions' | ||
import { RootState } from '../../shared/store' | ||
|
||
const mockStore = createMockStore<RootState, any>([thunk]) | ||
|
||
describe('Imagings', () => { | ||
jest.spyOn(ImagingRepository, 'findAll').mockResolvedValue([]) | ||
jest | ||
.spyOn(ImagingRepository, 'find') | ||
.mockResolvedValue({ id: '1234', requestedOn: new Date().toISOString() } as Imaging) | ||
jest | ||
.spyOn(PatientRepository, 'find') | ||
.mockResolvedValue({ id: '12345', fullName: 'test test' } as Patient) | ||
|
||
describe('routing', () => { | ||
describe('/imagings/new', () => { | ||
it('should render the new imaging request screen when /imagings/new is accessed', () => { | ||
const store = mockStore({ | ||
title: 'test', | ||
user: { permissions: [Permissions.RequestImaging] }, | ||
breadcrumbs: { breadcrumbs: [] }, | ||
components: { sidebarCollapsed: false }, | ||
imaging: { | ||
imaging: { id: 'imagingId', patient: 'patient' } as Imaging, | ||
patient: { id: 'patientId', fullName: 'some name' }, | ||
error: {}, | ||
}, | ||
} as any) | ||
|
||
const wrapper = mount( | ||
<Provider store={store}> | ||
<MemoryRouter initialEntries={['/imagings/new']}> | ||
<Imagings /> | ||
</MemoryRouter> | ||
</Provider>, | ||
) | ||
|
||
expect(wrapper.find(NewImagingRequest)).toHaveLength(1) | ||
}) | ||
|
||
it('should not navigate to /imagings/new if the user does not have RequestLab permissions', () => { | ||
const store = mockStore({ | ||
title: 'test', | ||
user: { permissions: [] }, | ||
breadcrumbs: { breadcrumbs: [] }, | ||
components: { sidebarCollapsed: false }, | ||
} as any) | ||
|
||
const wrapper = mount( | ||
<Provider store={store}> | ||
<MemoryRouter initialEntries={['/imagings/new']}> | ||
<Imagings /> | ||
</MemoryRouter> | ||
</Provider>, | ||
) | ||
|
||
expect(wrapper.find(NewImagingRequest)).toHaveLength(0) | ||
}) | ||
}) | ||
}) | ||
}) |
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,156 @@ | ||
import { Table } from '@hospitalrun/components' | ||
import { act } from '@testing-library/react' | ||
import { mount, ReactWrapper } from 'enzyme' | ||
import { createMemoryHistory } from 'history' | ||
import React from 'react' | ||
import { Provider } from 'react-redux' | ||
import { Router } from 'react-router-dom' | ||
import createMockStore from 'redux-mock-store' | ||
import thunk from 'redux-thunk' | ||
|
||
import ViewImagings from '../../imagings/ViewImagings' | ||
import * as ButtonBarProvider from '../../page-header/button-toolbar/ButtonBarProvider' | ||
import * as titleUtil from '../../page-header/title/useTitle' | ||
import ImagingRepository from '../../shared/db/ImagingRepository' | ||
import Imaging from '../../shared/model/Imaging' | ||
import Permissions from '../../shared/model/Permissions' | ||
import { RootState } from '../../shared/store' | ||
|
||
const mockStore = createMockStore<RootState, any>([thunk]) | ||
|
||
describe('View Imagings', () => { | ||
describe('title', () => { | ||
let titleSpy: any | ||
beforeEach(async () => { | ||
const store = mockStore({ | ||
title: '', | ||
user: { permissions: [Permissions.ViewImagings, Permissions.RequestLab] }, | ||
imagings: { imagings: [] }, | ||
} as any) | ||
titleSpy = jest.spyOn(titleUtil, 'default') | ||
jest.spyOn(ImagingRepository, 'findAll').mockResolvedValue([]) | ||
await act(async () => { | ||
await mount( | ||
<Provider store={store}> | ||
<Router history={createMemoryHistory()}> | ||
<ViewImagings /> | ||
</Router> | ||
</Provider>, | ||
) | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lately, we have been putting this kind of setup in a Each describe can share the |
||
}) | ||
|
||
it('should have the title', () => { | ||
expect(titleSpy).toHaveBeenCalledWith('imagings.label') | ||
}) | ||
}) | ||
|
||
describe('button bar', () => { | ||
it('should display button to add new imaging request', async () => { | ||
const store = mockStore({ | ||
title: '', | ||
user: { permissions: [Permissions.ViewImagings, Permissions.RequestImaging] }, | ||
imagings: { imagings: [] }, | ||
} as any) | ||
const setButtonToolBarSpy = jest.fn() | ||
jest.spyOn(ButtonBarProvider, 'useButtonToolbarSetter').mockReturnValue(setButtonToolBarSpy) | ||
jest.spyOn(ImagingRepository, 'findAll').mockResolvedValue([]) | ||
await act(async () => { | ||
await mount( | ||
<Provider store={store}> | ||
<Router history={createMemoryHistory()}> | ||
<ViewImagings /> | ||
</Router> | ||
</Provider>, | ||
) | ||
}) | ||
|
||
const actualButtons: React.ReactNode[] = setButtonToolBarSpy.mock.calls[0][0] | ||
expect((actualButtons[0] as any).props.children).toEqual('imagings.requests.new') | ||
}) | ||
|
||
it('should not display button to add new imaging request if the user does not have permissions', async () => { | ||
const store = mockStore({ | ||
title: '', | ||
user: { permissions: [Permissions.ViewImagings] }, | ||
imagings: { imagings: [] }, | ||
} as any) | ||
const setButtonToolBarSpy = jest.fn() | ||
jest.spyOn(ButtonBarProvider, 'useButtonToolbarSetter').mockReturnValue(setButtonToolBarSpy) | ||
jest.spyOn(ImagingRepository, 'findAll').mockResolvedValue([]) | ||
await act(async () => { | ||
await mount( | ||
<Provider store={store}> | ||
<Router history={createMemoryHistory()}> | ||
<ViewImagings /> | ||
</Router> | ||
</Provider>, | ||
) | ||
}) | ||
|
||
const actualButtons: React.ReactNode[] = setButtonToolBarSpy.mock.calls[0][0] | ||
expect(actualButtons).toEqual([]) | ||
}) | ||
}) | ||
|
||
describe('table', () => { | ||
let wrapper: ReactWrapper | ||
let history: any | ||
const expectedImaging = { | ||
code: 'I-1234', | ||
id: '1234', | ||
type: 'imaging type', | ||
patient: 'patient', | ||
status: 'requested', | ||
requestedOn: '2020-03-30T04:43:20.102Z', | ||
requestedBy: 'some user', | ||
} as Imaging | ||
|
||
beforeEach(async () => { | ||
const store = mockStore({ | ||
title: '', | ||
user: { permissions: [Permissions.ViewImagings, Permissions.RequestImaging] }, | ||
imagings: { imagings: [expectedImaging] }, | ||
} as any) | ||
history = createMemoryHistory() | ||
|
||
jest.spyOn(ImagingRepository, 'findAll').mockResolvedValue([expectedImaging]) | ||
await act(async () => { | ||
wrapper = await mount( | ||
<Provider store={store}> | ||
<Router history={history}> | ||
<ViewImagings /> | ||
</Router> | ||
</Provider>, | ||
) | ||
}) | ||
|
||
wrapper.update() | ||
}) | ||
|
||
it('should render a table with data', () => { | ||
const table = wrapper.find(Table) | ||
const columns = table.prop('columns') | ||
expect(columns[0]).toEqual( | ||
expect.objectContaining({ label: 'imagings.imaging.code', key: 'code' }), | ||
) | ||
expect(columns[1]).toEqual( | ||
expect.objectContaining({ label: 'imagings.imaging.type', key: 'type' }), | ||
) | ||
expect(columns[2]).toEqual( | ||
expect.objectContaining({ label: 'imagings.imaging.requestedOn', key: 'requestedOn' }), | ||
) | ||
expect(columns[3]).toEqual( | ||
expect.objectContaining({ label: 'imagings.imaging.patient', key: 'patient' }), | ||
) | ||
expect(columns[4]).toEqual( | ||
expect.objectContaining({ label: 'imagings.imaging.requestedBy', key: 'requestedBy' }), | ||
) | ||
expect(columns[5]).toEqual( | ||
expect.objectContaining({ label: 'imagings.imaging.status', key: 'status' }), | ||
) | ||
|
||
expect(table.prop('data')).toEqual([expectedImaging]) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's just go with
/imaging
for the route name