2018-08-26 00:39:27 +03:00
|
|
|
import { identity, values } from 'ramda';
|
2018-06-14 20:42:42 +03:00
|
|
|
import React from 'react';
|
|
|
|
import { shallow } from 'enzyme';
|
2018-08-20 17:44:46 +03:00
|
|
|
import { DropdownItem, DropdownToggle } from 'reactstrap';
|
2018-12-18 00:32:51 +03:00
|
|
|
import serversDropdownCreator from '../../src/servers/ServersDropdown';
|
2018-06-14 20:42:42 +03:00
|
|
|
|
2018-07-22 23:49:51 +03:00
|
|
|
describe('<ServersDropdown />', () => {
|
2018-06-14 20:42:42 +03:00
|
|
|
let wrapped;
|
2018-12-18 00:32:51 +03:00
|
|
|
let ServersDropdown;
|
2018-08-26 00:39:27 +03:00
|
|
|
const servers = {
|
2019-04-28 13:40:50 +03:00
|
|
|
list: {
|
|
|
|
'1a': { name: 'foo', id: 1 },
|
|
|
|
'2b': { name: 'bar', id: 2 },
|
|
|
|
'3c': { name: 'baz', id: 3 },
|
|
|
|
},
|
|
|
|
loading: false,
|
2018-08-26 00:39:27 +03:00
|
|
|
};
|
2018-06-14 20:42:42 +03:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2018-12-18 00:32:51 +03:00
|
|
|
ServersDropdown = serversDropdownCreator({});
|
2018-12-18 00:18:47 +03:00
|
|
|
wrapped = shallow(<ServersDropdown servers={servers} listServers={identity} />);
|
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
|
|
|
|
2018-08-20 17:53:48 +03:00
|
|
|
it('contains the list of servers', () =>
|
2019-04-28 13:40:50 +03:00
|
|
|
expect(wrapped.find(DropdownItem).filter('[to]')).toHaveLength(values(servers.list).length));
|
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', () => {
|
|
|
|
wrapped = shallow(<ServersDropdown servers={{ loading: false, list: {} }} listServers={identity} />);
|
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
|
|
|
});
|
2019-04-28 13:40:50 +03:00
|
|
|
|
|
|
|
it('shows a message when loading', () => {
|
|
|
|
wrapped = shallow(<ServersDropdown servers={{ loading: true, list: {} }} listServers={identity} />);
|
|
|
|
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 20:42:42 +03:00
|
|
|
});
|