diff --git a/src/short-urls/helpers/ShortUrlVisitsCount.js b/src/short-urls/helpers/ShortUrlVisitsCount.js index 663b3a0e..458ce16e 100644 --- a/src/short-urls/helpers/ShortUrlVisitsCount.js +++ b/src/short-urls/helpers/ShortUrlVisitsCount.js @@ -1,16 +1,17 @@ import React from 'react'; +import PropTypes from 'prop-types'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faInfoCircle as infoIcon } from '@fortawesome/free-solid-svg-icons'; import { UncontrolledTooltip } from 'reactstrap'; -import { shortUrlType } from '../reducers/shortUrlsList'; +import { shortUrlMetaType } from '../reducers/shortUrlsList'; import './ShortUrlVisitsCount.scss'; const propTypes = { - shortUrl: shortUrlType, + visitsCount: PropTypes.number.isRequired, + meta: shortUrlMetaType, }; -const ShortUrlVisitsCount = ({ shortUrl }) => { - const { visitsCount, meta } = shortUrl; +const ShortUrlVisitsCount = ({ visitsCount, meta }) => { const maxVisits = meta && meta.maxVisits; if (!maxVisits) { diff --git a/src/short-urls/helpers/ShortUrlsRow.js b/src/short-urls/helpers/ShortUrlsRow.js index 55aadfa1..43d4205f 100644 --- a/src/short-urls/helpers/ShortUrlsRow.js +++ b/src/short-urls/helpers/ShortUrlsRow.js @@ -58,7 +58,7 @@ const ShortUrlsRow = ( {this.renderTags(shortUrl.tags)} - + - +
Visits:{' '} - + Visit stats for diff --git a/test/short-urls/helpers/ShortUrlVisitsCount.test.js b/test/short-urls/helpers/ShortUrlVisitsCount.test.js index 9949fa4c..42508219 100644 --- a/test/short-urls/helpers/ShortUrlVisitsCount.test.js +++ b/test/short-urls/helpers/ShortUrlVisitsCount.test.js @@ -1,22 +1,23 @@ import React from 'react'; import { shallow } from 'enzyme'; import { UncontrolledTooltip } from 'reactstrap'; +import each from 'jest-each'; import ShortUrlVisitsCount from '../../../src/short-urls/helpers/ShortUrlVisitsCount'; describe('', () => { let wrapper; - const createWrapper = (shortUrl) => { - wrapper = shallow(); + const createWrapper = (visitsCount, meta) => { + wrapper = shallow(); return wrapper; }; afterEach(() => wrapper && wrapper.unmount()); - it('just returns visits when no maxVisits is provided', () => { + each([ undefined, {}]).it('just returns visits when no maxVisits is provided', (meta) => { const visitsCount = 45; - const wrapper = createWrapper({ visitsCount }); + const wrapper = createWrapper(visitsCount, meta); const maxVisitsHelper = wrapper.find('.short-urls-visits-count__max-visits-control'); const maxVisitsTooltip = wrapper.find(UncontrolledTooltip); @@ -29,7 +30,7 @@ describe('', () => { const visitsCount = 45; const maxVisits = 500; const meta = { maxVisits }; - const wrapper = createWrapper({ visitsCount, meta }); + const wrapper = createWrapper(visitsCount, meta); const maxVisitsHelper = wrapper.find('.short-urls-visits-count__max-visits-control'); const maxVisitsTooltip = wrapper.find(UncontrolledTooltip); diff --git a/test/visits/VisitsHeader.test.js b/test/visits/VisitsHeader.test.js index 8b35b93a..9af5b41a 100644 --- a/test/visits/VisitsHeader.test.js +++ b/test/visits/VisitsHeader.test.js @@ -11,20 +11,22 @@ describe('', () => { shortUrl: 'https://doma.in/abc123', longUrl: 'https://foo.bar/bar/foo', dateCreated: '2018-01-01T10:00:00+01:00', - visitsCount: 3, }, loading: false, }; + const shortUrlVisits = { + visits: [{}, {}, {}], + }; beforeEach(() => { - wrapper = shallow(); + wrapper = shallow(); }); afterEach(() => wrapper.unmount()); it('shows the amount of visits', () => { const visitsBadge = wrapper.find('.badge'); - expect(visitsBadge.html()).toContain(`Visits: ${shortUrlDetail.shortUrl.visitsCount}`); + expect(visitsBadge.html()).toContain(`Visits: ${shortUrlVisits.visits.length}`); }); it('shows when the URL was created', () => {