mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-23 09:30:31 +03:00
Created DeleteServerModal test
This commit is contained in:
parent
7cd9caee77
commit
badc8a7324
2 changed files with 69 additions and 5 deletions
|
@ -7,6 +7,12 @@ import { compose } from 'redux';
|
||||||
import { deleteServer } from './reducers/server';
|
import { deleteServer } from './reducers/server';
|
||||||
import { serverType } from './prop-types';
|
import { serverType } from './prop-types';
|
||||||
|
|
||||||
|
const propTypes = {
|
||||||
|
toggle: PropTypes.func.isRequired,
|
||||||
|
isOpen: PropTypes.bool.isRequired,
|
||||||
|
server: serverType,
|
||||||
|
};
|
||||||
|
|
||||||
export const DeleteServerModal = ({ server, toggle, isOpen, deleteServer, history }) => {
|
export const DeleteServerModal = ({ server, toggle, isOpen, deleteServer, history }) => {
|
||||||
const closeModal = () => {
|
const closeModal = () => {
|
||||||
deleteServer(server);
|
deleteServer(server);
|
||||||
|
@ -32,11 +38,7 @@ export const DeleteServerModal = ({ server, toggle, isOpen, deleteServer, histor
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
DeleteServerModal.propTypes = {
|
DeleteServerModal.propTypes = propTypes;
|
||||||
toggle: PropTypes.func.isRequired,
|
|
||||||
isOpen: PropTypes.bool.isRequired,
|
|
||||||
server: serverType,
|
|
||||||
};
|
|
||||||
|
|
||||||
export default compose(
|
export default compose(
|
||||||
withRouter,
|
withRouter,
|
||||||
|
|
62
test/servers/DeleteServerModal.test.js
Normal file
62
test/servers/DeleteServerModal.test.js
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
import React from 'react';
|
||||||
|
import { shallow } from 'enzyme';
|
||||||
|
import { DeleteServerModal } from '../../src/servers/DeleteServerModal';
|
||||||
|
import sinon from 'sinon';
|
||||||
|
import { Modal, ModalBody, ModalFooter, ModalHeader } from 'reactstrap';
|
||||||
|
|
||||||
|
describe('<DeleteServerModal />', () => {
|
||||||
|
let wrapper;
|
||||||
|
const deleteServerMock = sinon.fake();
|
||||||
|
const historyMock = { push: sinon.fake() };
|
||||||
|
const toggleMock = sinon.fake();
|
||||||
|
const serverName = 'the_server_name';
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
toggleMock.resetHistory();
|
||||||
|
deleteServerMock.resetHistory();
|
||||||
|
historyMock.push.resetHistory();
|
||||||
|
|
||||||
|
wrapper = shallow(
|
||||||
|
<DeleteServerModal
|
||||||
|
server={{ name: serverName }}
|
||||||
|
toggle={toggleMock}
|
||||||
|
isOpen={true}
|
||||||
|
deleteServer={deleteServerMock}
|
||||||
|
history={historyMock}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
afterEach(() => wrapper.unmount());
|
||||||
|
|
||||||
|
it('renders a modal window', () => {
|
||||||
|
expect(wrapper.find(Modal)).toHaveLength(1);
|
||||||
|
expect(wrapper.find(ModalHeader)).toHaveLength(1);
|
||||||
|
expect(wrapper.find(ModalBody)).toHaveLength(1);
|
||||||
|
expect(wrapper.find(ModalFooter)).toHaveLength(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('displays the name of the server as part of the content', () => {
|
||||||
|
const modalBody = wrapper.find(ModalBody);
|
||||||
|
expect(modalBody.find('p').first().text()).toEqual(
|
||||||
|
`Are you sure you want to delete server ${serverName}?`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('toggles when clicking cancel button', () => {
|
||||||
|
const cancelBtn = wrapper.find('button').first();
|
||||||
|
cancelBtn.simulate('click');
|
||||||
|
|
||||||
|
expect(toggleMock.callCount).toEqual(1);
|
||||||
|
expect(deleteServerMock.callCount).toEqual(0);
|
||||||
|
expect(historyMock.push.callCount).toEqual(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('deletes server when clicking accept button', () => {
|
||||||
|
const acceptBtn = wrapper.find('button').last();
|
||||||
|
acceptBtn.simulate('click');
|
||||||
|
|
||||||
|
expect(toggleMock.callCount).toEqual(1);
|
||||||
|
expect(deleteServerMock.callCount).toEqual(1);
|
||||||
|
expect(historyMock.push.callCount).toEqual(1);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in a new issue