2018-09-08 10:31:44 +03:00
|
|
|
import React from 'react';
|
|
|
|
import { shallow } from 'enzyme';
|
|
|
|
import Moment from 'react-moment';
|
2020-01-15 20:16:12 +03:00
|
|
|
import { ExternalLink } from 'react-external-link';
|
2019-03-04 20:14:45 +03:00
|
|
|
import VisitsHeader from '../../src/visits/VisitsHeader';
|
2018-09-08 10:31:44 +03:00
|
|
|
|
|
|
|
describe('<VisitsHeader />', () => {
|
|
|
|
let wrapper;
|
|
|
|
const shortUrlDetail = {
|
|
|
|
shortUrl: {
|
2019-01-13 11:49:02 +03:00
|
|
|
shortUrl: 'https://doma.in/abc123',
|
2018-09-08 10:31:44 +03:00
|
|
|
longUrl: 'https://foo.bar/bar/foo',
|
|
|
|
dateCreated: '2018-01-01T10:00:00+01:00',
|
|
|
|
},
|
|
|
|
loading: false,
|
|
|
|
};
|
2020-01-15 20:31:28 +03:00
|
|
|
const shortUrlVisits = {
|
|
|
|
visits: [{}, {}, {}],
|
|
|
|
};
|
2020-04-26 11:43:00 +03:00
|
|
|
const goBack = jest.fn();
|
2018-09-08 10:31:44 +03:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2020-04-26 11:43:00 +03:00
|
|
|
wrapper = shallow(<VisitsHeader shortUrlDetail={shortUrlDetail} shortUrlVisits={shortUrlVisits} goBack={goBack} />);
|
2018-09-08 10:31:44 +03:00
|
|
|
});
|
|
|
|
afterEach(() => wrapper.unmount());
|
|
|
|
|
|
|
|
it('shows the amount of visits', () => {
|
|
|
|
const visitsBadge = wrapper.find('.badge');
|
|
|
|
|
2020-04-18 11:50:01 +03:00
|
|
|
expect(visitsBadge.html()).toContain(
|
|
|
|
`Visits: <span><strong class="short-url-visits-count__amount">${shortUrlVisits.visits.length}</strong></span>`
|
|
|
|
);
|
2018-09-08 10:31:44 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('shows when the URL was created', () => {
|
|
|
|
const moment = wrapper.find(Moment).first();
|
|
|
|
|
|
|
|
expect(moment.prop('children')).toEqual(shortUrlDetail.shortUrl.dateCreated);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows the long URL', () => {
|
|
|
|
const longUrlLink = wrapper.find(ExternalLink).last();
|
|
|
|
|
|
|
|
expect(longUrlLink.prop('href')).toEqual(shortUrlDetail.shortUrl.longUrl);
|
|
|
|
});
|
|
|
|
});
|