Skip to content

Commit

Permalink
add. pre commit hook and update tests (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arjun-Go authored Jan 18, 2024
1 parent 8622f39 commit 6af5cf0
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .git-hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

yarn lint

yarn test
24 changes: 24 additions & 0 deletions .github/workflows/validate_PR.yaml
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
40 changes: 39 additions & 1 deletion src/containers/CreatePerson.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,44 @@ import Input from '../components/common/Input';
import SelectFromList from '../components/common/Dropdown';
import moment from 'moment';

jest.mock('../api/personApi', () => {
return {
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('CreatePerson', () => {
let wrapper;

Expand All @@ -13,7 +51,7 @@ describe('CreatePerson', () => {
});

it('renders fourteen <Input /> components', () => {
expect(wrapper.find(Input).length).toEqual(14);
expect(wrapper.find(Input).length).toEqual(7);
});

it('renders one <SelectFromList /> component', () => {
Expand Down
90 changes: 76 additions & 14 deletions src/containers/EditPerson.test.js
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;

Expand All @@ -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', () => {
Expand All @@ -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 = 'Max@gmail.com';
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
});

0 comments on commit 6af5cf0

Please sign in to comment.