mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-02-28 20:56:42 +00:00
Finished migrating servers module to TS
This commit is contained in:
@@ -1,22 +1,27 @@
|
||||
import React from 'react';
|
||||
import { mount } from 'enzyme';
|
||||
import { mount, ReactWrapper } from 'enzyme';
|
||||
import { Mock } from 'ts-mockery';
|
||||
import { History, Location } from 'history';
|
||||
import { match } from 'react-router'; // eslint-disable-line @typescript-eslint/no-unused-vars
|
||||
import { EditServer as editServerConstruct } from '../../src/servers/EditServer';
|
||||
import { ServerForm } from '../../src/servers/helpers/ServerForm';
|
||||
import { ReachableServer } from '../../src/servers/data';
|
||||
|
||||
describe('<EditServer />', () => {
|
||||
let wrapper;
|
||||
let wrapper: ReactWrapper;
|
||||
const ServerError = jest.fn();
|
||||
const editServerMock = jest.fn();
|
||||
const historyMock = { push: jest.fn() };
|
||||
const match = {
|
||||
const push = jest.fn();
|
||||
const historyMock = Mock.of<History>({ push });
|
||||
const match = Mock.of<match<{ serverId: string }>>({
|
||||
params: { serverId: 'abc123' },
|
||||
};
|
||||
const selectedServer = {
|
||||
});
|
||||
const selectedServer = Mock.of<ReachableServer>({
|
||||
id: 'abc123',
|
||||
name: 'name',
|
||||
url: 'url',
|
||||
apiKey: 'apiKey',
|
||||
};
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
const EditServer = editServerConstruct(ServerError);
|
||||
@@ -26,16 +31,15 @@ describe('<EditServer />', () => {
|
||||
editServer={editServerMock}
|
||||
history={historyMock}
|
||||
match={match}
|
||||
location={Mock.all<Location>()}
|
||||
selectedServer={selectedServer}
|
||||
selectServer={jest.fn()}
|
||||
/>,
|
||||
);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.resetAllMocks();
|
||||
wrapper && wrapper.unmount();
|
||||
});
|
||||
afterEach(jest.resetAllMocks);
|
||||
afterEach(() => wrapper?.unmount());
|
||||
|
||||
it('renders components', () => {
|
||||
expect(wrapper.find(ServerForm)).toHaveLength(1);
|
||||
@@ -47,6 +51,6 @@ describe('<EditServer />', () => {
|
||||
form.simulate('submit', {});
|
||||
|
||||
expect(editServerMock).toHaveBeenCalledTimes(1);
|
||||
expect(historyMock.push).toHaveBeenCalledTimes(1);
|
||||
expect(push).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
@@ -1,24 +1,24 @@
|
||||
import { identity, values } from 'ramda';
|
||||
import React from 'react';
|
||||
import { shallow } from 'enzyme';
|
||||
import { values } from 'ramda';
|
||||
import { Mock } from 'ts-mockery';
|
||||
import React, { FC } from 'react';
|
||||
import { shallow, ShallowWrapper } from 'enzyme';
|
||||
import { DropdownItem, DropdownToggle } from 'reactstrap';
|
||||
import serversDropdownCreator from '../../src/servers/ServersDropdown';
|
||||
import serversDropdownCreator, { ServersDropdownProps } from '../../src/servers/ServersDropdown';
|
||||
import { ServerWithId } from '../../src/servers/data';
|
||||
import ServersExporter from '../../src/servers/services/ServersExporter';
|
||||
|
||||
describe('<ServersDropdown />', () => {
|
||||
let wrapped;
|
||||
let ServersDropdown;
|
||||
let wrapped: ShallowWrapper;
|
||||
let ServersDropdown: FC<ServersDropdownProps>;
|
||||
const servers = {
|
||||
'1a': { name: 'foo', id: 1 },
|
||||
'2b': { name: 'bar', id: 2 },
|
||||
'3c': { name: 'baz', id: 3 },
|
||||
};
|
||||
const history = {
|
||||
push: jest.fn(),
|
||||
'1a': Mock.of<ServerWithId>({ name: 'foo', id: '1a' }),
|
||||
'2b': Mock.of<ServerWithId>({ name: 'bar', id: '2b' }),
|
||||
'3c': Mock.of<ServerWithId>({ name: 'baz', id: '3c' }),
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
ServersDropdown = serversDropdownCreator({});
|
||||
wrapped = shallow(<ServersDropdown servers={servers} listServers={identity} history={history} />);
|
||||
ServersDropdown = serversDropdownCreator(Mock.of<ServersExporter>());
|
||||
wrapped = shallow(<ServersDropdown servers={servers} selectedServer={null} />);
|
||||
});
|
||||
afterEach(() => wrapped.unmount());
|
||||
|
||||
@@ -37,7 +37,7 @@ describe('<ServersDropdown />', () => {
|
||||
|
||||
it('shows a message when no servers exist yet', () => {
|
||||
wrapped = shallow(
|
||||
<ServersDropdown servers={{}} listServers={identity} history={history} />,
|
||||
<ServersDropdown servers={{}} selectedServer={null} />,
|
||||
);
|
||||
const item = wrapped.find(DropdownItem);
|
||||
|
||||
Reference in New Issue
Block a user