mirror of
https://github.com/ansible/awx.git
synced 2026-01-13 02:50:02 -03:30
update components tests to use mountWithContexts when relevant
This commit is contained in:
parent
986641de9f
commit
261980f18e
@ -1,6 +1,5 @@
|
||||
import React from 'react';
|
||||
import { mount } from 'enzyme';
|
||||
import { I18nProvider } from '@lingui/react';
|
||||
import { mountWithContexts } from '../enzymeHelpers';
|
||||
import About from '../../src/components/About';
|
||||
|
||||
describe('<About />', () => {
|
||||
@ -8,20 +7,16 @@ describe('<About />', () => {
|
||||
let closeButton;
|
||||
const onClose = jest.fn();
|
||||
test('initially renders without crashing', () => {
|
||||
aboutWrapper = mount(
|
||||
<I18nProvider>
|
||||
<About isOpen onClose={onClose} />
|
||||
</I18nProvider>
|
||||
aboutWrapper = mountWithContexts(
|
||||
<About isOpen onClose={onClose} />
|
||||
);
|
||||
expect(aboutWrapper.length).toBe(1);
|
||||
aboutWrapper.unmount();
|
||||
});
|
||||
|
||||
test('close button calls onClose handler', () => {
|
||||
aboutWrapper = mount(
|
||||
<I18nProvider>
|
||||
<About isOpen onClose={onClose} />
|
||||
</I18nProvider>
|
||||
aboutWrapper = mountWithContexts(
|
||||
<About isOpen onClose={onClose} />
|
||||
);
|
||||
closeButton = aboutWrapper.find('AboutModalBoxCloseButton Button');
|
||||
closeButton.simulate('click');
|
||||
|
||||
@ -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);
|
||||
});
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
import React from 'react';
|
||||
import { mount } from 'enzyme';
|
||||
import { I18nProvider } from '@lingui/react';
|
||||
import { mountWithContexts } from '../enzymeHelpers';
|
||||
import DataListToolbar from '../../src/components/DataListToolbar';
|
||||
|
||||
describe('<DataListToolbar />', () => {
|
||||
@ -25,20 +24,18 @@ describe('<DataListToolbar />', () => {
|
||||
const onSort = jest.fn();
|
||||
const onSelectAll = jest.fn();
|
||||
|
||||
toolbar = mount(
|
||||
<I18nProvider>
|
||||
<DataListToolbar
|
||||
isAllSelected={false}
|
||||
showExpandCollapse
|
||||
sortedColumnKey="name"
|
||||
sortOrder="ascending"
|
||||
columns={columns}
|
||||
onSearch={onSearch}
|
||||
onSort={onSort}
|
||||
onSelectAll={onSelectAll}
|
||||
showSelectAll
|
||||
/>
|
||||
</I18nProvider>
|
||||
toolbar = mountWithContexts(
|
||||
<DataListToolbar
|
||||
isAllSelected={false}
|
||||
showExpandCollapse
|
||||
sortedColumnKey="name"
|
||||
sortOrder="ascending"
|
||||
columns={columns}
|
||||
onSearch={onSearch}
|
||||
onSort={onSort}
|
||||
onSelectAll={onSelectAll}
|
||||
showSelectAll
|
||||
/>
|
||||
);
|
||||
|
||||
toolbar.find(sort).simulate('click');
|
||||
@ -76,18 +73,16 @@ describe('<DataListToolbar />', () => {
|
||||
const onSort = jest.fn();
|
||||
const onSelectAll = jest.fn();
|
||||
|
||||
toolbar = mount(
|
||||
<I18nProvider>
|
||||
<DataListToolbar
|
||||
isAllSelected={false}
|
||||
sortedColumnKey="foo"
|
||||
sortOrder="ascending"
|
||||
columns={multipleColumns}
|
||||
onSearch={onSearch}
|
||||
onSort={onSort}
|
||||
onSelectAll={onSelectAll}
|
||||
/>
|
||||
</I18nProvider>
|
||||
toolbar = mountWithContexts(
|
||||
<DataListToolbar
|
||||
isAllSelected={false}
|
||||
sortedColumnKey="foo"
|
||||
sortOrder="ascending"
|
||||
columns={multipleColumns}
|
||||
onSearch={onSearch}
|
||||
onSort={onSort}
|
||||
onSelectAll={onSelectAll}
|
||||
/>
|
||||
);
|
||||
const sortDropdownToggle = toolbar.find(sortDropdownToggleSelector);
|
||||
expect(sortDropdownToggle.length).toBe(2);
|
||||
@ -100,18 +95,16 @@ describe('<DataListToolbar />', () => {
|
||||
|
||||
const mockedSortEvent = { target: { innerText: 'Bar' } };
|
||||
sortDropdownItems.at(0).simulate('click', mockedSortEvent);
|
||||
toolbar = mount(
|
||||
<I18nProvider>
|
||||
<DataListToolbar
|
||||
isAllSelected={false}
|
||||
sortedColumnKey="foo"
|
||||
sortOrder="descending"
|
||||
columns={multipleColumns}
|
||||
onSearch={onSearch}
|
||||
onSort={onSort}
|
||||
onSelectAll={onSelectAll}
|
||||
/>
|
||||
</I18nProvider>
|
||||
toolbar = mountWithContexts(
|
||||
<DataListToolbar
|
||||
isAllSelected={false}
|
||||
sortedColumnKey="foo"
|
||||
sortOrder="descending"
|
||||
columns={multipleColumns}
|
||||
onSearch={onSearch}
|
||||
onSort={onSort}
|
||||
onSelectAll={onSelectAll}
|
||||
/>
|
||||
);
|
||||
toolbar.update();
|
||||
|
||||
@ -152,70 +145,62 @@ describe('<DataListToolbar />', () => {
|
||||
const onSort = jest.fn();
|
||||
const onSelectAll = jest.fn();
|
||||
|
||||
toolbar = mount(
|
||||
<I18nProvider>
|
||||
<DataListToolbar
|
||||
isAllSelected={false}
|
||||
sortedColumnKey="id"
|
||||
sortOrder="descending"
|
||||
columns={numericColumns}
|
||||
onSearch={onSearch}
|
||||
onSort={onSort}
|
||||
onSelectAll={onSelectAll}
|
||||
showDelete
|
||||
/>
|
||||
</I18nProvider>
|
||||
toolbar = mountWithContexts(
|
||||
<DataListToolbar
|
||||
isAllSelected={false}
|
||||
sortedColumnKey="id"
|
||||
sortOrder="descending"
|
||||
columns={numericColumns}
|
||||
onSearch={onSearch}
|
||||
onSort={onSort}
|
||||
onSelectAll={onSelectAll}
|
||||
showDelete
|
||||
/>
|
||||
);
|
||||
|
||||
const downNumericIcon = toolbar.find(downNumericIconSelector);
|
||||
expect(downNumericIcon.length).toBe(1);
|
||||
|
||||
toolbar = mount(
|
||||
<I18nProvider>
|
||||
<DataListToolbar
|
||||
isAllSelected={false}
|
||||
sortedColumnKey="id"
|
||||
sortOrder="ascending"
|
||||
columns={numericColumns}
|
||||
onSearch={onSearch}
|
||||
onSort={onSort}
|
||||
onSelectAll={onSelectAll}
|
||||
/>
|
||||
</I18nProvider>
|
||||
toolbar = mountWithContexts(
|
||||
<DataListToolbar
|
||||
isAllSelected={false}
|
||||
sortedColumnKey="id"
|
||||
sortOrder="ascending"
|
||||
columns={numericColumns}
|
||||
onSearch={onSearch}
|
||||
onSort={onSort}
|
||||
onSelectAll={onSelectAll}
|
||||
/>
|
||||
);
|
||||
|
||||
const upNumericIcon = toolbar.find(upNumericIconSelector);
|
||||
expect(upNumericIcon.length).toBe(1);
|
||||
|
||||
toolbar = mount(
|
||||
<I18nProvider>
|
||||
<DataListToolbar
|
||||
isAllSelected={false}
|
||||
sortedColumnKey="name"
|
||||
sortOrder="descending"
|
||||
columns={alphaColumns}
|
||||
onSearch={onSearch}
|
||||
onSort={onSort}
|
||||
onSelectAll={onSelectAll}
|
||||
/>
|
||||
</I18nProvider>
|
||||
toolbar = mountWithContexts(
|
||||
<DataListToolbar
|
||||
isAllSelected={false}
|
||||
sortedColumnKey="name"
|
||||
sortOrder="descending"
|
||||
columns={alphaColumns}
|
||||
onSearch={onSearch}
|
||||
onSort={onSort}
|
||||
onSelectAll={onSelectAll}
|
||||
/>
|
||||
);
|
||||
|
||||
const downAlphaIcon = toolbar.find(downAlphaIconSelector);
|
||||
expect(downAlphaIcon.length).toBe(1);
|
||||
|
||||
toolbar = mount(
|
||||
<I18nProvider>
|
||||
<DataListToolbar
|
||||
isAllSelected={false}
|
||||
sortedColumnKey="name"
|
||||
sortOrder="ascending"
|
||||
columns={alphaColumns}
|
||||
onSearch={onSearch}
|
||||
onSort={onSort}
|
||||
onSelectAll={onSelectAll}
|
||||
/>
|
||||
</I18nProvider>
|
||||
toolbar = mountWithContexts(
|
||||
<DataListToolbar
|
||||
isAllSelected={false}
|
||||
sortedColumnKey="name"
|
||||
sortOrder="ascending"
|
||||
columns={alphaColumns}
|
||||
onSearch={onSearch}
|
||||
onSort={onSort}
|
||||
onSelectAll={onSelectAll}
|
||||
/>
|
||||
);
|
||||
|
||||
const upAlphaIcon = toolbar.find(upAlphaIconSelector);
|
||||
@ -232,22 +217,20 @@ describe('<DataListToolbar />', () => {
|
||||
const showDelete = true;
|
||||
const disableTrashCanIcon = false;
|
||||
|
||||
toolbar = mount(
|
||||
<I18nProvider>
|
||||
<DataListToolbar
|
||||
isAllSelected={false}
|
||||
selected={() => [1, 2, 3, 4]}
|
||||
sortedColumnKey="name"
|
||||
sortOrder="ascending"
|
||||
columns={columns}
|
||||
onSearch={onSearch}
|
||||
onSort={onSort}
|
||||
onSelectAll={onSelectAll}
|
||||
onOpenDeleteModal={onOpenDeleteModal}
|
||||
showDelete={showDelete}
|
||||
disableTrashCanIcon={disableTrashCanIcon}
|
||||
/>
|
||||
</I18nProvider>
|
||||
toolbar = mountWithContexts(
|
||||
<DataListToolbar
|
||||
isAllSelected={false}
|
||||
selected={() => [1, 2, 3, 4]}
|
||||
sortedColumnKey="name"
|
||||
sortOrder="ascending"
|
||||
columns={columns}
|
||||
onSearch={onSearch}
|
||||
onSort={onSort}
|
||||
onSelectAll={onSelectAll}
|
||||
onOpenDeleteModal={onOpenDeleteModal}
|
||||
showDelete={showDelete}
|
||||
disableTrashCanIcon={disableTrashCanIcon}
|
||||
/>
|
||||
);
|
||||
|
||||
toolbar.find(openDeleteModalButton).simulate('click');
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
import React from 'react';
|
||||
import { mount } from 'enzyme';
|
||||
import { I18nProvider } from '@lingui/react';
|
||||
import { mountWithContexts } from '../enzymeHelpers';
|
||||
import ExpandCollapse from '../../src/components/ExpandCollapse';
|
||||
|
||||
describe('<ExpandCollapse />', () => {
|
||||
@ -8,14 +7,12 @@ describe('<ExpandCollapse />', () => {
|
||||
const onExpand = jest.fn();
|
||||
const isCompact = false;
|
||||
test('initially renders without crashing', () => {
|
||||
const wrapper = mount(
|
||||
<I18nProvider>
|
||||
<ExpandCollapse
|
||||
onCompact={onCompact}
|
||||
onExpand={onExpand}
|
||||
isCompact={isCompact}
|
||||
/>
|
||||
</I18nProvider>
|
||||
const wrapper = mountWithContexts(
|
||||
<ExpandCollapse
|
||||
onCompact={onCompact}
|
||||
onExpand={onExpand}
|
||||
isCompact={isCompact}
|
||||
/>
|
||||
);
|
||||
expect(wrapper.length).toBe(1);
|
||||
wrapper.unmount();
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
import React from 'react';
|
||||
import { mount } from 'enzyme';
|
||||
import { I18nProvider } from '@lingui/react';
|
||||
import { mountWithContexts } from '../enzymeHelpers';
|
||||
import Lookup from '../../src/components/Lookup';
|
||||
import { _Lookup } from '../../src/components/Lookup/Lookup';
|
||||
|
||||
@ -10,36 +9,32 @@ const mockColumns = [
|
||||
];
|
||||
describe('<Lookup />', () => {
|
||||
test('initially renders succesfully', () => {
|
||||
mount(
|
||||
<I18nProvider>
|
||||
<_Lookup
|
||||
lookup_header="Foo Bar"
|
||||
name="fooBar"
|
||||
value={mockData}
|
||||
onLookupSave={() => { }}
|
||||
getItems={() => { }}
|
||||
columns={mockColumns}
|
||||
sortedColumnKey="name"
|
||||
handleHttpError={() => {}}
|
||||
/>
|
||||
</I18nProvider>
|
||||
mountWithContexts(
|
||||
<_Lookup
|
||||
lookup_header="Foo Bar"
|
||||
name="fooBar"
|
||||
value={mockData}
|
||||
onLookupSave={() => { }}
|
||||
getItems={() => { }}
|
||||
columns={mockColumns}
|
||||
sortedColumnKey="name"
|
||||
handleHttpError={() => {}}
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
||||
test('API response is formatted properly', (done) => {
|
||||
const wrapper = mount(
|
||||
<I18nProvider>
|
||||
<_Lookup
|
||||
lookup_header="Foo Bar"
|
||||
name="fooBar"
|
||||
value={mockData}
|
||||
onLookupSave={() => { }}
|
||||
getItems={() => ({ data: { results: [{ name: 'test instance', id: 1 }] } })}
|
||||
columns={mockColumns}
|
||||
sortedColumnKey="name"
|
||||
handleHttpError={() => {}}
|
||||
/>
|
||||
</I18nProvider>
|
||||
const wrapper = mountWithContexts(
|
||||
<_Lookup
|
||||
lookup_header="Foo Bar"
|
||||
name="fooBar"
|
||||
value={mockData}
|
||||
onLookupSave={() => { }}
|
||||
getItems={() => ({ data: { results: [{ name: 'test instance', id: 1 }] } })}
|
||||
columns={mockColumns}
|
||||
sortedColumnKey="name"
|
||||
handleHttpError={() => {}}
|
||||
/>
|
||||
).find('Lookup');
|
||||
|
||||
setImmediate(() => {
|
||||
@ -51,20 +46,18 @@ describe('<Lookup />', () => {
|
||||
test('Opens modal when search icon is clicked', () => {
|
||||
const spy = jest.spyOn(_Lookup.prototype, 'handleModalToggle');
|
||||
const mockSelected = [{ name: 'foo', id: 1 }];
|
||||
const wrapper = mount(
|
||||
<I18nProvider>
|
||||
<_Lookup
|
||||
id="search"
|
||||
lookup_header="Foo Bar"
|
||||
name="fooBar"
|
||||
value={mockSelected}
|
||||
onLookupSave={() => { }}
|
||||
getItems={() => { }}
|
||||
columns={mockColumns}
|
||||
sortedColumnKey="name"
|
||||
handleHttpError={() => {}}
|
||||
/>
|
||||
</I18nProvider>
|
||||
const wrapper = mountWithContexts(
|
||||
<_Lookup
|
||||
id="search"
|
||||
lookup_header="Foo Bar"
|
||||
name="fooBar"
|
||||
value={mockSelected}
|
||||
onLookupSave={() => { }}
|
||||
getItems={() => { }}
|
||||
columns={mockColumns}
|
||||
sortedColumnKey="name"
|
||||
handleHttpError={() => {}}
|
||||
/>
|
||||
).find('Lookup');
|
||||
expect(spy).not.toHaveBeenCalled();
|
||||
expect(wrapper.state('lookupSelectedItems')).toEqual(mockSelected);
|
||||
@ -81,20 +74,18 @@ describe('<Lookup />', () => {
|
||||
test('calls "toggleSelected" when a user changes a checkbox', (done) => {
|
||||
const spy = jest.spyOn(_Lookup.prototype, 'toggleSelected');
|
||||
const mockSelected = [{ name: 'foo', id: 1 }];
|
||||
const wrapper = mount(
|
||||
<I18nProvider>
|
||||
<_Lookup
|
||||
id="search"
|
||||
lookup_header="Foo Bar"
|
||||
name="fooBar"
|
||||
value={mockSelected}
|
||||
onLookupSave={() => { }}
|
||||
getItems={() => ({ data: { results: [{ name: 'test instance', id: 1 }] } })}
|
||||
columns={mockColumns}
|
||||
sortedColumnKey="name"
|
||||
handleHttpError={() => {}}
|
||||
/>
|
||||
</I18nProvider>
|
||||
const wrapper = mountWithContexts(
|
||||
<_Lookup
|
||||
id="search"
|
||||
lookup_header="Foo Bar"
|
||||
name="fooBar"
|
||||
value={mockSelected}
|
||||
onLookupSave={() => { }}
|
||||
getItems={() => ({ data: { results: [{ name: 'test instance', id: 1 }] } })}
|
||||
columns={mockColumns}
|
||||
sortedColumnKey="name"
|
||||
handleHttpError={() => {}}
|
||||
/>
|
||||
);
|
||||
setImmediate(() => {
|
||||
const searchItem = wrapper.find('button[aria-label="Search"]');
|
||||
@ -108,20 +99,18 @@ describe('<Lookup />', () => {
|
||||
test('calls "toggleSelected" when remove icon is clicked', () => {
|
||||
const spy = jest.spyOn(_Lookup.prototype, 'toggleSelected');
|
||||
mockData = [{ name: 'foo', id: 1 }, { name: 'bar', id: 2 }];
|
||||
const wrapper = mount(
|
||||
<I18nProvider>
|
||||
<_Lookup
|
||||
id="search"
|
||||
lookup_header="Foo Bar"
|
||||
name="fooBar"
|
||||
value={mockData}
|
||||
onLookupSave={() => { }}
|
||||
getItems={() => { }}
|
||||
columns={mockColumns}
|
||||
sortedColumnKey="name"
|
||||
handleHttpError={() => {}}
|
||||
/>
|
||||
</I18nProvider>
|
||||
const wrapper = mountWithContexts(
|
||||
<_Lookup
|
||||
id="search"
|
||||
lookup_header="Foo Bar"
|
||||
name="fooBar"
|
||||
value={mockData}
|
||||
onLookupSave={() => { }}
|
||||
getItems={() => { }}
|
||||
columns={mockColumns}
|
||||
sortedColumnKey="name"
|
||||
handleHttpError={() => {}}
|
||||
/>
|
||||
);
|
||||
const removeIcon = wrapper.find('button[aria-label="close"]').first();
|
||||
removeIcon.simulate('click');
|
||||
@ -130,19 +119,16 @@ describe('<Lookup />', () => {
|
||||
|
||||
test('renders chips from prop value', () => {
|
||||
mockData = [{ name: 'foo', id: 0 }, { name: 'bar', id: 1 }];
|
||||
const wrapper = mount(
|
||||
<I18nProvider>
|
||||
<Lookup
|
||||
lookup_header="Foo Bar"
|
||||
onLookupSave={() => { }}
|
||||
value={mockData}
|
||||
selected={[]}
|
||||
getItems={() => { }}
|
||||
columns={mockColumns}
|
||||
sortedColumnKey="name"
|
||||
handleHttpError={() => {}}
|
||||
/>
|
||||
</I18nProvider>
|
||||
const wrapper = mountWithContexts(
|
||||
<Lookup
|
||||
lookup_header="Foo Bar"
|
||||
onLookupSave={() => { }}
|
||||
value={mockData}
|
||||
selected={[]}
|
||||
getItems={() => { }}
|
||||
columns={mockColumns}
|
||||
sortedColumnKey="name"
|
||||
/>
|
||||
).find('Lookup');
|
||||
const chip = wrapper.find('li.pf-c-chip');
|
||||
expect(chip).toHaveLength(2);
|
||||
@ -150,18 +136,15 @@ describe('<Lookup />', () => {
|
||||
|
||||
test('toggleSelected successfully adds/removes row from lookupSelectedItems state', () => {
|
||||
mockData = [];
|
||||
const wrapper = mount(
|
||||
<I18nProvider>
|
||||
<Lookup
|
||||
lookup_header="Foo Bar"
|
||||
onLookupSave={() => { }}
|
||||
value={mockData}
|
||||
getItems={() => { }}
|
||||
columns={mockColumns}
|
||||
sortedColumnKey="name"
|
||||
handleHttpError={() => {}}
|
||||
/>
|
||||
</I18nProvider>
|
||||
const wrapper = mountWithContexts(
|
||||
<Lookup
|
||||
lookup_header="Foo Bar"
|
||||
onLookupSave={() => { }}
|
||||
value={mockData}
|
||||
getItems={() => { }}
|
||||
columns={mockColumns}
|
||||
sortedColumnKey="name"
|
||||
/>
|
||||
).find('Lookup');
|
||||
wrapper.instance().toggleSelected({
|
||||
id: 1,
|
||||
@ -181,17 +164,14 @@ describe('<Lookup />', () => {
|
||||
test('saveModal calls callback with selected items', () => {
|
||||
mockData = [];
|
||||
const onLookupSaveFn = jest.fn();
|
||||
const wrapper = mount(
|
||||
<I18nProvider>
|
||||
<Lookup
|
||||
lookup_header="Foo Bar"
|
||||
name="fooBar"
|
||||
value={mockData}
|
||||
onLookupSave={onLookupSaveFn}
|
||||
getItems={() => { }}
|
||||
handleHttpError={() => {}}
|
||||
/>
|
||||
</I18nProvider>
|
||||
const wrapper = mountWithContexts(
|
||||
<Lookup
|
||||
lookup_header="Foo Bar"
|
||||
name="fooBar"
|
||||
value={mockData}
|
||||
onLookupSave={onLookupSaveFn}
|
||||
getItems={() => { }}
|
||||
/>
|
||||
).find('Lookup');
|
||||
wrapper.instance().toggleSelected({
|
||||
id: 1,
|
||||
@ -210,19 +190,17 @@ describe('<Lookup />', () => {
|
||||
|
||||
test('onSort sets state and calls getData ', () => {
|
||||
const spy = jest.spyOn(_Lookup.prototype, 'getData');
|
||||
const wrapper = mount(
|
||||
<I18nProvider>
|
||||
<_Lookup
|
||||
lookup_header="Foo Bar"
|
||||
onLookupSave={() => { }}
|
||||
value={mockData}
|
||||
selected={[]}
|
||||
columns={mockColumns}
|
||||
sortedColumnKey="name"
|
||||
getItems={() => { }}
|
||||
handleHttpError={() => {}}
|
||||
/>
|
||||
</I18nProvider>
|
||||
const wrapper = mountWithContexts(
|
||||
<_Lookup
|
||||
lookup_header="Foo Bar"
|
||||
onLookupSave={() => { }}
|
||||
value={mockData}
|
||||
selected={[]}
|
||||
columns={mockColumns}
|
||||
sortedColumnKey="name"
|
||||
getItems={() => { }}
|
||||
handleHttpError={() => {}}
|
||||
/>
|
||||
).find('Lookup');
|
||||
wrapper.instance().onSort('id', 'descending');
|
||||
expect(wrapper.state('sortedColumnKey')).toEqual('id');
|
||||
@ -232,19 +210,17 @@ describe('<Lookup />', () => {
|
||||
|
||||
test('onSearch calls getData (through calling onSort)', () => {
|
||||
const spy = jest.spyOn(_Lookup.prototype, 'getData');
|
||||
const wrapper = mount(
|
||||
<I18nProvider>
|
||||
<_Lookup
|
||||
lookup_header="Foo Bar"
|
||||
onLookupSave={() => { }}
|
||||
value={mockData}
|
||||
selected={[]}
|
||||
columns={mockColumns}
|
||||
sortedColumnKey="name"
|
||||
getItems={() => { }}
|
||||
handleHttpError={() => {}}
|
||||
/>
|
||||
</I18nProvider>
|
||||
const wrapper = mountWithContexts(
|
||||
<_Lookup
|
||||
lookup_header="Foo Bar"
|
||||
onLookupSave={() => { }}
|
||||
value={mockData}
|
||||
selected={[]}
|
||||
columns={mockColumns}
|
||||
sortedColumnKey="name"
|
||||
getItems={() => { }}
|
||||
handleHttpError={() => {}}
|
||||
/>
|
||||
).find('Lookup');
|
||||
wrapper.instance().onSearch();
|
||||
expect(spy).toHaveBeenCalled();
|
||||
@ -252,19 +228,17 @@ describe('<Lookup />', () => {
|
||||
|
||||
test('onSetPage sets state and calls getData ', () => {
|
||||
const spy = jest.spyOn(_Lookup.prototype, 'getData');
|
||||
const wrapper = mount(
|
||||
<I18nProvider>
|
||||
<_Lookup
|
||||
lookup_header="Foo Bar"
|
||||
onLookupSave={() => { }}
|
||||
value={mockData}
|
||||
selected={[]}
|
||||
columns={mockColumns}
|
||||
sortedColumnKey="name"
|
||||
getItems={() => { }}
|
||||
handleHttpError={() => {}}
|
||||
/>
|
||||
</I18nProvider>
|
||||
const wrapper = mountWithContexts(
|
||||
<_Lookup
|
||||
lookup_header="Foo Bar"
|
||||
onLookupSave={() => { }}
|
||||
value={mockData}
|
||||
selected={[]}
|
||||
columns={mockColumns}
|
||||
sortedColumnKey="name"
|
||||
getItems={() => { }}
|
||||
handleHttpError={() => {}}
|
||||
/>
|
||||
).find('Lookup');
|
||||
wrapper.instance().onSetPage(2, 10);
|
||||
expect(wrapper.state('page')).toEqual(2);
|
||||
|
||||
@ -39,7 +39,7 @@ describe('NavExpandableGroup', () => {
|
||||
];
|
||||
|
||||
params.forEach(([location, path, expected]) => {
|
||||
test(`when location is ${location}', isActivePath('${path}') returns ${expected} `, () => {
|
||||
test(`when location is ${location}, isActivePath('${path}') returns ${expected} `, () => {
|
||||
const component = mount(
|
||||
<MemoryRouter initialEntries={[location]}>
|
||||
<Nav aria-label="Test Navigation">
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
import React from 'react';
|
||||
import { mount } from 'enzyme';
|
||||
import { MemoryRouter } from 'react-router-dom';
|
||||
import { I18nProvider } from '@lingui/react';
|
||||
import { mountWithContexts } from '../enzymeHelpers';
|
||||
import NotificationListItem from '../../src/components/NotificationsList/NotificationListItem';
|
||||
|
||||
describe('<NotificationListItem />', () => {
|
||||
@ -16,88 +14,68 @@ describe('<NotificationListItem />', () => {
|
||||
});
|
||||
|
||||
test('initially renders succesfully', () => {
|
||||
wrapper = mount(
|
||||
<I18nProvider>
|
||||
<MemoryRouter>
|
||||
<NotificationListItem
|
||||
itemId={9000}
|
||||
toggleNotification={toggleNotification}
|
||||
detailUrl="/foo"
|
||||
notificationType="slack"
|
||||
/>
|
||||
</MemoryRouter>
|
||||
</I18nProvider>
|
||||
wrapper = mountWithContexts(
|
||||
<NotificationListItem
|
||||
itemId={9000}
|
||||
toggleNotification={toggleNotification}
|
||||
detailUrl="/foo"
|
||||
notificationType="slack"
|
||||
/>
|
||||
);
|
||||
expect(wrapper.length).toBe(1);
|
||||
});
|
||||
|
||||
test('handles success click when toggle is on', () => {
|
||||
wrapper = mount(
|
||||
<I18nProvider>
|
||||
<MemoryRouter>
|
||||
<NotificationListItem
|
||||
itemId={9000}
|
||||
successTurnedOn
|
||||
toggleNotification={toggleNotification}
|
||||
detailUrl="/foo"
|
||||
notificationType="slack"
|
||||
/>
|
||||
</MemoryRouter>
|
||||
</I18nProvider>
|
||||
wrapper = mountWithContexts(
|
||||
<NotificationListItem
|
||||
itemId={9000}
|
||||
successTurnedOn
|
||||
toggleNotification={toggleNotification}
|
||||
detailUrl="/foo"
|
||||
notificationType="slack"
|
||||
/>
|
||||
);
|
||||
wrapper.find('Switch').first().find('input').simulate('change');
|
||||
expect(toggleNotification).toHaveBeenCalledWith(9000, true, 'success');
|
||||
});
|
||||
|
||||
test('handles success click when toggle is off', () => {
|
||||
wrapper = mount(
|
||||
<I18nProvider>
|
||||
<MemoryRouter>
|
||||
<NotificationListItem
|
||||
itemId={9000}
|
||||
successTurnedOn={false}
|
||||
toggleNotification={toggleNotification}
|
||||
detailUrl="/foo"
|
||||
notificationType="slack"
|
||||
/>
|
||||
</MemoryRouter>
|
||||
</I18nProvider>
|
||||
wrapper = mountWithContexts(
|
||||
<NotificationListItem
|
||||
itemId={9000}
|
||||
successTurnedOn={false}
|
||||
toggleNotification={toggleNotification}
|
||||
detailUrl="/foo"
|
||||
notificationType="slack"
|
||||
/>
|
||||
);
|
||||
wrapper.find('Switch').first().find('input').simulate('change');
|
||||
expect(toggleNotification).toHaveBeenCalledWith(9000, false, 'success');
|
||||
});
|
||||
|
||||
test('handles error click when toggle is on', () => {
|
||||
wrapper = mount(
|
||||
<I18nProvider>
|
||||
<MemoryRouter>
|
||||
<NotificationListItem
|
||||
itemId={9000}
|
||||
errorTurnedOn
|
||||
toggleNotification={toggleNotification}
|
||||
detailUrl="/foo"
|
||||
notificationType="slack"
|
||||
/>
|
||||
</MemoryRouter>
|
||||
</I18nProvider>
|
||||
wrapper = mountWithContexts(
|
||||
<NotificationListItem
|
||||
itemId={9000}
|
||||
errorTurnedOn
|
||||
toggleNotification={toggleNotification}
|
||||
detailUrl="/foo"
|
||||
notificationType="slack"
|
||||
/>
|
||||
);
|
||||
wrapper.find('Switch').at(1).find('input').simulate('change');
|
||||
expect(toggleNotification).toHaveBeenCalledWith(9000, true, 'error');
|
||||
});
|
||||
|
||||
test('handles error click when toggle is off', () => {
|
||||
wrapper = mount(
|
||||
<I18nProvider>
|
||||
<MemoryRouter>
|
||||
<NotificationListItem
|
||||
itemId={9000}
|
||||
errorTurnedOn={false}
|
||||
toggleNotification={toggleNotification}
|
||||
detailUrl="/foo"
|
||||
notificationType="slack"
|
||||
/>
|
||||
</MemoryRouter>
|
||||
</I18nProvider>
|
||||
wrapper = mountWithContexts(
|
||||
<NotificationListItem
|
||||
itemId={9000}
|
||||
errorTurnedOn={false}
|
||||
toggleNotification={toggleNotification}
|
||||
detailUrl="/foo"
|
||||
notificationType="slack"
|
||||
/>
|
||||
);
|
||||
wrapper.find('Switch').at(1).find('input').simulate('change');
|
||||
expect(toggleNotification).toHaveBeenCalledWith(9000, false, 'error');
|
||||
|
||||
@ -1,24 +1,17 @@
|
||||
import React from 'react';
|
||||
import { mount } from 'enzyme';
|
||||
|
||||
import { MemoryRouter } from 'react-router-dom';
|
||||
import { I18nProvider } from '@lingui/react';
|
||||
import { mountWithContexts } from '../enzymeHelpers';
|
||||
|
||||
import { _NotifyAndRedirect } from '../../src/components/NotifyAndRedirect';
|
||||
|
||||
describe('<NotifyAndRedirect />', () => {
|
||||
test('initially renders succesfully and calls setRootDialogMessage', () => {
|
||||
const setRootDialogMessage = jest.fn();
|
||||
mount(
|
||||
<MemoryRouter>
|
||||
<I18nProvider>
|
||||
<_NotifyAndRedirect
|
||||
to="foo"
|
||||
setRootDialogMessage={setRootDialogMessage}
|
||||
location={{ pathname: 'foo' }}
|
||||
/>
|
||||
</I18nProvider>
|
||||
</MemoryRouter>
|
||||
mountWithContexts(
|
||||
<_NotifyAndRedirect
|
||||
to="foo"
|
||||
setRootDialogMessage={setRootDialogMessage}
|
||||
location={{ pathname: 'foo' }}
|
||||
/>
|
||||
);
|
||||
expect(setRootDialogMessage).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@ -1,8 +1,5 @@
|
||||
import React from 'react';
|
||||
import { MemoryRouter } from 'react-router-dom';
|
||||
import { mount } from 'enzyme';
|
||||
|
||||
import { I18nProvider } from '@lingui/react';
|
||||
import { mountWithContexts } from '../enzymeHelpers';
|
||||
import PageHeaderToolbar from '../../src/components/PageHeaderToolbar';
|
||||
|
||||
describe('PageHeaderToolbar', () => {
|
||||
@ -12,13 +9,11 @@ describe('PageHeaderToolbar', () => {
|
||||
const onLogoutClick = jest.fn();
|
||||
|
||||
test('expected content is rendered on initialization', () => {
|
||||
const wrapper = mount(
|
||||
<I18nProvider>
|
||||
<PageHeaderToolbar
|
||||
onAboutClick={onAboutClick}
|
||||
onLogoutClick={onLogoutClick}
|
||||
/>
|
||||
</I18nProvider>
|
||||
const wrapper = mountWithContexts(
|
||||
<PageHeaderToolbar
|
||||
onAboutClick={onAboutClick}
|
||||
onLogoutClick={onLogoutClick}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(wrapper.find(pageHelpDropdownSelector)).toHaveLength(1);
|
||||
@ -26,15 +21,11 @@ describe('PageHeaderToolbar', () => {
|
||||
});
|
||||
|
||||
test('dropdowns have expected items and callbacks', () => {
|
||||
const wrapper = mount(
|
||||
<MemoryRouter>
|
||||
<I18nProvider>
|
||||
<PageHeaderToolbar
|
||||
onAboutClick={onAboutClick}
|
||||
onLogoutClick={onLogoutClick}
|
||||
/>
|
||||
</I18nProvider>
|
||||
</MemoryRouter>
|
||||
const wrapper = mountWithContexts(
|
||||
<PageHeaderToolbar
|
||||
onAboutClick={onAboutClick}
|
||||
onLogoutClick={onLogoutClick}
|
||||
/>
|
||||
);
|
||||
expect(wrapper.find('DropdownItem')).toHaveLength(0);
|
||||
wrapper.find(pageHelpDropdownSelector).simulate('click');
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
import React from 'react';
|
||||
import { mount } from 'enzyme';
|
||||
import { I18nProvider } from '@lingui/react';
|
||||
import { mountWithContexts } from '../enzymeHelpers';
|
||||
import Search from '../../src/components/Search';
|
||||
|
||||
describe('<Search />', () => {
|
||||
@ -8,7 +7,6 @@ describe('<Search />', () => {
|
||||
|
||||
afterEach(() => {
|
||||
if (search) {
|
||||
search.unmount();
|
||||
search = null;
|
||||
}
|
||||
});
|
||||
@ -21,14 +19,12 @@ describe('<Search />', () => {
|
||||
|
||||
const onSearch = jest.fn();
|
||||
|
||||
search = mount(
|
||||
<I18nProvider>
|
||||
<Search
|
||||
sortedColumnKey="name"
|
||||
columns={columns}
|
||||
onSearch={onSearch}
|
||||
/>
|
||||
</I18nProvider>
|
||||
search = mountWithContexts(
|
||||
<Search
|
||||
sortedColumnKey="name"
|
||||
columns={columns}
|
||||
onSearch={onSearch}
|
||||
/>
|
||||
);
|
||||
|
||||
search.find(searchTextInput).instance().value = 'test-321';
|
||||
@ -42,14 +38,12 @@ describe('<Search />', () => {
|
||||
test('handleDropdownToggle properly updates state', async () => {
|
||||
const columns = [{ name: 'Name', key: 'name', isSortable: true }];
|
||||
const onSearch = jest.fn();
|
||||
const wrapper = mount(
|
||||
<I18nProvider>
|
||||
<Search
|
||||
sortedColumnKey="name"
|
||||
columns={columns}
|
||||
onSearch={onSearch}
|
||||
/>
|
||||
</I18nProvider>
|
||||
const wrapper = mountWithContexts(
|
||||
<Search
|
||||
sortedColumnKey="name"
|
||||
columns={columns}
|
||||
onSearch={onSearch}
|
||||
/>
|
||||
).find('Search');
|
||||
expect(wrapper.state('isSearchDropdownOpen')).toEqual(false);
|
||||
wrapper.instance().handleDropdownToggle(true);
|
||||
@ -62,14 +56,12 @@ describe('<Search />', () => {
|
||||
{ name: 'Description', key: 'description', isSortable: true }
|
||||
];
|
||||
const onSearch = jest.fn();
|
||||
const wrapper = mount(
|
||||
<I18nProvider>
|
||||
<Search
|
||||
sortedColumnKey="name"
|
||||
columns={columns}
|
||||
onSearch={onSearch}
|
||||
/>
|
||||
</I18nProvider>
|
||||
const wrapper = mountWithContexts(
|
||||
<Search
|
||||
sortedColumnKey="name"
|
||||
columns={columns}
|
||||
onSearch={onSearch}
|
||||
/>
|
||||
).find('Search');
|
||||
expect(wrapper.state('searchKey')).toEqual('name');
|
||||
wrapper.instance().handleDropdownSelect({ target: { innerText: 'Description' } });
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
import React from 'react';
|
||||
import { mount } from 'enzyme';
|
||||
import { I18nProvider } from '@lingui/react';
|
||||
import { mountWithContexts } from '../enzymeHelpers';
|
||||
import Sort from '../../src/components/Sort';
|
||||
|
||||
describe('<Sort />', () => {
|
||||
@ -8,7 +7,6 @@ describe('<Sort />', () => {
|
||||
|
||||
afterEach(() => {
|
||||
if (sort) {
|
||||
sort.unmount();
|
||||
sort = null;
|
||||
}
|
||||
});
|
||||
@ -20,15 +18,13 @@ describe('<Sort />', () => {
|
||||
|
||||
const onSort = jest.fn();
|
||||
|
||||
const wrapper = mount(
|
||||
<I18nProvider>
|
||||
<Sort
|
||||
sortedColumnKey="name"
|
||||
sortOrder="ascending"
|
||||
columns={columns}
|
||||
onSort={onSort}
|
||||
/>
|
||||
</I18nProvider>
|
||||
const wrapper = mountWithContexts(
|
||||
<Sort
|
||||
sortedColumnKey="name"
|
||||
sortOrder="ascending"
|
||||
columns={columns}
|
||||
onSort={onSort}
|
||||
/>
|
||||
).find('Sort');
|
||||
|
||||
wrapper.find(sortBtn).simulate('click');
|
||||
@ -47,15 +43,13 @@ describe('<Sort />', () => {
|
||||
|
||||
const onSort = jest.fn();
|
||||
|
||||
const wrapper = mount(
|
||||
<I18nProvider>
|
||||
<Sort
|
||||
sortedColumnKey="foo"
|
||||
sortOrder="ascending"
|
||||
columns={multipleColumns}
|
||||
onSort={onSort}
|
||||
/>
|
||||
</I18nProvider>
|
||||
const wrapper = mountWithContexts(
|
||||
<Sort
|
||||
sortedColumnKey="foo"
|
||||
sortOrder="ascending"
|
||||
columns={multipleColumns}
|
||||
onSort={onSort}
|
||||
/>
|
||||
).find('Sort');
|
||||
const sortDropdownToggle = wrapper.find('Button');
|
||||
expect(sortDropdownToggle.length).toBe(1);
|
||||
@ -73,15 +67,13 @@ describe('<Sort />', () => {
|
||||
|
||||
const onSort = jest.fn();
|
||||
|
||||
const wrapper = mount(
|
||||
<I18nProvider>
|
||||
<Sort
|
||||
sortedColumnKey="foo"
|
||||
sortOrder="descending"
|
||||
columns={multipleColumns}
|
||||
onSort={onSort}
|
||||
/>
|
||||
</I18nProvider>
|
||||
const wrapper = mountWithContexts(
|
||||
<Sort
|
||||
sortedColumnKey="foo"
|
||||
sortOrder="descending"
|
||||
columns={multipleColumns}
|
||||
onSort={onSort}
|
||||
/>
|
||||
).find('Sort');
|
||||
const sortDropdownToggle = wrapper.find('Button');
|
||||
expect(sortDropdownToggle.length).toBe(1);
|
||||
@ -99,15 +91,13 @@ describe('<Sort />', () => {
|
||||
|
||||
const onSort = jest.fn();
|
||||
|
||||
const wrapper = mount(
|
||||
<I18nProvider>
|
||||
<Sort
|
||||
sortedColumnKey="foo"
|
||||
sortOrder="ascending"
|
||||
columns={multipleColumns}
|
||||
onSort={onSort}
|
||||
/>
|
||||
</I18nProvider>
|
||||
const wrapper = mountWithContexts(
|
||||
<Sort
|
||||
sortedColumnKey="foo"
|
||||
sortOrder="ascending"
|
||||
columns={multipleColumns}
|
||||
onSort={onSort}
|
||||
/>
|
||||
).find('Sort');
|
||||
|
||||
wrapper.instance().handleDropdownSelect({ target: { innerText: 'Bar' } });
|
||||
@ -124,15 +114,13 @@ describe('<Sort />', () => {
|
||||
|
||||
const onSort = jest.fn();
|
||||
|
||||
const wrapper = mount(
|
||||
<I18nProvider>
|
||||
<Sort
|
||||
sortedColumnKey="foo"
|
||||
sortOrder="ascending"
|
||||
columns={multipleColumns}
|
||||
onSort={onSort}
|
||||
/>
|
||||
</I18nProvider>
|
||||
const wrapper = mountWithContexts(
|
||||
<Sort
|
||||
sortedColumnKey="foo"
|
||||
sortOrder="ascending"
|
||||
columns={multipleColumns}
|
||||
onSort={onSort}
|
||||
/>
|
||||
).find('Sort');
|
||||
expect(wrapper.state('isSortDropdownOpen')).toEqual(false);
|
||||
wrapper.instance().handleDropdownToggle(true);
|
||||
@ -149,57 +137,49 @@ describe('<Sort />', () => {
|
||||
const alphaColumns = [{ name: 'Name', key: 'name', isSortable: true, isNumeric: false }];
|
||||
const onSort = jest.fn();
|
||||
|
||||
sort = mount(
|
||||
<I18nProvider>
|
||||
<Sort
|
||||
sortedColumnKey="id"
|
||||
sortOrder="descending"
|
||||
columns={numericColumns}
|
||||
onSort={onSort}
|
||||
/>
|
||||
</I18nProvider>
|
||||
sort = mountWithContexts(
|
||||
<Sort
|
||||
sortedColumnKey="id"
|
||||
sortOrder="descending"
|
||||
columns={numericColumns}
|
||||
onSort={onSort}
|
||||
/>
|
||||
);
|
||||
|
||||
const downNumericIcon = sort.find(downNumericIconSelector);
|
||||
expect(downNumericIcon.length).toBe(1);
|
||||
|
||||
sort = mount(
|
||||
<I18nProvider>
|
||||
<Sort
|
||||
sortedColumnKey="id"
|
||||
sortOrder="ascending"
|
||||
columns={numericColumns}
|
||||
onSort={onSort}
|
||||
/>
|
||||
</I18nProvider>
|
||||
sort = mountWithContexts(
|
||||
<Sort
|
||||
sortedColumnKey="id"
|
||||
sortOrder="ascending"
|
||||
columns={numericColumns}
|
||||
onSort={onSort}
|
||||
/>
|
||||
);
|
||||
|
||||
const upNumericIcon = sort.find(upNumericIconSelector);
|
||||
expect(upNumericIcon.length).toBe(1);
|
||||
|
||||
sort = mount(
|
||||
<I18nProvider>
|
||||
<Sort
|
||||
sortedColumnKey="name"
|
||||
sortOrder="descending"
|
||||
columns={alphaColumns}
|
||||
onSort={onSort}
|
||||
/>
|
||||
</I18nProvider>
|
||||
sort = mountWithContexts(
|
||||
<Sort
|
||||
sortedColumnKey="name"
|
||||
sortOrder="descending"
|
||||
columns={alphaColumns}
|
||||
onSort={onSort}
|
||||
/>
|
||||
);
|
||||
|
||||
const downAlphaIcon = sort.find(downAlphaIconSelector);
|
||||
expect(downAlphaIcon.length).toBe(1);
|
||||
|
||||
sort = mount(
|
||||
<I18nProvider>
|
||||
<Sort
|
||||
sortedColumnKey="name"
|
||||
sortOrder="ascending"
|
||||
columns={alphaColumns}
|
||||
onSort={onSort}
|
||||
/>
|
||||
</I18nProvider>
|
||||
sort = mountWithContexts(
|
||||
<Sort
|
||||
sortedColumnKey="name"
|
||||
sortOrder="ascending"
|
||||
columns={alphaColumns}
|
||||
onSort={onSort}
|
||||
/>
|
||||
);
|
||||
|
||||
const upAlphaIcon = sort.find(upAlphaIconSelector);
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import React from 'react';
|
||||
import { MemoryRouter } from 'react-router-dom';
|
||||
import { mount } from 'enzyme';
|
||||
import { I18nProvider } from '@lingui/react';
|
||||
import { createMemoryHistory } from 'history';
|
||||
import { mountWithContexts } from '../enzymeHelpers';
|
||||
import TowerLogo from '../../src/components/TowerLogo';
|
||||
|
||||
let logoWrapper;
|
||||
@ -15,12 +14,8 @@ const findChildren = () => {
|
||||
|
||||
describe('<TowerLogo />', () => {
|
||||
test('initially renders without crashing', () => {
|
||||
logoWrapper = mount(
|
||||
<MemoryRouter>
|
||||
<I18nProvider>
|
||||
<TowerLogo />
|
||||
</I18nProvider>
|
||||
</MemoryRouter>
|
||||
logoWrapper = mountWithContexts(
|
||||
<TowerLogo />
|
||||
);
|
||||
findChildren();
|
||||
expect(logoWrapper.length).toBe(1);
|
||||
@ -29,12 +24,12 @@ describe('<TowerLogo />', () => {
|
||||
});
|
||||
|
||||
test('adds navigation to route history on click', () => {
|
||||
logoWrapper = mount(
|
||||
<MemoryRouter>
|
||||
<I18nProvider>
|
||||
<TowerLogo linkTo="/" />
|
||||
</I18nProvider>
|
||||
</MemoryRouter>
|
||||
const history = createMemoryHistory({
|
||||
initialEntries: ['/organizations/1/teams'],
|
||||
});
|
||||
|
||||
logoWrapper = mountWithContexts(
|
||||
<TowerLogo linkTo="/" />, { context: { router: { history } } }
|
||||
);
|
||||
findChildren();
|
||||
expect(towerLogoElem.props().history.length).toBe(1);
|
||||
@ -42,27 +37,9 @@ describe('<TowerLogo />', () => {
|
||||
expect(towerLogoElem.props().history.length).toBe(2);
|
||||
});
|
||||
|
||||
test('linkTo prop is optional', () => {
|
||||
logoWrapper = mount(
|
||||
<MemoryRouter>
|
||||
<I18nProvider>
|
||||
<TowerLogo />
|
||||
</I18nProvider>
|
||||
</MemoryRouter>
|
||||
);
|
||||
findChildren();
|
||||
expect(towerLogoElem.props().history.length).toBe(1);
|
||||
logoWrapper.simulate('click');
|
||||
expect(towerLogoElem.props().history.length).toBe(1);
|
||||
});
|
||||
|
||||
test('handles mouse over and out state.hover changes', () => {
|
||||
logoWrapper = mount(
|
||||
<MemoryRouter>
|
||||
<I18nProvider>
|
||||
<TowerLogo />
|
||||
</I18nProvider>
|
||||
</MemoryRouter>
|
||||
logoWrapper = mountWithContexts(
|
||||
<TowerLogo />
|
||||
);
|
||||
findChildren();
|
||||
findChildren();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user