mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-04-22 22:46:19 +00:00
Finished migrating servers module to TS
This commit is contained in:
56
test/servers/EditServer.test.tsx
Normal file
56
test/servers/EditServer.test.tsx
Normal file
@@ -0,0 +1,56 @@
|
||||
import React from 'react';
|
||||
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: ReactWrapper;
|
||||
const ServerError = jest.fn();
|
||||
const editServerMock = jest.fn();
|
||||
const push = jest.fn();
|
||||
const historyMock = Mock.of<History>({ push });
|
||||
const match = Mock.of<match<{ serverId: string }>>({
|
||||
params: { serverId: 'abc123' },
|
||||
});
|
||||
const selectedServer = Mock.of<ReachableServer>({
|
||||
id: 'abc123',
|
||||
name: 'name',
|
||||
url: 'url',
|
||||
apiKey: 'apiKey',
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
const EditServer = editServerConstruct(ServerError);
|
||||
|
||||
wrapper = mount(
|
||||
<EditServer
|
||||
editServer={editServerMock}
|
||||
history={historyMock}
|
||||
match={match}
|
||||
location={Mock.all<Location>()}
|
||||
selectedServer={selectedServer}
|
||||
selectServer={jest.fn()}
|
||||
/>,
|
||||
);
|
||||
});
|
||||
|
||||
afterEach(jest.resetAllMocks);
|
||||
afterEach(() => wrapper?.unmount());
|
||||
|
||||
it('renders components', () => {
|
||||
expect(wrapper.find(ServerForm)).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('edits server and redirects to it when form is submitted', () => {
|
||||
const form = wrapper.find(ServerForm);
|
||||
|
||||
form.simulate('submit', {});
|
||||
|
||||
expect(editServerMock).toHaveBeenCalledTimes(1);
|
||||
expect(push).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user