mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-02-28 04:36:45 +00:00
Moved common code to handle currently selected server to HOC
This commit is contained in:
52
test/servers/EditServer.test.js
Normal file
52
test/servers/EditServer.test.js
Normal file
@@ -0,0 +1,52 @@
|
||||
import React from 'react';
|
||||
import { mount } from 'enzyme';
|
||||
import { EditServer as editServerConstruct } from '../../src/servers/EditServer';
|
||||
import { ServerForm } from '../../src/servers/helpers/ServerForm';
|
||||
|
||||
describe('<EditServer />', () => {
|
||||
let wrapper;
|
||||
const ServerError = jest.fn();
|
||||
const editServerMock = jest.fn();
|
||||
const historyMock = { push: jest.fn() };
|
||||
const match = {
|
||||
params: { serverId: 'abc123' },
|
||||
};
|
||||
const selectedServer = {
|
||||
id: 'abc123',
|
||||
name: 'name',
|
||||
url: 'url',
|
||||
apiKey: 'apiKey',
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
const EditServer = editServerConstruct(ServerError);
|
||||
|
||||
wrapper = mount(
|
||||
<EditServer
|
||||
editServer={editServerMock}
|
||||
history={historyMock}
|
||||
match={match}
|
||||
selectedServer={selectedServer}
|
||||
selectServer={jest.fn()}
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.resetAllMocks();
|
||||
wrapper && 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(historyMock.push).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user