shlink-web-client/test/servers/ServersListGroup.test.tsx

63 lines
2 KiB
TypeScript
Raw Normal View History

import { shallow, ShallowWrapper } from 'enzyme';
import { ListGroup } from 'reactstrap';
import { Mock } from 'ts-mockery';
2022-05-28 11:47:39 +03:00
import { ServersListGroup } from '../../src/servers/ServersListGroup';
import { ServerWithId } from '../../src/servers/data';
describe('<ServersListGroup />', () => {
2020-12-20 14:17:12 +03:00
const servers = [
Mock.of<ServerWithId>({ name: 'foo', id: '123' }),
Mock.of<ServerWithId>({ name: 'bar', id: '456' }),
];
let wrapped: ShallowWrapper;
2020-12-20 14:17:12 +03:00
const createComponent = (params: { servers?: ServerWithId[]; withChildren?: boolean; embedded?: boolean }) => {
const { servers = [], withChildren = true, embedded } = params;
wrapped = shallow(
<ServersListGroup servers={servers} embedded={embedded}>
{withChildren ? 'The list of servers' : undefined}
</ServersListGroup>,
);
return wrapped;
};
afterEach(() => wrapped?.unmount());
2020-12-20 14:17:12 +03:00
it('renders title', () => {
const wrapped = createComponent({});
const title = wrapped.find('h5');
expect(title).toHaveLength(1);
expect(title.text()).toEqual('The list of servers');
});
2020-12-20 14:17:12 +03:00
it('does not render title when children is not provided', () => {
const wrapped = createComponent({ withChildren: false });
const title = wrapped.find('h5');
expect(title).toHaveLength(0);
});
it.each([
2022-03-26 14:17:42 +03:00
[servers],
2020-12-20 14:17:12 +03:00
[[]],
])('shows servers list', (servers) => {
const wrapped = createComponent({ servers });
2020-12-20 14:17:12 +03:00
expect(wrapped.find(ListGroup)).toHaveLength(servers.length ? 1 : 0);
expect(wrapped.find('ServerListItem')).toHaveLength(servers.length);
});
2020-12-20 14:17:12 +03:00
it.each([
2022-03-26 14:17:42 +03:00
[true, 'servers-list__list-group servers-list__list-group--embedded'],
[false, 'servers-list__list-group'],
[undefined, 'servers-list__list-group'],
2020-12-20 14:17:12 +03:00
])('renders proper classes for embedded', (embedded, expectedClasses) => {
const wrapped = createComponent({ servers, embedded });
const listGroup = wrapped.find(ListGroup);
expect(listGroup.prop('className')).toEqual(expectedClasses);
});
});