2018-08-25 23:39:27 +02:00
|
|
|
import { identity, values } from 'ramda';
|
2018-06-14 19:42:42 +02:00
|
|
|
import React from 'react';
|
|
|
|
import { shallow } from 'enzyme';
|
2018-08-20 16:44:46 +02:00
|
|
|
import { DropdownItem, DropdownToggle } from 'reactstrap';
|
2018-12-17 22:32:51 +01:00
|
|
|
import serversDropdownCreator from '../../src/servers/ServersDropdown';
|
2018-06-14 19:42:42 +02:00
|
|
|
|
2018-07-22 22:49:51 +02:00
|
|
|
describe('<ServersDropdown />', () => {
|
2018-06-14 19:42:42 +02:00
|
|
|
let wrapped;
|
2018-12-17 22:32:51 +01:00
|
|
|
let ServersDropdown;
|
2018-08-25 23:39:27 +02:00
|
|
|
const servers = {
|
2019-04-28 12:40:50 +02:00
|
|
|
list: {
|
|
|
|
'1a': { name: 'foo', id: 1 },
|
|
|
|
'2b': { name: 'bar', id: 2 },
|
|
|
|
'3c': { name: 'baz', id: 3 },
|
|
|
|
},
|
|
|
|
loading: false,
|
2018-08-25 23:39:27 +02:00
|
|
|
};
|
2019-10-05 19:51:50 +02:00
|
|
|
const history = {
|
|
|
|
push: jest.fn(),
|
|
|
|
};
|
2018-06-14 19:42:42 +02:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2018-12-17 22:32:51 +01:00
|
|
|
ServersDropdown = serversDropdownCreator({});
|
2019-10-05 19:51:50 +02:00
|
|
|
wrapped = shallow(<ServersDropdown servers={servers} listServers={identity} history={history} />);
|
2018-06-14 19:42:42 +02:00
|
|
|
});
|
2018-07-22 22:49:51 +02:00
|
|
|
afterEach(() => wrapped.unmount());
|
2018-06-14 19:42:42 +02:00
|
|
|
|
2019-10-05 19:51:50 +02:00
|
|
|
it('contains the list of servers, the divider and the export button', () =>
|
|
|
|
expect(wrapped.find(DropdownItem)).toHaveLength(values(servers.list).length + 2));
|
2018-08-20 16:53:48 +02:00
|
|
|
|
|
|
|
it('contains a toggle with proper title', () =>
|
2018-08-25 23:39:27 +02:00
|
|
|
expect(wrapped.find(DropdownToggle)).toHaveLength(1));
|
2018-08-20 16:53:48 +02:00
|
|
|
|
|
|
|
it('contains a button to export servers', () => {
|
|
|
|
const items = wrapped.find(DropdownItem);
|
2018-08-25 23:39:27 +02:00
|
|
|
|
2018-08-20 16:53:48 +02:00
|
|
|
expect(items.filter('[divider]')).toHaveLength(1);
|
|
|
|
expect(items.filter('.servers-dropdown__export-item')).toHaveLength(1);
|
2018-06-14 19:42:42 +02:00
|
|
|
});
|
|
|
|
|
2019-04-28 12:40:50 +02:00
|
|
|
it('shows a message when no servers exist yet', () => {
|
2019-10-05 19:51:50 +02:00
|
|
|
wrapped = shallow(
|
|
|
|
<ServersDropdown servers={{ loading: false, list: {} }} listServers={identity} history={history} />
|
|
|
|
);
|
2018-08-20 16:53:48 +02: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 19:42:42 +02:00
|
|
|
});
|
2019-04-28 12:40:50 +02:00
|
|
|
|
|
|
|
it('shows a message when loading', () => {
|
2019-10-05 19:51:50 +02:00
|
|
|
wrapped = shallow(
|
|
|
|
<ServersDropdown servers={{ loading: true, list: {} }} listServers={identity} history={history} />
|
|
|
|
);
|
2019-04-28 12:40:50 +02:00
|
|
|
const item = wrapped.find(DropdownItem);
|
|
|
|
|
|
|
|
expect(item).toHaveLength(1);
|
|
|
|
expect(item.prop('disabled')).toEqual(true);
|
|
|
|
expect(item.find('i').text()).toEqual('Trying to load servers...');
|
|
|
|
});
|
2018-06-14 19:42:42 +02:00
|
|
|
});
|