-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[spec] improves existing specs and adds new ones
- Loading branch information
1 parent
861be24
commit 10d4ac9
Showing
11 changed files
with
241 additions
and
103 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
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
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
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,31 +1,70 @@ | ||
// @flow | ||
|
||
import React from 'react' | ||
import Enzyme, {shallow} from 'enzyme' | ||
import { act } from 'react-dom/test-utils' | ||
import Enzyme, {mount, shallow} from 'enzyme' | ||
import Adapter from 'enzyme-adapter-react-16' | ||
|
||
import {ServiceSourceForm} from 'NewService' | ||
|
||
Enzyme.configure({adapter: new Adapter()}) | ||
|
||
const serviceDiscoveryAuthenticateUrl = 'my-url' | ||
const props = { | ||
isServiceDiscoveryUsable: true, | ||
serviceDiscoveryAuthenticateUrl: 'my-url', | ||
handleFormsVisibility: jest.fn() | ||
serviceDiscoveryAuthenticateUrl, | ||
handleFormsVisibility: () => {}, | ||
loadingProjects: false | ||
} | ||
|
||
it('should render itself', () => { | ||
const wrapper = shallow(<ServiceSourceForm {...props}/>) | ||
expect(wrapper.find('#new_service_source').exists()).toEqual(true) | ||
const wrapper = mount(<ServiceSourceForm {...props} />) | ||
expect(wrapper.find(ServiceSourceForm).exists()).toEqual(true) | ||
}) | ||
|
||
it('should render all possible sources for the new service', () => { | ||
const wrapper = shallow(<ServiceSourceForm {...props} />) | ||
|
||
const manual = wrapper.find('[htmlFor="source_manual"]') | ||
expect(manual.exists()).toBe(true) | ||
expect(manual.find('input').prop('type')).toBe('radio') | ||
expect(manual.text()).toBe('Define manually') | ||
|
||
const discovery = wrapper.find('[htmlFor="source_discover"]') | ||
expect(discovery.exists()).toBe(true) | ||
expect(discovery.find('input').prop('type')).toBe('radio') | ||
expect(discovery.text()).toBe('Import from OpenShift') | ||
}) | ||
|
||
it('should call `handleFormsVisibility`', () => { | ||
const wrapper = shallow(<ServiceSourceForm {...props}/>) | ||
it('should call `handleFormsVisibility` when changing the source', () => { | ||
const wrapper = shallow(<ServiceSourceForm {...props} />) | ||
const handleFormsVisibility = jest.fn() | ||
wrapper.setProps({ handleFormsVisibility }) | ||
|
||
wrapper.find('#source_discover').simulate('change') | ||
expect(props.handleFormsVisibility).toHaveBeenCalled() | ||
expect(handleFormsVisibility).toHaveBeenCalled() | ||
}) | ||
|
||
it('should render `Import from OpenShift` input disabled when Service Discovery is not usable', () => { | ||
const propsNotUsable = {...props, isServiceDiscoveryUsable: false} | ||
const wrapper = shallow(<ServiceSourceForm {...propsNotUsable}/>) | ||
expect(wrapper.find('#source_discover + span').text()).toEqual('Import from OpenShift') | ||
expect(wrapper.find('#source_discover').props().disabled).toEqual(true) | ||
it('should render a spinner when loading projects', () => { | ||
const wrapper = shallow(<ServiceSourceForm {...props} />) | ||
|
||
wrapper.setProps({ loadingProjects: true }) | ||
expect(wrapper.find('.fa-spinner').exists()).toBe(true) | ||
|
||
wrapper.setProps({ loadingProjects: false }) | ||
expect(wrapper.find('.fa-spinner').exists()).toBe(false) | ||
}) | ||
|
||
it('should render a link to authenticate when Service Discovery is not usable', () => { | ||
const wrapper = shallow(<ServiceSourceForm {...props} />) | ||
|
||
act(() => { | ||
wrapper.setProps({ isServiceDiscoveryUsable: false }) | ||
}) | ||
expect(wrapper.find(`a[href="${serviceDiscoveryAuthenticateUrl}"]`).exists()).toBe(true) | ||
|
||
act(() => { | ||
wrapper.setProps({ isServiceDiscoveryUsable: true }) | ||
}) | ||
expect(wrapper.find(`a[href="${serviceDiscoveryAuthenticateUrl}"]`).exists()).toBe(false) | ||
}) |
37 changes: 25 additions & 12 deletions
37
spec/javascripts/NewService/formElements/FormWrapper.spec.jsx
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,38 +1,51 @@ | ||
// @flow | ||
|
||
import React from 'react' | ||
import Enzyme, {mount} from 'enzyme' | ||
import Enzyme, {shallow} from 'enzyme' | ||
import Adapter from 'enzyme-adapter-react-16' | ||
|
||
import {FormWrapper} from 'NewService/components/FormElements' | ||
import {HiddenServiceDiscoveryInput} from 'NewService/components/FormElements' | ||
import {CSRFToken} from 'utilities/utils' | ||
|
||
Enzyme.configure({adapter: new Adapter()}) | ||
|
||
const submitText = 'Add API' | ||
const props = { | ||
id: 'form-id', | ||
formActionPath: 'my-path', | ||
hasHiddenServiceDiscoveryInput: true, | ||
submitText: 'Add API' | ||
submitText | ||
} | ||
|
||
it('should render itself', () => { | ||
const wrapper = mount(<FormWrapper {...props}/>) | ||
const wrapper = shallow(<FormWrapper {...props}/>) | ||
expect(wrapper.find('#form-id').exists()).toEqual(true) | ||
}) | ||
|
||
it('should render an empty input', () => { | ||
const wrapper = shallow(<FormWrapper {...props}/>) | ||
const input = wrapper.find(`input[name="utf8"][type='hidden']`) | ||
expect(input.exists()).toBe(true) | ||
}) | ||
|
||
it('should render submit button with proper text', () => { | ||
const wrapper = mount(<FormWrapper {...props}/>) | ||
expect(wrapper.find(`input[type='submit']`).props().value).toEqual('Add API') | ||
expect(wrapper.find(HiddenServiceDiscoveryInput).exists()).toEqual(true) | ||
expect(wrapper.find(CSRFToken).exists()).toEqual(true) | ||
const wrapper = shallow(<FormWrapper {...props}/>) | ||
const button = wrapper.find(`input[type='submit']`) | ||
expect(button.exists()).toBe(true) | ||
expect(button.prop('value')).toEqual(submitText) | ||
}) | ||
|
||
it('should render `HiddenServiceDiscoveryInput` child', () => { | ||
const wrapper = mount(<FormWrapper {...props}/>) | ||
it('should render a hidden input for service discovery when required', () => { | ||
const wrapper = shallow(<FormWrapper {...props}/>) | ||
|
||
wrapper.setProps({ hasHiddenServiceDiscoveryInput: false }) | ||
expect(wrapper.find(HiddenServiceDiscoveryInput).exists()).toEqual(false) | ||
|
||
wrapper.setProps({ hasHiddenServiceDiscoveryInput: true }) | ||
expect(wrapper.find(HiddenServiceDiscoveryInput).exists()).toEqual(true) | ||
}) | ||
|
||
it('should render `CSRFToken` child', () => { | ||
const wrapper = mount(<FormWrapper {...props}/>) | ||
expect(wrapper.find(CSRFToken).exists()).toEqual(true) | ||
const wrapper = shallow(<FormWrapper {...props}/>) | ||
expect(wrapper.find('CSRFToken').exists()).toEqual(true) | ||
}) |
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,32 +1,41 @@ | ||
// @flow | ||
|
||
import React from 'react' | ||
import Enzyme, {mount} from 'enzyme' | ||
import Enzyme, {mount, shallow} from 'enzyme' | ||
import Adapter from 'enzyme-adapter-react-16' | ||
|
||
import {Select} from 'NewService/components/FormElements' | ||
|
||
Enzyme.configure({adapter: new Adapter()}) | ||
|
||
const options = ['project_01', 'project_02'] | ||
const props = { | ||
name: 'my-select', | ||
id: 'select-id', | ||
onChange: jest.fn(), | ||
options: [ | ||
{metadata: {name: 'one'}}, | ||
{metadata: {name: 'two'}} | ||
] | ||
options | ||
} | ||
|
||
it('should render itself properly', () => { | ||
const wrapper = mount(<Select {...props}/>) | ||
expect(wrapper.find('select').exists()).toEqual(true) | ||
expect(wrapper.find('select').props().name).toEqual('my-select') | ||
expect(wrapper.find('select').props().id).toEqual('select-id') | ||
expect(wrapper.find('select').props().onChange).toEqual(props.onChange) | ||
expect(wrapper.find(Select).exists()).toEqual(true) | ||
}) | ||
|
||
it('should render with proper options', () => { | ||
it('should render a select with options', () => { | ||
const wrapper = mount(<Select {...props}/>) | ||
expect(wrapper.find('option').length).toEqual(2) | ||
expect(wrapper.find('option').first().props().value).toEqual('one') | ||
expect(wrapper.find('option').last().props().value).toEqual('two') | ||
expect(wrapper.find('select').exists()).toEqual(true) | ||
|
||
for (let option of options) { | ||
expect(wrapper.exists(`option[value="${option}"]`)).toEqual(true) | ||
} | ||
}) | ||
|
||
it('should call onChange when an option is selected', () => { | ||
const option = 'foo' | ||
const onChange = jest.fn() | ||
const wrapper = shallow(<Select {...props}/>) | ||
|
||
wrapper.setProps({ onChange }) | ||
wrapper.find('select').simulate('change', option) | ||
|
||
expect(onChange).toHaveBeenCalledWith(option) | ||
}) |
Oops, something went wrong.