shlink-web-client/test/servers/DeleteServerModal.test.tsx

64 lines
1.9 KiB
TypeScript
Raw Normal View History

import { shallow, ShallowWrapper } from 'enzyme';
2018-08-24 13:36:14 +03:00
import { Modal, ModalBody, ModalFooter, ModalHeader } from 'reactstrap';
import { History } from 'history';
import { Mock } from 'ts-mockery';
2018-12-18 00:32:51 +03:00
import DeleteServerModal from '../../src/servers/DeleteServerModal';
import { ServerWithId } from '../../src/servers/data';
2018-08-24 13:36:14 +03:00
describe('<DeleteServerModal />', () => {
let wrapper: ShallowWrapper;
const deleteServerMock = jest.fn();
const push = jest.fn();
const toggleMock = jest.fn();
2018-08-24 13:36:14 +03:00
const serverName = 'the_server_name';
beforeEach(() => {
wrapper = shallow(
2018-12-18 00:32:51 +03:00
<DeleteServerModal
server={Mock.of<ServerWithId>({ name: serverName })}
2018-08-24 13:36:14 +03:00
toggle={toggleMock}
isOpen={true}
deleteServer={deleteServerMock}
history={Mock.of<History>({ push })}
2020-08-22 09:10:31 +03:00
/>,
2018-08-24 13:36:14 +03:00
);
});
afterEach(() => wrapper.unmount());
afterEach(jest.clearAllMocks);
2018-08-24 13:36:14 +03:00
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);
2018-08-24 13:36:14 +03:00
expect(modalBody.find('p').first().text()).toEqual(
2020-08-22 09:10:31 +03:00
`Are you sure you want to remove ${serverName}?`,
2018-08-24 13:36:14 +03:00
);
});
it('toggles when clicking cancel button', () => {
const cancelBtn = wrapper.find('button').first();
2018-08-24 13:36:14 +03:00
cancelBtn.simulate('click');
expect(toggleMock).toHaveBeenCalledTimes(1);
expect(deleteServerMock).not.toHaveBeenCalled();
expect(push).not.toHaveBeenCalled();
2018-08-24 13:36:14 +03:00
});
it('deletes server when clicking accept button', () => {
const acceptBtn = wrapper.find('button').last();
2018-08-24 13:36:14 +03:00
acceptBtn.simulate('click');
expect(toggleMock).toHaveBeenCalledTimes(1);
expect(deleteServerMock).toHaveBeenCalledTimes(1);
expect(push).toHaveBeenCalledTimes(1);
2018-08-24 13:36:14 +03:00
});
});