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
/
Imagings.test.tsx
74 lines (65 loc) · 2.53 KB
/
Imagings.test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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('/imaging/new', () => {
it('should render the new imaging request screen when /imaging/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={['/imaging/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)
})
})
})
})