2020-08-29 21:20:45 +03:00
|
|
|
import { values } from 'ramda';
|
|
|
|
import { Mock } from 'ts-mockery';
|
|
|
|
import React, { FC } from 'react';
|
|
|
|
import { shallow, ShallowWrapper } from 'enzyme';
|
2018-08-20 17:44:46 +03:00
|
|
|
import { DropdownItem, DropdownToggle } from 'reactstrap';
|
2020-08-29 21:20:45 +03:00
|
|
|
import serversDropdownCreator, { ServersDropdownProps } from '../../src/servers/ServersDropdown';
|
|
|
|
import { ServerWithId } from '../../src/servers/data';
|
|
|
|
import ServersExporter from '../../src/servers/services/ServersExporter';
|
2018-06-14 20:42:42 +03:00
|
|
|
|
2018-07-22 23:49:51 +03:00
|
|
|
describe('<ServersDropdown />', () => {
|
2020-08-29 21:20:45 +03:00
|
|
|
let wrapped: ShallowWrapper;
|
|
|
|
let ServersDropdown: FC<ServersDropdownProps>;
|
2018-08-26 00:39:27 +03:00
|
|
|
const servers = {
|
2020-08-29 21:20:45 +03:00
|
|
|
'1a': Mock.of<ServerWithId>({ name: 'foo', id: '1a' }),
|
|
|
|
'2b': Mock.of<ServerWithId>({ name: 'bar', id: '2b' }),
|
|
|
|
'3c': Mock.of<ServerWithId>({ name: 'baz', id: '3c' }),
|
2019-10-05 20:51:50 +03:00
|
|
|
};
|
2018-06-14 20:42:42 +03:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2020-08-29 21:20:45 +03:00
|
|
|
ServersDropdown = serversDropdownCreator(Mock.of<ServersExporter>());
|
|
|
|
wrapped = shallow(<ServersDropdown servers={servers} selectedServer={null} />);
|
2018-06-14 20:42:42 +03:00
|
|
|
});
|
2018-07-22 23:49:51 +03:00
|
|
|
afterEach(() => wrapped.unmount());
|
2018-06-14 20:42:42 +03:00
|
|
|
|
2019-10-05 20:51:50 +03:00
|
|
|
it('contains the list of servers, the divider and the export button', () =>
|
2020-04-27 11:49:55 +03:00
|
|
|
expect(wrapped.find(DropdownItem)).toHaveLength(values(servers).length + 2));
|
2018-08-20 17:53:48 +03:00
|
|
|
|
|
|
|
it('contains a toggle with proper title', () =>
|
2018-08-26 00:39:27 +03:00
|
|
|
expect(wrapped.find(DropdownToggle)).toHaveLength(1));
|
2018-08-20 17:53:48 +03:00
|
|
|
|
|
|
|
it('contains a button to export servers', () => {
|
|
|
|
const items = wrapped.find(DropdownItem);
|
2018-08-26 00:39:27 +03:00
|
|
|
|
2018-08-20 17:53:48 +03:00
|
|
|
expect(items.filter('[divider]')).toHaveLength(1);
|
|
|
|
expect(items.filter('.servers-dropdown__export-item')).toHaveLength(1);
|
2018-06-14 20:42:42 +03:00
|
|
|
});
|
|
|
|
|
2019-04-28 13:40:50 +03:00
|
|
|
it('shows a message when no servers exist yet', () => {
|
2019-10-05 20:51:50 +03:00
|
|
|
wrapped = shallow(
|
2020-08-29 21:20:45 +03:00
|
|
|
<ServersDropdown servers={{}} selectedServer={null} />,
|
2019-10-05 20:51:50 +03:00
|
|
|
);
|
2018-08-20 17:53:48 +03:00
|
|
|
const item = wrapped.find(DropdownItem);
|
|
|
|
|
|
|
|
expect(item).toHaveLength(1);
|
|
|
|
expect(item.prop('disabled')).toEqual(true);
|
|
|
|
expect(item.find('i').text()).toEqual('Add a server first...');
|
2018-06-14 20:42:42 +03:00
|
|
|
});
|
|
|
|
});
|