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

39 lines
1.3 KiB
JavaScript
Raw Normal View History

2018-07-22 23:49:51 +03:00
import { identity } from 'ramda';
2018-06-14 20:42:42 +03:00
import React from 'react';
import { ServersDropdown } from '../../src/servers/ServersDropdown';
import { shallow } from 'enzyme';
2018-08-20 17:44:46 +03:00
import { DropdownItem, DropdownToggle } from 'reactstrap';
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-07-22 23:49:51 +03:00
const servers = [{ name: 'foo', id: 1 }, { name: 'bar', id: 2 }, { name: 'baz', id: 3 }];
2018-06-14 20:42:42 +03:00
beforeEach(() => {
2018-07-22 23:49:51 +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', () =>
expect(wrapped.find(DropdownItem).filter('[to]')).toHaveLength(servers.length)
);
it('contains a toggle with proper title', () =>
expect(wrapped.find(DropdownToggle)).toHaveLength(1)
);
it('contains a button to export servers', () => {
const items = wrapped.find(DropdownItem);
expect(items.filter('[divider]')).toHaveLength(1);
expect(items.filter('.servers-dropdown__export-item')).toHaveLength(1);
2018-06-14 20:42:42 +03:00
});
2018-08-20 17:53:48 +03:00
it('contains a message when no servers exist yet', () => {
wrapped = shallow(<ServersDropdown servers={[]} listServers={identity} />);
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
});
});