Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
Merge branch 'important-patient-info' of https://github.com/AlexTan33…
Browse files Browse the repository at this point in the history
…1/hospitalrun-frontend into important-patient-info
  • Loading branch information
Alex Tan authored and Alex Tan committed Sep 28, 2020
2 parents 4b234a1 + 67aab7c commit 315c544
Show file tree
Hide file tree
Showing 44 changed files with 996 additions and 1,211 deletions.
96 changes: 96 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hospitalrun/frontend",
"version": "2.0.0-alpha.4",
"version": "2.0.0-alpha.5",
"description": "React frontend for HospitalRun",
"private": false,
"license": "MIT",
Expand Down Expand Up @@ -91,7 +91,7 @@
"enzyme-adapter-react-16": "~1.15.2",
"eslint": "~6.8.0",
"eslint-config-airbnb": "~18.2.0",
"eslint-config-prettier": "~6.11.0",
"eslint-config-prettier": "~6.12.0",
"eslint-import-resolver-typescript": "~2.3.0",
"eslint-plugin-import": "~2.22.0",
"eslint-plugin-jest": "~24.0.0",
Expand Down
51 changes: 22 additions & 29 deletions src/__tests__/labs/Labs.test.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { act } from '@testing-library/react'
import { mount, ReactWrapper } from 'enzyme'
import React from 'react'
import { Provider } from 'react-redux'
Expand Down Expand Up @@ -28,62 +29,54 @@ describe('Labs', () => {
jest
.spyOn(PatientRepository, 'find')
.mockResolvedValue({ id: '12345', fullName: 'test test' } as Patient)
const setup = (route: string, permissions: Permissions[] = []) => {

const setup = async (initialEntry: string, permissions: Permissions[] = []) => {
const store = mockStore({
user: { permissions },
breadcrumbs: { breadcrumbs: [] },
components: { sidebarCollapsed: false },
lab: {
lab: ({
id: '1234',
patientId: 'patientId',
requestedOn: new Date().toISOString(),
} as unknown) as Lab,
patient: { id: 'patientId', fullName: 'some name' },
error: {},
},
} as any)

const wrapper = mount(
<Provider store={store}>
<MemoryRouter initialEntries={[route]}>
<TitleProvider>
<Labs />
</TitleProvider>
</MemoryRouter>
</Provider>,
)
let wrapper: any
await act(async () => {
wrapper = await mount(
<Provider store={store}>
<MemoryRouter initialEntries={[initialEntry]}>
<TitleProvider>
<Labs />
</TitleProvider>
</MemoryRouter>
</Provider>,
)
})

wrapper.update()
return { wrapper: wrapper as ReactWrapper }
}

describe('routing', () => {
describe('/labs/new', () => {
it('should render the new lab request screen when /labs/new is accessed', () => {
const permissions: Permissions[] = [Permissions.RequestLab]
const { wrapper } = setup('/labs/new', permissions)
it('should render the new lab request screen when /labs/new is accessed', async () => {
const { wrapper } = await setup('/labs/new', [Permissions.RequestLab])

expect(wrapper.find(NewLabRequest)).toHaveLength(1)
})

it('should not navigate to /labs/new if the user does not have RequestLab permissions', () => {
const { wrapper } = setup('/labs/new')
it('should not navigate to /labs/new if the user does not have RequestLab permissions', async () => {
const { wrapper } = await setup('/labs/new')

expect(wrapper.find(NewLabRequest)).toHaveLength(0)
})
})

describe('/labs/:id', () => {
it('should render the view lab screen when /labs/:id is accessed', async () => {
const permissions: Permissions[] = [Permissions.ViewLab]
const { wrapper } = setup('/labs/1234', permissions)
const { wrapper } = await setup('/labs/1234', [Permissions.ViewLab])

expect(wrapper.find(ViewLab)).toHaveLength(1)
})
})

it('should not navigate to /labs/:id if the user does not have ViewLab permissions', async () => {
const { wrapper } = setup('/labs/1234')
const { wrapper } = await setup('/labs/1234')

expect(wrapper.find(ViewLab)).toHaveLength(0)
})
Expand Down
Loading

0 comments on commit 315c544

Please sign in to comment.