2022-07-07 19:44:00 +03:00
|
|
|
import { render } from '@testing-library/react';
|
2020-08-30 10:59:14 +03:00
|
|
|
import { Mock } from 'ts-mockery';
|
2022-05-28 12:16:59 +03:00
|
|
|
import { ShortUrlVisitsCount } from '../../../src/short-urls/helpers/ShortUrlVisitsCount';
|
2020-08-30 10:59:14 +03:00
|
|
|
import { ShortUrl } from '../../../src/short-urls/data';
|
2020-01-11 21:58:04 +03:00
|
|
|
|
|
|
|
describe('<ShortUrlVisitsCount />', () => {
|
2022-07-07 19:44:00 +03:00
|
|
|
const setUp = (visitsCount: number, shortUrl: ShortUrl) => render(
|
|
|
|
<ShortUrlVisitsCount visitsCount={visitsCount} shortUrl={shortUrl} />,
|
|
|
|
);
|
2020-01-11 21:58:04 +03:00
|
|
|
|
2022-03-26 14:17:42 +03:00
|
|
|
it.each([undefined, {}])('just returns visits when no maxVisits is provided', (meta) => {
|
2020-01-11 21:58:04 +03:00
|
|
|
const visitsCount = 45;
|
2022-07-07 19:44:00 +03:00
|
|
|
const { container } = setUp(visitsCount, Mock.of<ShortUrl>({ meta }));
|
2020-01-11 21:58:04 +03:00
|
|
|
|
2022-07-07 19:44:00 +03:00
|
|
|
expect(container.firstChild).toHaveTextContent(`${visitsCount}`);
|
|
|
|
expect(container.querySelector('.short-urls-visits-count__max-visits-control')).not.toBeInTheDocument();
|
2020-01-11 21:58:04 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('displays the maximum amount of visits when present', () => {
|
|
|
|
const visitsCount = 45;
|
|
|
|
const maxVisits = 500;
|
|
|
|
const meta = { maxVisits };
|
2022-07-07 19:44:00 +03:00
|
|
|
const { container } = setUp(visitsCount, Mock.of<ShortUrl>({ meta }));
|
2020-01-11 21:58:04 +03:00
|
|
|
|
2022-07-07 19:44:00 +03:00
|
|
|
expect(container.firstChild).toHaveTextContent(`/ ${maxVisits}`);
|
|
|
|
expect(container.querySelector('.short-urls-visits-count__max-visits-control')).toBeInTheDocument();
|
2020-01-11 21:58:04 +03:00
|
|
|
});
|
|
|
|
});
|