2020-02-08 11:20:19 +03:00
|
|
|
import React from 'react';
|
|
|
|
import { shallow } from 'enzyme';
|
|
|
|
import { Link } from 'react-router-dom';
|
|
|
|
import VisitStatsLink from '../../../src/short-urls/helpers/VisitStatsLink';
|
|
|
|
|
|
|
|
describe('<VisitStatsLink />', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
afterEach(() => wrapper && wrapper.unmount());
|
|
|
|
|
2020-02-17 20:21:52 +03:00
|
|
|
it.each([
|
2020-02-08 11:20:19 +03:00
|
|
|
[ undefined, undefined ],
|
|
|
|
[ null, null ],
|
|
|
|
[{}, null ],
|
|
|
|
[{}, undefined ],
|
|
|
|
[ null, {}],
|
|
|
|
[ undefined, {}],
|
2020-02-17 20:21:52 +03:00
|
|
|
])('only renders a plan span when either server or short URL are not set', (selectedServer, shortUrl) => {
|
2020-02-08 11:20:19 +03:00
|
|
|
wrapper = shallow(<VisitStatsLink selectedServer={selectedServer} shortUrl={shortUrl}>Something</VisitStatsLink>);
|
|
|
|
const link = wrapper.find(Link);
|
|
|
|
|
|
|
|
expect(link).toHaveLength(0);
|
|
|
|
expect(wrapper.html()).toEqual('<span>Something</span>');
|
|
|
|
});
|
|
|
|
|
2020-02-17 20:21:52 +03:00
|
|
|
it.each([
|
2020-02-08 11:20:19 +03:00
|
|
|
[{ id: '1' }, { shortCode: 'abc123' }, '/server/1/short-code/abc123/visits' ],
|
|
|
|
[
|
|
|
|
{ id: '3' },
|
|
|
|
{ shortCode: 'def456', domain: 'example.com' },
|
|
|
|
'/server/3/short-code/def456/visits?domain=example.com',
|
|
|
|
],
|
2020-02-17 20:21:52 +03:00
|
|
|
])('renders link with expected query when', (selectedServer, shortUrl, expectedLink) => {
|
2020-02-08 11:20:19 +03:00
|
|
|
wrapper = shallow(<VisitStatsLink selectedServer={selectedServer} shortUrl={shortUrl}>Something</VisitStatsLink>);
|
|
|
|
const link = wrapper.find(Link);
|
|
|
|
const to = link.prop('to');
|
|
|
|
|
|
|
|
expect(link).toHaveLength(1);
|
|
|
|
expect(to).toEqual(expectedLink);
|
|
|
|
});
|
|
|
|
});
|