From 79a16a2c2c2c15c48f354ff6efbf64f42c6b0302 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Thu, 1 Nov 2018 12:34:18 +0100 Subject: [PATCH] Created PreviewModal test --- src/short-urls/helpers/PreviewModal.js | 6 +++-- test/short-urls/helpers/PreviewModal.test.js | 28 ++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 test/short-urls/helpers/PreviewModal.test.js diff --git a/src/short-urls/helpers/PreviewModal.js b/src/short-urls/helpers/PreviewModal.js index 87e171aa..13b1ef61 100644 --- a/src/short-urls/helpers/PreviewModal.js +++ b/src/short-urls/helpers/PreviewModal.js @@ -10,7 +10,7 @@ const propTypes = { isOpen: PropTypes.bool, }; -export default function PreviewModal({ url, toggle, isOpen }) { +const PreviewModal = ({ url, toggle, isOpen }) => { return ( @@ -24,6 +24,8 @@ export default function PreviewModal({ url, toggle, isOpen }) { ); -} +}; PreviewModal.propTypes = propTypes; + +export default PreviewModal; diff --git a/test/short-urls/helpers/PreviewModal.test.js b/test/short-urls/helpers/PreviewModal.test.js new file mode 100644 index 00000000..694eb0f7 --- /dev/null +++ b/test/short-urls/helpers/PreviewModal.test.js @@ -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('', () => { + let wrapper; + const url = 'https://doma.in/abc123'; + + beforeEach(() => { + wrapper = shallow(); + }); + 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`); + }); +});