-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add. pre commit hook and update tests (#157)
- Loading branch information
Showing
4 changed files
with
144 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/sh | ||
|
||
yarn lint | ||
|
||
yarn test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: Workflow to validate PRs | ||
|
||
on: | ||
pull_request: | ||
branches: [master] | ||
|
||
jobs: | ||
build-release: | ||
name: Build the web app and make a zip release | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout to repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup Node.js 16.x | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: "16.x" | ||
|
||
- name: Install dependencies | ||
run: yarn install | ||
|
||
- name: Run tests | ||
run: yarn test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,66 @@ | ||
import React from 'react'; | ||
import { shallow, render as mount } from 'enzyme'; | ||
import { shallow } from 'enzyme'; | ||
import EditPerson from './EditPerson'; | ||
import Input from '../components/common/Input'; | ||
import SelectFromList from '../components/common/Dropdown'; | ||
|
||
jest.mock('../api/personApi', () => { | ||
return { | ||
fetchPerson: jest.fn(() => { | ||
return Promise.resolve({ | ||
status: 200, | ||
json: jest.fn(() => | ||
Promise.resolve({ | ||
display: 'John Doe', | ||
uuid: '819ba69e-6c13-4803-8a14-d7abfac66e99', | ||
gender: 'M', | ||
birthdate: '1990-01-01', | ||
birthdateEstimated: false, | ||
attributes: [ | ||
{ | ||
display: 'occupation = Teacher' | ||
} | ||
] | ||
}) | ||
) | ||
}); | ||
}), | ||
fetchPersonAttributeConfig: jest.fn(() => | ||
Promise.resolve({ | ||
status: 200, | ||
json: jest.fn(() => | ||
Promise.resolve({ | ||
config: { | ||
personAttributesForRelations: [ | ||
{ | ||
name: 'occupation', | ||
attributeName: 'occupationNew', | ||
text: 'Occupation' | ||
} | ||
] | ||
} | ||
}) | ||
) | ||
}) | ||
), | ||
getPersonAttributeTypeUuid: jest.fn(() => | ||
Promise.resolve({ | ||
status: 200, | ||
json: jest.fn(() => | ||
Promise.resolve({ | ||
results: [ | ||
{ | ||
uuid: '8d871d18-c2cc-11de-8d13-0010c6dffd0f', | ||
display: 'Occupation' | ||
} | ||
] | ||
}) | ||
) | ||
}) | ||
) | ||
}; | ||
}); | ||
|
||
describe('EditPerson', () => { | ||
let wrapper; | ||
|
||
|
@@ -16,7 +73,7 @@ describe('EditPerson', () => { | |
}); | ||
|
||
it('renders fourteen <Input /> components', () => { | ||
expect(wrapper.find(Input).length).toEqual(14); | ||
expect(wrapper.find(Input).length).toEqual(7); | ||
}); | ||
|
||
it('renders one <SelectFromList /> component', () => { | ||
|
@@ -39,23 +96,28 @@ describe('EditPerson', () => { | |
expect(wrapper.find('#lastName').prop('disabled')).toBe(true); | ||
}); | ||
|
||
it('renders email input', () => { | ||
expect(wrapper.find('#email').length).toEqual(1); | ||
it('renders occupation input', () => { | ||
setTimeout(() => { | ||
wrapper.update(); | ||
expect(wrapper.find('#occupation').length).toEqual(1); | ||
done(); | ||
}, 1000); | ||
}); | ||
|
||
describe('the user populates email input', () => { | ||
const exampleEmail = '[email protected]'; | ||
const exampleOccupation = 'Teacher'; | ||
let firstNameInput; | ||
|
||
beforeEach(() => { | ||
firstNameInput = wrapper.find('#email'); | ||
firstNameInput.simulate('change', { | ||
target: { value: exampleEmail, name: 'email' } | ||
}); | ||
}); | ||
|
||
it('should update the state property email', () => { | ||
expect(wrapper.state().person.email).toEqual(exampleEmail); | ||
setTimeout(() => { | ||
wrapper.update(); | ||
firstNameInput = wrapper.find('#occupation'); | ||
firstNameInput.simulate('change', { | ||
target: { value: exampleOccupation, name: 'occupation' } | ||
}); | ||
expect(wrapper.state().attributes[0].value).toEqual(exampleOccupation); | ||
done(); | ||
}, 1000); | ||
}); | ||
}); | ||
}); // end of outer describe | ||
}); |