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

Commit

Permalink
feat(labs): reduxify request, cancel, fetch, and update labs
Browse files Browse the repository at this point in the history
  • Loading branch information
jackcmeyer committed Apr 19, 2020
1 parent 1a4ece9 commit 7ba2e8e
Show file tree
Hide file tree
Showing 7 changed files with 460 additions and 102 deletions.
14 changes: 14 additions & 0 deletions src/__tests__/labs/Labs.test.tsx
Expand Up @@ -34,6 +34,11 @@ describe('Labs', () => {
user: { permissions: [Permissions.RequestLab] },
breadcrumbs: { breadcrumbs: [] },
components: { sidebarCollapsed: false },
lab: {
lab: { id: 'labId', patientId: 'patientId' } as Lab,
patient: { id: 'patientId', fullName: 'some name' },
error: {},
},
})

const wrapper = mount(
Expand Down Expand Up @@ -74,6 +79,15 @@ describe('Labs', () => {
user: { permissions: [Permissions.ViewLab] },
breadcrumbs: { breadcrumbs: [] },
components: { sidebarCollapsed: false },
lab: {
lab: {
id: 'labId',
patientId: 'patientId',
requestedOn: new Date().toISOString(),
} as Lab,
patient: { id: 'patientId', fullName: 'some name' },
error: {},
},
})

let wrapper: any
Expand Down
55 changes: 25 additions & 30 deletions src/__tests__/labs/ViewLab.test.tsx
Expand Up @@ -37,7 +37,7 @@ describe('View Labs', () => {
let titleSpy: any
let labRepositorySaveSpy: any
const expectedDate = new Date()
const setup = async (lab: Lab, permissions: Permissions[]) => {
const setup = async (lab: Lab, permissions: Permissions[], error = {}) => {
jest.resetAllMocks()
Date.now = jest.fn(() => expectedDate.valueOf())
setButtonToolBarSpy = jest.fn()
Expand All @@ -54,6 +54,12 @@ describe('View Labs', () => {
user: {
permissions,
},
lab: {
lab,
patient: mockPatient,
error,
status: Object.keys(error).length > 0 ? 'error' : 'success',
},
})

let wrapper: any
Expand Down Expand Up @@ -133,11 +139,11 @@ describe('View Labs', () => {
} as Lab
const wrapper = await setup(expectedLab, [Permissions.ViewLab])

const notesTextField = wrapper.find(TextFieldWithLabelFormGroup).at(0)
const resultTextField = wrapper.find(TextFieldWithLabelFormGroup).at(0)

expect(notesTextField).toBeDefined()
expect(notesTextField.prop('label')).toEqual('labs.lab.result')
expect(notesTextField.prop('value')).toEqual(expectedLab.result)
expect(resultTextField).toBeDefined()
expect(resultTextField.prop('label')).toEqual('labs.lab.result')
expect(resultTextField.prop('value')).toEqual(expectedLab.result)
})

it('should display the notes in the notes text field', async () => {
Expand All @@ -151,6 +157,20 @@ describe('View Labs', () => {
expect(notesTextField.prop('value')).toEqual(expectedLab.notes)
})

it('should display errors', async () => {
const expectedLab = { ...mockLab, status: 'requested' } as Lab
const expectedError = { message: 'some message', result: 'some result feedback' }
const wrapper = await setup(expectedLab, [Permissions.ViewLab], expectedError)

const alert = wrapper.find(Alert)
const resultTextField = wrapper.find(TextFieldWithLabelFormGroup).at(0)
expect(alert.prop('message')).toEqual(expectedError.message)
expect(alert.prop('title')).toEqual('states.error')
expect(alert.prop('color')).toEqual('danger')
expect(resultTextField.prop('isInvalid')).toBeTruthy()
expect(resultTextField.prop('feedback')).toEqual(expectedError.result)
})

describe('requested lab request', () => {
it('should display a warning badge if the status is requested', async () => {
const expectedLab = { ...mockLab, status: 'requested' } as Lab
Expand Down Expand Up @@ -343,31 +363,6 @@ describe('View Labs', () => {
)
expect(history.location.pathname).toEqual('/labs')
})

it('should validate that the result has been filled in', async () => {
const wrapper = await setup(mockLab, [
Permissions.ViewLab,
Permissions.CompleteLab,
Permissions.CancelLab,
])

const completeButton = wrapper.find(Button).at(1)
await act(async () => {
const onClick = completeButton.prop('onClick')
await onClick()
})
wrapper.update()

const alert = wrapper.find(Alert)
const resultField = wrapper.find(TextFieldWithLabelFormGroup).at(0)
expect(alert).toHaveLength(1)
expect(alert.prop('title')).toEqual('states.error')
expect(alert.prop('message')).toEqual('labs.requests.error.unableToComplete')
expect(resultField.prop('isInvalid')).toBeTruthy()
expect(resultField.prop('feedback')).toEqual('labs.requests.error.resultRequiredToComplete')

expect(labRepositorySaveSpy).not.toHaveBeenCalled()
})
})

describe('on cancel', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/labs/ViewLabs.test.tsx
Expand Up @@ -38,7 +38,7 @@ describe('View Labs', () => {
})
})

it('should have New Lab Request as the title', () => {
it('should have the title', () => {
expect(titleSpy).toHaveBeenCalledWith('labs.label')
})
})
Expand Down

0 comments on commit 7ba2e8e

Please sign in to comment.