update components tests to use mountWithContexts when relevant

This commit is contained in:
John Mitchell
2019-04-22 16:34:33 -04:00
parent 986641de9f
commit 261980f18e
12 changed files with 399 additions and 546 deletions

View File

@@ -1,37 +1,32 @@
import React from 'react';
import { mount } from 'enzyme';
import { I18nProvider } from '@lingui/react';
import { mountWithContexts } from '../enzymeHelpers';
import AnsibleSelect from '../../src/components/AnsibleSelect';
const label = 'test select';
const mockData = ['/venv/baz/', '/venv/ansible/'];
describe('<AnsibleSelect />', () => {
test('initially renders succesfully', async () => {
mount(
<I18nProvider>
<AnsibleSelect
value="foo"
name="bar"
onChange={() => { }}
label={label}
data={mockData}
/>
</I18nProvider>
mountWithContexts(
<AnsibleSelect
value="foo"
name="bar"
onChange={() => { }}
label={label}
data={mockData}
/>
);
});
test('calls "onSelectChange" on dropdown select change', () => {
const spy = jest.spyOn(AnsibleSelect.prototype, 'onSelectChange');
const wrapper = mount(
<I18nProvider>
<AnsibleSelect
value="foo"
name="bar"
onChange={() => { }}
label={label}
data={mockData}
/>
</I18nProvider>
const wrapper = mountWithContexts(
<AnsibleSelect
value="foo"
name="bar"
onChange={() => { }}
label={label}
data={mockData}
/>
);
expect(spy).not.toHaveBeenCalled();
wrapper.find('select').simulate('change');
@@ -39,17 +34,15 @@ describe('<AnsibleSelect />', () => {
});
test('Returns correct select options if defaultSelected props is passed', () => {
const wrapper = mount(
<I18nProvider>
<AnsibleSelect
value="foo"
name="bar"
onChange={() => { }}
label={label}
data={mockData}
defaultSelected={mockData[1]}
/>
</I18nProvider>
const wrapper = mountWithContexts(
<AnsibleSelect
value="foo"
name="bar"
onChange={() => { }}
label={label}
data={mockData}
defaultSelected={mockData[1]}
/>
);
expect(wrapper.find('FormSelect')).toHaveLength(1);
});