Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test ResetPasswordModal and ChangePasswordModal #457

Merged
merged 19 commits into from
Aug 11, 2020
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion frontend/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = {
node: true,
browser: true,
es6: true,
jest: true,
},
parser: 'babel-eslint',
parserOptions: {
Expand All @@ -13,7 +14,7 @@ module.exports = {
modules: true,
},
},
plugins: ['prettier', 'react'],
plugins: ['prettier', 'react', 'jest'],
extends: ['prettier', 'eslint:recommended', 'plugin:react/recommended'],
rules: {
'prettier/prettier': 'error',
Expand Down
8 changes: 8 additions & 0 deletions frontend/__mocks__/fileMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
process() {
return 'module.exports = {};'
},
getCacheKey() {
return 'fileMock'
},
}
1 change: 1 addition & 0 deletions frontend/__mocks__/styleMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {}
14 changes: 14 additions & 0 deletions frontend/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// babel.config.js
module.exports = {
presets: [
[
'@babel/preset-env',
{
targets: {
node: 'current',
},
},
],
'@babel/react',
],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`renders correctly 1`] = `
<ContextProvider
value={
Component {
"__authStateListener": [Function],
"__firstVisibleMember": null,
"__lastVisibleMember": null,
"__organizationDocumentListener": null,
"__pageOfMembersListener": null,
"__userDocumentListener": null,
"__userImageListener": null,
"context": Object {},
"data": Object {
"organization": Object {
"currentPageOfMembers": Array [],
"diagnosisText": "",
"enableExposureText": "",
"exposureAboutText": "",
"exposureDetailsLearnText": "",
"exposureDetailsText": "",
"exposureInfoText": "",
"exposureText": "",
"id": "",
"name": "",
"notifyingOthersText": "",
"recommendExposureText": "",
"verificationAdministrationDateText": "",
"verificationIdentifierAboutText": "",
"verificationIdentifierText": "",
"verificationNotSharedText": "",
"verificationReviewText": "",
"verificationSharedText": "",
"verificationStartText": "",
"welcomeText": "",
},
"user": Object {
"disabled": false,
"email": "",
"firstName": "",
"imageBlob": null,
"isAdmin": false,
"isFirstTimeUser": undefined,
"isSignedIn": false,
"lastName": "",
"organizationID": "",
"prefix": "",
},
},
"displayName": "storeProvider",
"props": Object {
"hidden": false,
"onClose": [MockFunction],
"onFailure": [MockFunction],
"onSuccess": [MockFunction],
},
"refs": Object {},
"setState": [Function],
"state": null,
"updater": Updater {
"_callbacks": Array [],
"_renderer": ReactShallowRenderer {
"_context": Object {},
"_didScheduleRenderPhaseUpdate": false,
"_dispatcher": Object {
"readContext": [Function],
"useCallback": [Function],
"useContext": [Function],
"useDebugValue": [Function],
"useDeferredValue": [Function],
"useEffect": [Function],
"useImperativeHandle": [Function],
"useLayoutEffect": [Function],
"useMemo": [Function],
"useReducer": [Function],
"useRef": [Function],
"useResponder": [Function],
"useState": [Function],
"useTransition": [Function],
},
"_element": <Component
hidden={false}
onClose={[MockFunction]}
onFailure={[MockFunction]}
onSuccess={[MockFunction]}
/>,
"_firstWorkInProgressHook": null,
"_forcedUpdate": false,
"_instance": [Circular],
"_isReRender": false,
"_newState": null,
"_numberOfReRenders": 0,
"_renderPhaseUpdates": null,
"_rendered": <Context.Provider
value={[Circular]}
>
<Component
hidden={false}
onClose={[MockFunction]}
onFailure={[MockFunction]}
onSuccess={[MockFunction]}
/>
</Context.Provider>,
"_rendering": false,
"_updater": [Circular],
"_workInProgressHook": null,
},
},
}
}
>
<Component
hidden={false}
onClose={[MockFunction]}
onFailure={[MockFunction]}
onSuccess={[MockFunction]}
/>
</ContextProvider>
`;
153 changes: 153 additions & 0 deletions frontend/client/__tests__/addmembermodal.react.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
import { JSDOM } from 'jsdom'

const dom = new JSDOM('<!doctype html><html><body></body></html>')
global.window = dom
global.document = dom.document

import React from 'react'
import Adapter from 'enzyme-adapter-react-16'
import { configure, shallow, mount } from 'enzyme'
import toJson from 'enzyme-to-json'
import { rootStore } from '../src/store/model'
import AddMemberModal from '../src/components/AddMemberModal'

configure({ adapter: new Adapter() })

jest.mock('../src/store')

test('renders correctly', () => {
var showAddMemberModal = true
const onAddMemberCancel = jest.fn()
const onAddMemberSuccess = jest.fn()
const onAddMemberFailure = jest.fn()

const wrapper = shallow(
<AddMemberModal
hidden={!showAddMemberModal}
onClose={onAddMemberCancel}
onSuccess={onAddMemberSuccess}
onFailure={onAddMemberFailure}
store={rootStore}
/>
)

expect(toJson(wrapper)).toMatchSnapshot()
})

test('clicking close button hides modal', () => {
var showAddMemberModal = true
const onAddMemberCancel = jest.fn()
const onAddMemberSuccess = jest.fn()
const onAddMemberFailure = jest.fn()

const wrapper = mount(
<AddMemberModal
hidden={!showAddMemberModal}
onClose={onAddMemberCancel}
onSuccess={onAddMemberSuccess}
onFailure={onAddMemberFailure}
store={rootStore}
/>
)

wrapper.find('.close-btn').at(0).simulate('click')

expect(onAddMemberCancel.mock.calls.length).toBe(1)

wrapper.unmount()
})

test('clicking modal background hides modal', () => {
var showAddMemberModal = true
const onAddMemberCancel = jest.fn()
const onAddMemberSuccess = jest.fn()
const onAddMemberFailure = jest.fn()

const wrapper = mount(
<AddMemberModal
hidden={!showAddMemberModal}
onClose={onAddMemberCancel}
onSuccess={onAddMemberSuccess}
onFailure={onAddMemberFailure}
store={rootStore}
/>
)

wrapper.find('.modal-background').at(0).simulate('click')

expect(onAddMemberCancel.mock.calls.length).toBe(1)

wrapper.unmount()
})

test('successfully create new user', () => {
var showAddMemberModal = true
const onAddMemberCancel = jest.fn()
const onAddMemberSuccess = jest.fn()
const onAddMemberFailure = jest.fn()

const wrapper = mount(
<AddMemberModal
hidden={!showAddMemberModal}
onClose={onAddMemberCancel}
onSuccess={onAddMemberSuccess}
onFailure={onAddMemberFailure}
store={rootStore}
/>
)

wrapper.instance().createUser = jest.fn(() => Promise.resolve())

const firstName = 'Test'
const lastName = 'Test'
const email = 'testuser@soylentgreen.com'
const role = 'Test Validator'

wrapper
.find('#firstName')
.at(0)
.simulate('change', {
target: {
name: 'firstName',
value: firstName,
},
})
wrapper
.find('#lastName')
.at(0)
.simulate('change', {
target: {
name: 'lastName',
value: lastName,
},
})
wrapper
.find('#email')
.at(0)
.simulate('change', {
target: {
name: 'email',
value: email,
},
})
wrapper
.find('#role')
.at(0)
.simulate('change', {
target: {
name: 'role',
value: role,
},
})
wrapper.find('.save-button').at(0).simulate('click')

expect(wrapper.instance().createUser).toBeCalledWith({
email: email,
firstName: firstName,
lastName: lastName,
isAdmin: false,
})

// expect(onAddMemberSuccess).toBeCalled()
wrapper.unmount()
})
26 changes: 26 additions & 0 deletions frontend/client/__tests__/footer.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react'
import { mount } from 'enzyme'
import { rootStore } from '../src/store/model'
import Footer from '../src/components/Footer'
const https = require('https')

const wrapper = mount(<Footer store={{ data: rootStore }} />)

test('privacy policy link is valid', (done) => {
// See https://jestjs.io/docs/en/asynchronous
function callback(res) {
expect(res.statusCode).toBe(200)
done()
}

https.get(wrapper.find('a').at(0).props().href, callback)
})

test('support link is valid', (done) => {
function callback(res) {
expect(res.statusCode).toBe(200)
done()
}

https.get(wrapper.find('a').at(1).props().href, callback)
})
Loading