2020-08-29 21:20:45 +03:00
|
|
|
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
|
2020-03-15 15:43:12 +03:00
|
|
|
import { EditServer as editServerConstruct } from '../../src/servers/EditServer';
|
|
|
|
import { ServerForm } from '../../src/servers/helpers/ServerForm';
|
2020-08-29 21:20:45 +03:00
|
|
|
import { ReachableServer } from '../../src/servers/data';
|
2020-03-15 15:43:12 +03:00
|
|
|
|
|
|
|
describe('<EditServer />', () => {
|
2020-08-29 21:20:45 +03:00
|
|
|
let wrapper: ReactWrapper;
|
2020-03-15 15:43:12 +03:00
|
|
|
const ServerError = jest.fn();
|
|
|
|
const editServerMock = jest.fn();
|
2021-10-22 19:53:00 +03:00
|
|
|
const goBack = jest.fn();
|
|
|
|
const historyMock = Mock.of<History>({ goBack });
|
2020-08-29 21:20:45 +03:00
|
|
|
const match = Mock.of<match<{ serverId: string }>>({
|
2020-03-15 15:43:12 +03:00
|
|
|
params: { serverId: 'abc123' },
|
2020-08-29 21:20:45 +03:00
|
|
|
});
|
|
|
|
const selectedServer = Mock.of<ReachableServer>({
|
2020-03-15 15:43:12 +03:00
|
|
|
id: 'abc123',
|
|
|
|
name: 'name',
|
|
|
|
url: 'url',
|
|
|
|
apiKey: 'apiKey',
|
2020-08-29 21:20:45 +03:00
|
|
|
});
|
2020-03-15 15:43:12 +03:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
const EditServer = editServerConstruct(ServerError);
|
|
|
|
|
|
|
|
wrapper = mount(
|
|
|
|
<EditServer
|
|
|
|
editServer={editServerMock}
|
|
|
|
history={historyMock}
|
|
|
|
match={match}
|
2020-08-29 21:20:45 +03:00
|
|
|
location={Mock.all<Location>()}
|
2020-03-15 15:43:12 +03:00
|
|
|
selectedServer={selectedServer}
|
|
|
|
selectServer={jest.fn()}
|
2020-08-22 09:10:31 +03:00
|
|
|
/>,
|
2020-03-15 15:43:12 +03:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-08-29 21:20:45 +03:00
|
|
|
afterEach(jest.resetAllMocks);
|
|
|
|
afterEach(() => wrapper?.unmount());
|
2020-03-15 15:43:12 +03:00
|
|
|
|
|
|
|
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);
|
2021-10-22 19:53:00 +03:00
|
|
|
expect(goBack).toHaveBeenCalledTimes(1);
|
2020-03-15 15:43:12 +03:00
|
|
|
});
|
|
|
|
});
|