2020-01-11 21:58:04 +03:00
|
|
|
import React from 'react';
|
|
|
|
import { shallow } from 'enzyme';
|
|
|
|
import { UncontrolledTooltip } from 'reactstrap';
|
2020-01-15 20:31:28 +03:00
|
|
|
import each from 'jest-each';
|
2020-01-11 21:58:04 +03:00
|
|
|
import ShortUrlVisitsCount from '../../../src/short-urls/helpers/ShortUrlVisitsCount';
|
|
|
|
|
|
|
|
describe('<ShortUrlVisitsCount />', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
2020-01-15 20:31:28 +03:00
|
|
|
const createWrapper = (visitsCount, meta) => {
|
|
|
|
wrapper = shallow(<ShortUrlVisitsCount visitsCount={visitsCount} meta={meta} />);
|
2020-01-11 21:58:04 +03:00
|
|
|
|
|
|
|
return wrapper;
|
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => wrapper && wrapper.unmount());
|
|
|
|
|
2020-01-15 20:31:28 +03:00
|
|
|
each([ undefined, {}]).it('just returns visits when no maxVisits is provided', (meta) => {
|
2020-01-11 21:58:04 +03:00
|
|
|
const visitsCount = 45;
|
2020-01-15 20:31:28 +03:00
|
|
|
const wrapper = createWrapper(visitsCount, meta);
|
2020-01-12 14:08:26 +03:00
|
|
|
const maxVisitsHelper = wrapper.find('.short-urls-visits-count__max-visits-control');
|
2020-01-11 21:58:04 +03:00
|
|
|
const maxVisitsTooltip = wrapper.find(UncontrolledTooltip);
|
|
|
|
|
|
|
|
expect(wrapper.html()).toEqual(`<span>${visitsCount}</span>`);
|
|
|
|
expect(maxVisitsHelper).toHaveLength(0);
|
|
|
|
expect(maxVisitsTooltip).toHaveLength(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('displays the maximum amount of visits when present', () => {
|
|
|
|
const visitsCount = 45;
|
|
|
|
const maxVisits = 500;
|
|
|
|
const meta = { maxVisits };
|
2020-01-15 20:31:28 +03:00
|
|
|
const wrapper = createWrapper(visitsCount, meta);
|
2020-01-12 14:08:26 +03:00
|
|
|
const maxVisitsHelper = wrapper.find('.short-urls-visits-count__max-visits-control');
|
2020-01-11 21:58:04 +03:00
|
|
|
const maxVisitsTooltip = wrapper.find(UncontrolledTooltip);
|
|
|
|
|
|
|
|
expect(wrapper.html()).toContain(`/ ${maxVisits}`);
|
|
|
|
expect(maxVisitsHelper).toHaveLength(1);
|
|
|
|
expect(maxVisitsTooltip).toHaveLength(1);
|
|
|
|
});
|
|
|
|
});
|