Fixed tests

This commit is contained in:
Alejandro Celaya 2022-02-14 20:04:38 +01:00
parent f24c8052a9
commit ae9e5a0566
3 changed files with 17 additions and 4 deletions

View file

@ -54,7 +54,7 @@ describe('<App />', () => {
const routes = wrapper.find(Route); const routes = wrapper.find(Route);
const expectedPaths = [ const expectedPaths = [
undefined, undefined,
'/settings', '/settings/*',
'/manage-servers', '/manage-servers',
'/server/create', '/server/create',
'/server/:serverId/edit', '/server/:serverId/edit',

View file

@ -35,6 +35,8 @@ describe('<MainHeader />', () => {
[ '/foo', false ], [ '/foo', false ],
[ '/bar', false ], [ '/bar', false ],
[ '/settings', true ], [ '/settings', true ],
[ '/settings/foo', true ],
[ '/settings/bar', true ],
])('sets link to settings as active only when current path is settings', (currentPath, isActive) => { ])('sets link to settings as active only when current path is settings', (currentPath, isActive) => {
const wrapper = createWrapper(currentPath); const wrapper = createWrapper(currentPath);
const settingsLink = wrapper.find(NavLink); const settingsLink = wrapper.find(NavLink);

View file

@ -1,6 +1,8 @@
import { shallow } from 'enzyme'; import { shallow } from 'enzyme';
import { Route } from 'react-router-dom';
import createSettings from '../../src/settings/Settings'; import createSettings from '../../src/settings/Settings';
import { NoMenuLayout } from '../../src/common/NoMenuLayout'; import { NoMenuLayout } from '../../src/common/NoMenuLayout';
import { NavPillItem } from '../../src/utils/NavPills';
describe('<Settings />', () => { describe('<Settings />', () => {
const Component = () => null; const Component = () => null;
@ -9,10 +11,19 @@ describe('<Settings />', () => {
it('renders a no-menu layout with the expected settings sections', () => { it('renders a no-menu layout with the expected settings sections', () => {
const wrapper = shallow(<Settings />); const wrapper = shallow(<Settings />);
const layout = wrapper.find(NoMenuLayout); const layout = wrapper.find(NoMenuLayout);
const sections = wrapper.find('SettingsSections'); const sections = wrapper.find(Route);
expect(layout).toHaveLength(1); expect(layout).toHaveLength(1);
expect(sections).toHaveLength(1); expect(sections).toHaveLength(4);
expect((sections.prop('items') as any[]).flat()).toHaveLength(6); });
it('renders expected menu', () => {
const wrapper = shallow(<Settings />);
const items = wrapper.find(NavPillItem);
expect(items).toHaveLength(3);
expect(items.first().prop('to')).toEqual('app');
expect(items.at(1).prop('to')).toEqual('short-urls');
expect(items.last().prop('to')).toEqual('others');
}); });
}); });