Created PreviewModal test

This commit is contained in:
Alejandro Celaya 2018-11-01 12:34:18 +01:00
parent 30192cb349
commit 79a16a2c2c
2 changed files with 32 additions and 2 deletions

View file

@ -10,7 +10,7 @@ const propTypes = {
isOpen: PropTypes.bool, isOpen: PropTypes.bool,
}; };
export default function PreviewModal({ url, toggle, isOpen }) { const PreviewModal = ({ url, toggle, isOpen }) => {
return ( return (
<Modal isOpen={isOpen} toggle={toggle} size="lg"> <Modal isOpen={isOpen} toggle={toggle} size="lg">
<ModalHeader toggle={toggle}> <ModalHeader toggle={toggle}>
@ -24,6 +24,8 @@ export default function PreviewModal({ url, toggle, isOpen }) {
</ModalBody> </ModalBody>
</Modal> </Modal>
); );
} };
PreviewModal.propTypes = propTypes; PreviewModal.propTypes = propTypes;
export default PreviewModal;

View file

@ -0,0 +1,28 @@
import React from 'react';
import { shallow } from 'enzyme';
import PreviewModal from '../../../src/short-urls/helpers/PreviewModal';
import ExternalLink from '../../../src/utils/ExternalLink';
describe('<PreviewModal />', () => {
let wrapper;
const url = 'https://doma.in/abc123';
beforeEach(() => {
wrapper = shallow(<PreviewModal url={url} />);
});
afterEach(() => wrapper.unmount());
it('shows an external link to the URL', () => {
const externalLink = wrapper.find(ExternalLink);
expect(externalLink).toHaveLength(1);
expect(externalLink.prop('href')).toEqual(url);
});
it('displays an image with the preview of the URL', () => {
const img = wrapper.find('img');
expect(img).toHaveLength(1);
expect(img.prop('src')).toEqual(`${url}/preview`);
});
});