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,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>
aboutWrapper = mountWithContexts(
<About isOpen onClose={onClose} />
</I18nProvider>
);
expect(aboutWrapper.length).toBe(1);
aboutWrapper.unmount();
});
test('close button calls onClose handler', () => {
aboutWrapper = mount(
<I18nProvider>
aboutWrapper = mountWithContexts(
<About isOpen onClose={onClose} />
</I18nProvider>
);
closeButton = aboutWrapper.find('AboutModalBoxCloseButton Button');
closeButton.simulate('click');

View File

@@ -1,14 +1,12 @@
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>
mountWithContexts(
<AnsibleSelect
value="foo"
name="bar"
@@ -16,14 +14,12 @@ describe('<AnsibleSelect />', () => {
label={label}
data={mockData}
/>
</I18nProvider>
);
});
test('calls "onSelectChange" on dropdown select change', () => {
const spy = jest.spyOn(AnsibleSelect.prototype, 'onSelectChange');
const wrapper = mount(
<I18nProvider>
const wrapper = mountWithContexts(
<AnsibleSelect
value="foo"
name="bar"
@@ -31,7 +27,6 @@ describe('<AnsibleSelect />', () => {
label={label}
data={mockData}
/>
</I18nProvider>
);
expect(spy).not.toHaveBeenCalled();
wrapper.find('select').simulate('change');
@@ -39,8 +34,7 @@ describe('<AnsibleSelect />', () => {
});
test('Returns correct select options if defaultSelected props is passed', () => {
const wrapper = mount(
<I18nProvider>
const wrapper = mountWithContexts(
<AnsibleSelect
value="foo"
name="bar"
@@ -49,7 +43,6 @@ describe('<AnsibleSelect />', () => {
data={mockData}
defaultSelected={mockData[1]}
/>
</I18nProvider>
);
expect(wrapper.find('FormSelect')).toHaveLength(1);
});

View File

@@ -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,8 +24,7 @@ describe('<DataListToolbar />', () => {
const onSort = jest.fn();
const onSelectAll = jest.fn();
toolbar = mount(
<I18nProvider>
toolbar = mountWithContexts(
<DataListToolbar
isAllSelected={false}
showExpandCollapse
@@ -38,7 +36,6 @@ describe('<DataListToolbar />', () => {
onSelectAll={onSelectAll}
showSelectAll
/>
</I18nProvider>
);
toolbar.find(sort).simulate('click');
@@ -76,8 +73,7 @@ describe('<DataListToolbar />', () => {
const onSort = jest.fn();
const onSelectAll = jest.fn();
toolbar = mount(
<I18nProvider>
toolbar = mountWithContexts(
<DataListToolbar
isAllSelected={false}
sortedColumnKey="foo"
@@ -87,7 +83,6 @@ describe('<DataListToolbar />', () => {
onSort={onSort}
onSelectAll={onSelectAll}
/>
</I18nProvider>
);
const sortDropdownToggle = toolbar.find(sortDropdownToggleSelector);
expect(sortDropdownToggle.length).toBe(2);
@@ -100,8 +95,7 @@ describe('<DataListToolbar />', () => {
const mockedSortEvent = { target: { innerText: 'Bar' } };
sortDropdownItems.at(0).simulate('click', mockedSortEvent);
toolbar = mount(
<I18nProvider>
toolbar = mountWithContexts(
<DataListToolbar
isAllSelected={false}
sortedColumnKey="foo"
@@ -111,7 +105,6 @@ describe('<DataListToolbar />', () => {
onSort={onSort}
onSelectAll={onSelectAll}
/>
</I18nProvider>
);
toolbar.update();
@@ -152,8 +145,7 @@ describe('<DataListToolbar />', () => {
const onSort = jest.fn();
const onSelectAll = jest.fn();
toolbar = mount(
<I18nProvider>
toolbar = mountWithContexts(
<DataListToolbar
isAllSelected={false}
sortedColumnKey="id"
@@ -164,14 +156,12 @@ describe('<DataListToolbar />', () => {
onSelectAll={onSelectAll}
showDelete
/>
</I18nProvider>
);
const downNumericIcon = toolbar.find(downNumericIconSelector);
expect(downNumericIcon.length).toBe(1);
toolbar = mount(
<I18nProvider>
toolbar = mountWithContexts(
<DataListToolbar
isAllSelected={false}
sortedColumnKey="id"
@@ -181,14 +171,12 @@ describe('<DataListToolbar />', () => {
onSort={onSort}
onSelectAll={onSelectAll}
/>
</I18nProvider>
);
const upNumericIcon = toolbar.find(upNumericIconSelector);
expect(upNumericIcon.length).toBe(1);
toolbar = mount(
<I18nProvider>
toolbar = mountWithContexts(
<DataListToolbar
isAllSelected={false}
sortedColumnKey="name"
@@ -198,14 +186,12 @@ describe('<DataListToolbar />', () => {
onSort={onSort}
onSelectAll={onSelectAll}
/>
</I18nProvider>
);
const downAlphaIcon = toolbar.find(downAlphaIconSelector);
expect(downAlphaIcon.length).toBe(1);
toolbar = mount(
<I18nProvider>
toolbar = mountWithContexts(
<DataListToolbar
isAllSelected={false}
sortedColumnKey="name"
@@ -215,7 +201,6 @@ describe('<DataListToolbar />', () => {
onSort={onSort}
onSelectAll={onSelectAll}
/>
</I18nProvider>
);
const upAlphaIcon = toolbar.find(upAlphaIconSelector);
@@ -232,8 +217,7 @@ describe('<DataListToolbar />', () => {
const showDelete = true;
const disableTrashCanIcon = false;
toolbar = mount(
<I18nProvider>
toolbar = mountWithContexts(
<DataListToolbar
isAllSelected={false}
selected={() => [1, 2, 3, 4]}
@@ -247,7 +231,6 @@ describe('<DataListToolbar />', () => {
showDelete={showDelete}
disableTrashCanIcon={disableTrashCanIcon}
/>
</I18nProvider>
);
toolbar.find(openDeleteModalButton).simulate('click');

View File

@@ -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>
const wrapper = mountWithContexts(
<ExpandCollapse
onCompact={onCompact}
onExpand={onExpand}
isCompact={isCompact}
/>
</I18nProvider>
);
expect(wrapper.length).toBe(1);
wrapper.unmount();

View File

@@ -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,8 +9,7 @@ const mockColumns = [
];
describe('<Lookup />', () => {
test('initially renders succesfully', () => {
mount(
<I18nProvider>
mountWithContexts(
<_Lookup
lookup_header="Foo Bar"
name="fooBar"
@@ -22,13 +20,11 @@ describe('<Lookup />', () => {
sortedColumnKey="name"
handleHttpError={() => {}}
/>
</I18nProvider>
);
});
test('API response is formatted properly', (done) => {
const wrapper = mount(
<I18nProvider>
const wrapper = mountWithContexts(
<_Lookup
lookup_header="Foo Bar"
name="fooBar"
@@ -39,7 +35,6 @@ describe('<Lookup />', () => {
sortedColumnKey="name"
handleHttpError={() => {}}
/>
</I18nProvider>
).find('Lookup');
setImmediate(() => {
@@ -51,8 +46,7 @@ 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>
const wrapper = mountWithContexts(
<_Lookup
id="search"
lookup_header="Foo Bar"
@@ -64,7 +58,6 @@ describe('<Lookup />', () => {
sortedColumnKey="name"
handleHttpError={() => {}}
/>
</I18nProvider>
).find('Lookup');
expect(spy).not.toHaveBeenCalled();
expect(wrapper.state('lookupSelectedItems')).toEqual(mockSelected);
@@ -81,8 +74,7 @@ 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>
const wrapper = mountWithContexts(
<_Lookup
id="search"
lookup_header="Foo Bar"
@@ -94,7 +86,6 @@ describe('<Lookup />', () => {
sortedColumnKey="name"
handleHttpError={() => {}}
/>
</I18nProvider>
);
setImmediate(() => {
const searchItem = wrapper.find('button[aria-label="Search"]');
@@ -108,8 +99,7 @@ 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>
const wrapper = mountWithContexts(
<_Lookup
id="search"
lookup_header="Foo Bar"
@@ -121,7 +111,6 @@ describe('<Lookup />', () => {
sortedColumnKey="name"
handleHttpError={() => {}}
/>
</I18nProvider>
);
const removeIcon = wrapper.find('button[aria-label="close"]').first();
removeIcon.simulate('click');
@@ -130,8 +119,7 @@ describe('<Lookup />', () => {
test('renders chips from prop value', () => {
mockData = [{ name: 'foo', id: 0 }, { name: 'bar', id: 1 }];
const wrapper = mount(
<I18nProvider>
const wrapper = mountWithContexts(
<Lookup
lookup_header="Foo Bar"
onLookupSave={() => { }}
@@ -140,9 +128,7 @@ describe('<Lookup />', () => {
getItems={() => { }}
columns={mockColumns}
sortedColumnKey="name"
handleHttpError={() => {}}
/>
</I18nProvider>
).find('Lookup');
const chip = wrapper.find('li.pf-c-chip');
expect(chip).toHaveLength(2);
@@ -150,8 +136,7 @@ describe('<Lookup />', () => {
test('toggleSelected successfully adds/removes row from lookupSelectedItems state', () => {
mockData = [];
const wrapper = mount(
<I18nProvider>
const wrapper = mountWithContexts(
<Lookup
lookup_header="Foo Bar"
onLookupSave={() => { }}
@@ -159,9 +144,7 @@ describe('<Lookup />', () => {
getItems={() => { }}
columns={mockColumns}
sortedColumnKey="name"
handleHttpError={() => {}}
/>
</I18nProvider>
).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>
const wrapper = mountWithContexts(
<Lookup
lookup_header="Foo Bar"
name="fooBar"
value={mockData}
onLookupSave={onLookupSaveFn}
getItems={() => { }}
handleHttpError={() => {}}
/>
</I18nProvider>
).find('Lookup');
wrapper.instance().toggleSelected({
id: 1,
@@ -210,8 +190,7 @@ describe('<Lookup />', () => {
test('onSort sets state and calls getData ', () => {
const spy = jest.spyOn(_Lookup.prototype, 'getData');
const wrapper = mount(
<I18nProvider>
const wrapper = mountWithContexts(
<_Lookup
lookup_header="Foo Bar"
onLookupSave={() => { }}
@@ -222,7 +201,6 @@ describe('<Lookup />', () => {
getItems={() => { }}
handleHttpError={() => {}}
/>
</I18nProvider>
).find('Lookup');
wrapper.instance().onSort('id', 'descending');
expect(wrapper.state('sortedColumnKey')).toEqual('id');
@@ -232,8 +210,7 @@ describe('<Lookup />', () => {
test('onSearch calls getData (through calling onSort)', () => {
const spy = jest.spyOn(_Lookup.prototype, 'getData');
const wrapper = mount(
<I18nProvider>
const wrapper = mountWithContexts(
<_Lookup
lookup_header="Foo Bar"
onLookupSave={() => { }}
@@ -244,7 +221,6 @@ describe('<Lookup />', () => {
getItems={() => { }}
handleHttpError={() => {}}
/>
</I18nProvider>
).find('Lookup');
wrapper.instance().onSearch();
expect(spy).toHaveBeenCalled();
@@ -252,8 +228,7 @@ describe('<Lookup />', () => {
test('onSetPage sets state and calls getData ', () => {
const spy = jest.spyOn(_Lookup.prototype, 'getData');
const wrapper = mount(
<I18nProvider>
const wrapper = mountWithContexts(
<_Lookup
lookup_header="Foo Bar"
onLookupSave={() => { }}
@@ -264,7 +239,6 @@ describe('<Lookup />', () => {
getItems={() => { }}
handleHttpError={() => {}}
/>
</I18nProvider>
).find('Lookup');
wrapper.instance().onSetPage(2, 10);
expect(wrapper.state('page')).toEqual(2);

View File

@@ -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">

View File

@@ -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,25 +14,19 @@ describe('<NotificationListItem />', () => {
});
test('initially renders succesfully', () => {
wrapper = mount(
<I18nProvider>
<MemoryRouter>
wrapper = mountWithContexts(
<NotificationListItem
itemId={9000}
toggleNotification={toggleNotification}
detailUrl="/foo"
notificationType="slack"
/>
</MemoryRouter>
</I18nProvider>
);
expect(wrapper.length).toBe(1);
});
test('handles success click when toggle is on', () => {
wrapper = mount(
<I18nProvider>
<MemoryRouter>
wrapper = mountWithContexts(
<NotificationListItem
itemId={9000}
successTurnedOn
@@ -42,17 +34,13 @@ describe('<NotificationListItem />', () => {
detailUrl="/foo"
notificationType="slack"
/>
</MemoryRouter>
</I18nProvider>
);
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>
wrapper = mountWithContexts(
<NotificationListItem
itemId={9000}
successTurnedOn={false}
@@ -60,17 +48,13 @@ describe('<NotificationListItem />', () => {
detailUrl="/foo"
notificationType="slack"
/>
</MemoryRouter>
</I18nProvider>
);
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>
wrapper = mountWithContexts(
<NotificationListItem
itemId={9000}
errorTurnedOn
@@ -78,17 +62,13 @@ describe('<NotificationListItem />', () => {
detailUrl="/foo"
notificationType="slack"
/>
</MemoryRouter>
</I18nProvider>
);
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>
wrapper = mountWithContexts(
<NotificationListItem
itemId={9000}
errorTurnedOn={false}
@@ -96,8 +76,6 @@ describe('<NotificationListItem />', () => {
detailUrl="/foo"
notificationType="slack"
/>
</MemoryRouter>
</I18nProvider>
);
wrapper.find('Switch').at(1).find('input').simulate('change');
expect(toggleNotification).toHaveBeenCalledWith(9000, false, 'error');

View File

@@ -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>
mountWithContexts(
<_NotifyAndRedirect
to="foo"
setRootDialogMessage={setRootDialogMessage}
location={{ pathname: 'foo' }}
/>
</I18nProvider>
</MemoryRouter>
);
expect(setRootDialogMessage).toHaveBeenCalled();
});

View File

@@ -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>
const wrapper = mountWithContexts(
<PageHeaderToolbar
onAboutClick={onAboutClick}
onLogoutClick={onLogoutClick}
/>
</I18nProvider>
);
expect(wrapper.find(pageHelpDropdownSelector)).toHaveLength(1);
@@ -26,15 +21,11 @@ describe('PageHeaderToolbar', () => {
});
test('dropdowns have expected items and callbacks', () => {
const wrapper = mount(
<MemoryRouter>
<I18nProvider>
const wrapper = mountWithContexts(
<PageHeaderToolbar
onAboutClick={onAboutClick}
onLogoutClick={onLogoutClick}
/>
</I18nProvider>
</MemoryRouter>
);
expect(wrapper.find('DropdownItem')).toHaveLength(0);
wrapper.find(pageHelpDropdownSelector).simulate('click');

View File

@@ -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 = mountWithContexts(
<Search
sortedColumnKey="name"
columns={columns}
onSearch={onSearch}
/>
</I18nProvider>
);
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>
const wrapper = mountWithContexts(
<Search
sortedColumnKey="name"
columns={columns}
onSearch={onSearch}
/>
</I18nProvider>
).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>
const wrapper = mountWithContexts(
<Search
sortedColumnKey="name"
columns={columns}
onSearch={onSearch}
/>
</I18nProvider>
).find('Search');
expect(wrapper.state('searchKey')).toEqual('name');
wrapper.instance().handleDropdownSelect({ target: { innerText: 'Description' } });

View File

@@ -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>
const wrapper = mountWithContexts(
<Sort
sortedColumnKey="name"
sortOrder="ascending"
columns={columns}
onSort={onSort}
/>
</I18nProvider>
).find('Sort');
wrapper.find(sortBtn).simulate('click');
@@ -47,15 +43,13 @@ describe('<Sort />', () => {
const onSort = jest.fn();
const wrapper = mount(
<I18nProvider>
const wrapper = mountWithContexts(
<Sort
sortedColumnKey="foo"
sortOrder="ascending"
columns={multipleColumns}
onSort={onSort}
/>
</I18nProvider>
).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>
const wrapper = mountWithContexts(
<Sort
sortedColumnKey="foo"
sortOrder="descending"
columns={multipleColumns}
onSort={onSort}
/>
</I18nProvider>
).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>
const wrapper = mountWithContexts(
<Sort
sortedColumnKey="foo"
sortOrder="ascending"
columns={multipleColumns}
onSort={onSort}
/>
</I18nProvider>
).find('Sort');
wrapper.instance().handleDropdownSelect({ target: { innerText: 'Bar' } });
@@ -124,15 +114,13 @@ describe('<Sort />', () => {
const onSort = jest.fn();
const wrapper = mount(
<I18nProvider>
const wrapper = mountWithContexts(
<Sort
sortedColumnKey="foo"
sortOrder="ascending"
columns={multipleColumns}
onSort={onSort}
/>
</I18nProvider>
).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 = mountWithContexts(
<Sort
sortedColumnKey="id"
sortOrder="descending"
columns={numericColumns}
onSort={onSort}
/>
</I18nProvider>
);
const downNumericIcon = sort.find(downNumericIconSelector);
expect(downNumericIcon.length).toBe(1);
sort = mount(
<I18nProvider>
sort = mountWithContexts(
<Sort
sortedColumnKey="id"
sortOrder="ascending"
columns={numericColumns}
onSort={onSort}
/>
</I18nProvider>
);
const upNumericIcon = sort.find(upNumericIconSelector);
expect(upNumericIcon.length).toBe(1);
sort = mount(
<I18nProvider>
sort = mountWithContexts(
<Sort
sortedColumnKey="name"
sortOrder="descending"
columns={alphaColumns}
onSort={onSort}
/>
</I18nProvider>
);
const downAlphaIcon = sort.find(downAlphaIconSelector);
expect(downAlphaIcon.length).toBe(1);
sort = mount(
<I18nProvider>
sort = mountWithContexts(
<Sort
sortedColumnKey="name"
sortOrder="ascending"
columns={alphaColumns}
onSort={onSort}
/>
</I18nProvider>
);
const upAlphaIcon = sort.find(upAlphaIconSelector);

View File

@@ -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>
logoWrapper = mountWithContexts(
<TowerLogo />
</I18nProvider>
</MemoryRouter>
);
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>
logoWrapper = mountWithContexts(
<TowerLogo />
</I18nProvider>
</MemoryRouter>
);
findChildren();
findChildren();