-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dd48d9f
commit 4d72748
Showing
2 changed files
with
92 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,77 @@ | ||
import { mount } from 'enzyme'; | ||
import React from 'react'; | ||
import renderer from 'react-test-renderer'; | ||
import { checkProps } from '../../setupTest'; | ||
import EntitlementForm from './EntitlementForm'; | ||
import { DefaultProps } from './PropTypes'; | ||
|
||
describe('Entitlement Form', () => { | ||
let props; | ||
let wrapper; | ||
|
||
beforeEach(() => { | ||
props = { | ||
entitlement: EntitlementDefaultProps, | ||
changeHandler: jest.fn(), | ||
closeHandler: jest.fn(), | ||
forwardedRef: null, | ||
}; | ||
wrapper = mount(<EntitlementForm {...props} />); | ||
}); | ||
|
||
describe('Checking PropTypes', () => { | ||
it('does not throw a warning', () => { | ||
const propsError = checkProps(EntitlementForm, props); | ||
|
||
expect(propsError).toBeUndefined(); | ||
}); | ||
it('does not throw error with undefined userIdentifier', () => { | ||
delete props.userIdentifier; | ||
const propsError = checkProps(UserSearch, props); | ||
|
||
expect(propsError).toBeUndefined(); | ||
}); | ||
it('throw error with undefined search handler', () => { | ||
const propsError = checkProps(UserSearch, {}); | ||
|
||
expect(propsError).not.toBeUndefined(); | ||
expect(propsError).toContain('Failed props type'); | ||
expect(propsError).toContain('searchHandler'); | ||
}); | ||
}); | ||
|
||
describe('renders correctly', () => { | ||
it('with correct user identifier', () => { | ||
expect(wrapper.find('input').prop('defaultValue')).toEqual( | ||
props.userIdentifier, | ||
); | ||
}); | ||
it('with correct default user identifier', () => { | ||
delete props.userIdentifier; | ||
const userSearchwrapper = mount(<UserSearch {...props} />); | ||
|
||
expect(userSearchwrapper.find('input').prop('defaultValue')).toEqual(''); | ||
}); | ||
it('with submit button', () => { | ||
expect(wrapper.find('button')).toHaveLength(1); | ||
expect(wrapper.find('button').text()).toEqual('Search'); | ||
}); | ||
|
||
it('when submit button is clicked', () => { | ||
const searchProps = { userIdentifier: 'staff', searchHandler: jest.fn() }; | ||
const userSearchwrapper = mount(<UserSearch {...searchProps} />); | ||
|
||
userSearchwrapper.find('button').simulate('click'); | ||
|
||
expect(searchProps.searchHandler).toHaveBeenCalledWith( | ||
searchProps.userIdentifier, | ||
); | ||
}); | ||
|
||
it('matches snapshot', () => { | ||
const tree = renderer.create(wrapper).toJSON(); | ||
|
||
expect(tree).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); |
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