2020-09-05 09:49:18 +03:00
|
|
|
import { shallow, ShallowWrapper } from 'enzyme';
|
2020-05-10 20:37:00 +03:00
|
|
|
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';
|
2021-03-05 18:04:02 +03:00
|
|
|
import { ShortUrlDetail } from '../../src/short-urls/reducers/shortUrlDetail';
|
2020-09-05 09:49:18 +03:00
|
|
|
import { ShortUrlVisits } from '../../src/visits/reducers/shortUrlVisits';
|
2021-06-24 21:13:06 +03:00
|
|
|
import { Time } from '../../src/utils/Time';
|
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', () => {
|
2021-06-24 21:13:06 +03:00
|
|
|
const time = wrapper.find(Time).first();
|
2020-05-10 20:37:00 +03:00
|
|
|
|
2021-06-24 21:13:06 +03:00
|
|
|
expect(time.prop('date')).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
|
|
|
});
|
|
|
|
});
|