shlink-web-client/test/servers/ServersDropdown.test.js

49 lines
1.6 KiB
JavaScript
Raw Normal View History

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;
const servers = {
2020-04-27 11:49:55 +03:00
'1a': { name: 'foo', id: 1 },
'2b': { name: 'bar', id: 2 },
'3c': { name: 'baz', id: 3 },
};
const history = {
push: jest.fn(),
};
2018-06-14 20:42:42 +03:00
beforeEach(() => {
2018-12-18 00:32:51 +03:00
ServersDropdown = serversDropdownCreator({});
wrapped = shallow(<ServersDropdown servers={servers} listServers={identity} history={history} />);
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
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', () =>
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-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(
2020-08-22 09:10:31 +03:00
<ServersDropdown servers={{}} listServers={identity} history={history} />,
);
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
});
});