Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
akshay-ap committed Apr 22, 2020
2 parents d55dbb7 + 4e69b79 commit 29cd413
Show file tree
Hide file tree
Showing 16 changed files with 780 additions and 212 deletions.
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
REACT_APP_HOSPITALRUN_API=http://0.0.0.0:3001
37 changes: 29 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [12.x, 13.x]
# node-version: [12.x, 14.x]
node-version: [12.x]
os: [ubuntu-latest, windows-latest, macOS-latest]
# exclude:
# - os: windows-latest
# node-version: 13.x
steps:
- run: git config --global core.autocrlf false # this is needed to prevent git changing EOL after cloning on Windows OS
- uses: actions/checkout@v2
Expand All @@ -38,16 +36,39 @@ jobs:
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: ./coverage/lcov.info

npm-node14:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [14.x]
os: [ubuntu-latest]
steps:
- run: git config --global core.autocrlf false # this is needed to prevent git changing EOL after cloning on Windows OS
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install with npm
run: |
npm install
- name: Lint code
run: |
npm run lint
- name: Build
run: |
npm run build
- name: Run tests
run: |
npm run test:ci
yarn:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [12.x, 13.x]
node-version: [12.x]
os: [ubuntu-latest, windows-latest, macOS-latest]
# exclude:
# - os: windows-latest
# node-version: 13.x
steps:
- run: git config --global core.autocrlf false # this is needed to prevent git changing EOL after cloning on Windows OS
- uses: actions/checkout@v2
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"@testing-library/react": "~10.0.0",
"@testing-library/react-hooks": "~3.2.1",
"@types/jest": "~25.2.0",
"@types/node": "~13.11.0",
"@types/node": "~13.13.0",
"@types/pouchdb": "~6.4.0",
"@types/react": "~16.9.17",
"@types/react-dom": "~16.9.4",
Expand All @@ -61,7 +61,7 @@
"@types/shortid": "^0.0.29",
"@types/uuid": "^7.0.0",
"@typescript-eslint/eslint-plugin": "~2.28.0",
"@typescript-eslint/parser": "~2.28.0",
"@typescript-eslint/parser": "~2.29.0",
"commitizen": "~4.0.3",
"commitlint-config-cz": "~0.13.0",
"cross-env": "~7.0.0",
Expand All @@ -71,7 +71,7 @@
"enzyme-adapter-react-16": "~1.15.2",
"eslint": "~6.8.0",
"eslint-config-airbnb": "~18.1.0",
"eslint-config-prettier": "~6.10.1",
"eslint-config-prettier": "~6.11.0",
"eslint-plugin-import": "~2.20.0",
"eslint-plugin-jest": "~23.8.0",
"eslint-plugin-jsx-a11y": "~6.2.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,21 @@ describe('date picker with label form group', () => {

it('should render and date time picker', () => {
const expectedName = 'test'
const expectedDate = new Date()
const wrapper = shallow(
<DatePickerWithLabelFormGroup
name={expectedName}
label="test"
value={new Date()}
isEditable
onChange={jest.fn()}
maxDate={expectedDate}
/>,
)

const input = wrapper.find(DateTimePicker)
expect(input).toHaveLength(1)
expect(input.prop('maxDate')).toEqual(expectedDate)
})

it('should render disabled is isDisable disabled is true', () => {
Expand Down
14 changes: 14 additions & 0 deletions src/__tests__/labs/Labs.test.tsx
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,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
Loading

0 comments on commit 29cd413

Please sign in to comment.