shlink-web-client/test/visits/ShortUrlVisitsHeader.test.tsx

44 lines
1.4 KiB
TypeScript
Raw Normal View History

import React from 'react';
2020-09-05 09:49:18 +03:00
import { shallow, ShallowWrapper } from 'enzyme';
import Moment from 'react-moment';
import { ExternalLink } from 'react-external-link';
2020-09-05 09:49:18 +03:00
import { Mock } from 'ts-mockery';
import ShortUrlVisitsHeader from '../../src/visits/ShortUrlVisitsHeader';
2020-09-05 09:49:18 +03:00
import { ShortUrlDetail } from '../../src/visits/reducers/shortUrlDetail';
import { ShortUrlVisits } from '../../src/visits/reducers/shortUrlVisits';
describe('<ShortUrlVisitsHeader />', () => {
2020-09-05 09:49:18 +03:00
let wrapper: ShallowWrapper;
const shortUrlDetail = Mock.of<ShortUrlDetail>({
shortUrl: {
shortUrl: 'https://doma.in/abc123',
longUrl: 'https://foo.bar/bar/foo',
dateCreated: '2018-01-01T10:00:00+01:00',
},
loading: false,
2020-09-05 09:49:18 +03:00
});
const shortUrlVisits = Mock.of<ShortUrlVisits>({
visits: [{}, {}, {}],
2020-09-05 09:49:18 +03:00
});
const goBack = jest.fn();
beforeEach(() => {
wrapper = shallow(
2020-08-22 09:10:31 +03:00
<ShortUrlVisitsHeader shortUrlDetail={shortUrlDetail} shortUrlVisits={shortUrlVisits} goBack={goBack} />,
);
});
afterEach(() => wrapper.unmount());
it('shows when the URL was created', () => {
const moment = wrapper.find(Moment).first();
2020-09-05 09:49:18 +03:00
expect(moment.prop('children')).toEqual(shortUrlDetail.shortUrl?.dateCreated);
});
it('shows the long URL', () => {
const longUrlLink = wrapper.find(ExternalLink).last();
2020-09-05 09:49:18 +03:00
expect(longUrlLink.prop('href')).toEqual(shortUrlDetail.shortUrl?.longUrl);
});
});