2020-09-05 09:49:18 +03:00
|
|
|
import { shallow, ShallowWrapper } from 'enzyme';
|
2020-05-10 20:37:00 +03:00
|
|
|
import Moment from 'react-moment';
|
|
|
|
import { ExternalLink } from 'react-external-link';
|
2020-09-05 09:49:18 +03:00
|
|
|
import { Mock } from 'ts-mockery';
|
2020-05-10 20:37:00 +03:00
|
|
|
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';
|
2020-05-10 20:37:00 +03:00
|
|
|
|
|
|
|
describe('<ShortUrlVisitsHeader />', () => {
|
2020-09-05 09:49:18 +03:00
|
|
|
let wrapper: ShallowWrapper;
|
|
|
|
const shortUrlDetail = Mock.of<ShortUrlDetail>({
|
2020-05-10 20:37:00 +03:00
|
|
|
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>({
|
2020-05-10 20:37:00 +03:00
|
|
|
visits: [{}, {}, {}],
|
2020-09-05 09:49:18 +03:00
|
|
|
});
|
2020-05-10 20:37:00 +03:00
|
|
|
const goBack = jest.fn();
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = shallow(
|
2020-08-22 09:10:31 +03:00
|
|
|
<ShortUrlVisitsHeader shortUrlDetail={shortUrlDetail} shortUrlVisits={shortUrlVisits} goBack={goBack} />,
|
2020-05-10 20:37:00 +03:00
|
|
|
);
|
|
|
|
});
|
|
|
|
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);
|
2020-05-10 20:37:00 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
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);
|
2020-05-10 20:37:00 +03:00
|
|
|
});
|
|
|
|
});
|