mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-03-17 21:13:48 +00:00
Improved welcome screen
This commit is contained in:
@@ -5,31 +5,58 @@ import ServersListGroup from '../../src/servers/ServersListGroup';
|
||||
import { ServerWithId } from '../../src/servers/data';
|
||||
|
||||
describe('<ServersListGroup />', () => {
|
||||
const servers = [
|
||||
Mock.of<ServerWithId>({ name: 'foo', id: '123' }),
|
||||
Mock.of<ServerWithId>({ name: 'bar', id: '456' }),
|
||||
];
|
||||
let wrapped: ShallowWrapper;
|
||||
const createComponent = (servers: ServerWithId[]) => {
|
||||
wrapped = shallow(<ServersListGroup servers={servers}>The list of servers</ServersListGroup>);
|
||||
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());
|
||||
|
||||
it('Renders title', () => {
|
||||
const wrapped = createComponent([]);
|
||||
it('renders title', () => {
|
||||
const wrapped = createComponent({});
|
||||
const title = wrapped.find('h5');
|
||||
|
||||
expect(title).toHaveLength(1);
|
||||
expect(title.text()).toEqual('The list of servers');
|
||||
});
|
||||
|
||||
it('shows servers list', () => {
|
||||
const servers = [
|
||||
Mock.of<ServerWithId>({ name: 'foo', id: '123' }),
|
||||
Mock.of<ServerWithId>({ name: 'bar', id: '456' }),
|
||||
];
|
||||
const wrapped = createComponent(servers);
|
||||
it('does not render title when children is not provided', () => {
|
||||
const wrapped = createComponent({ withChildren: false });
|
||||
const title = wrapped.find('h5');
|
||||
|
||||
expect(wrapped.find(ListGroup)).toHaveLength(1);
|
||||
expect(title).toHaveLength(0);
|
||||
});
|
||||
|
||||
it.each([
|
||||
[ servers ],
|
||||
[[]],
|
||||
])('shows servers list', (servers) => {
|
||||
const wrapped = createComponent({ servers });
|
||||
|
||||
expect(wrapped.find(ListGroup)).toHaveLength(servers.length ? 1 : 0);
|
||||
expect(wrapped.find('ServerListItem')).toHaveLength(servers.length);
|
||||
});
|
||||
|
||||
it.each([
|
||||
[ true, 'servers-list__list-group servers-list__list-group--embedded' ],
|
||||
[ false, 'servers-list__list-group' ],
|
||||
[ undefined, 'servers-list__list-group' ],
|
||||
])('renders proper classes for embedded', (embedded, expectedClasses) => {
|
||||
const wrapped = createComponent({ servers, embedded });
|
||||
const listGroup = wrapped.find(ListGroup);
|
||||
|
||||
expect(listGroup.prop('className')).toEqual(expectedClasses);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user