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;
|
2021-03-05 17:44:15 +03:00
|
|
|
const dateCreated = '2018-01-01T10:00:00+01:00';
|
|
|
|
const longUrl = 'https://foo.bar/bar/foo';
|
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();
|
2021-03-05 17:44:15 +03:00
|
|
|
const createWrapper = (title?: string | null) => {
|
|
|
|
const shortUrlDetail = Mock.of<ShortUrlDetail>({
|
|
|
|
shortUrl: {
|
|
|
|
shortUrl: 'https://doma.in/abc123',
|
|
|
|
longUrl,
|
|
|
|
dateCreated,
|
|
|
|
title,
|
|
|
|
},
|
|
|
|
loading: false,
|
|
|
|
});
|
2020-05-10 20:37:00 +03:00
|
|
|
|
|
|
|
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
|
|
|
);
|
2021-03-05 17:44:15 +03:00
|
|
|
|
|
|
|
return wrapper;
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => createWrapper());
|
2020-05-10 20:37:00 +03:00
|
|
|
afterEach(() => wrapper.unmount());
|
|
|
|
|
|
|
|
it('shows when the URL was created', () => {
|
|
|
|
const moment = wrapper.find(Moment).first();
|
|
|
|
|
2021-03-05 17:44:15 +03:00
|
|
|
expect(moment.prop('children')).toEqual(dateCreated);
|
2020-05-10 20:37:00 +03:00
|
|
|
});
|
|
|
|
|
2021-03-05 17:44:15 +03:00
|
|
|
it.each([
|
|
|
|
[ null, longUrl ],
|
|
|
|
[ undefined, longUrl ],
|
|
|
|
[ 'My cool title', 'My cool title' ],
|
|
|
|
])('shows the long URL and title', (title, expectedContent) => {
|
|
|
|
const wrapper = createWrapper(title);
|
2020-05-10 20:37:00 +03:00
|
|
|
const longUrlLink = wrapper.find(ExternalLink).last();
|
|
|
|
|
2021-03-05 17:44:15 +03:00
|
|
|
expect(longUrlLink.prop('href')).toEqual(longUrl);
|
|
|
|
expect(longUrlLink.prop('children')).toEqual(expectedContent);
|
2020-05-10 20:37:00 +03:00
|
|
|
});
|
|
|
|
});
|