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
/
HospitalRun.test.tsx
89 lines (80 loc) · 2.71 KB
/
HospitalRun.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import '../__mocks__/matchMediaMock'
import React from 'react'
import { mount } from 'enzyme'
import { MemoryRouter } from 'react-router-dom'
import { Provider } from 'react-redux'
import thunk from 'redux-thunk'
import configureMockStore from 'redux-mock-store'
import { Toaster } from '@hospitalrun/components'
import { act } from 'react-dom/test-utils'
import Dashboard from 'dashboard/Dashboard'
import ViewLabs from 'labs/ViewLabs'
import LabRepository from 'clients/db/LabRepository'
import HospitalRun from '../HospitalRun'
import Permissions from '../model/Permissions'
const mockStore = configureMockStore([thunk])
describe('HospitalRun', () => {
describe('routing', () => {
describe('/labs', () => {
it('should render the Labs component when /labs is accessed', async () => {
jest.spyOn(LabRepository, 'findAll').mockResolvedValue([])
const store = mockStore({
title: 'test',
user: { permissions: [Permissions.ViewLabs] },
labs: { labs: [] },
breadcrumbs: { breadcrumbs: [] },
components: { sidebarCollapsed: false },
})
let wrapper: any
await act(async () => {
wrapper = await mount(
<Provider store={store}>
<MemoryRouter initialEntries={['/labs']}>
<HospitalRun />
</MemoryRouter>
</Provider>,
)
})
wrapper.update()
expect(wrapper.find(ViewLabs)).toHaveLength(1)
})
it('should render the dashboard if the user does not have permissions to view labs', () => {
jest.spyOn(LabRepository, 'findAll').mockResolvedValue([])
const store = mockStore({
title: 'test',
user: { permissions: [] },
breadcrumbs: { breadcrumbs: [] },
components: { sidebarCollapsed: false },
})
const wrapper = mount(
<Provider store={store}>
<MemoryRouter initialEntries={['/labs']}>
<HospitalRun />
</MemoryRouter>
</Provider>,
)
expect(wrapper.find(ViewLabs)).toHaveLength(0)
expect(wrapper.find(Dashboard)).toHaveLength(1)
})
})
})
describe('layout', () => {
it('should render a Toaster', () => {
const wrapper = mount(
<Provider
store={mockStore({
title: 'test',
user: { permissions: [Permissions.WritePatients] },
breadcrumbs: { breadcrumbs: [] },
components: { sidebarCollapsed: false },
})}
>
<MemoryRouter initialEntries={['/']}>
<HospitalRun />
</MemoryRouter>
</Provider>,
)
expect(wrapper.find(Toaster)).toHaveLength(1)
})
})
})