From 0ac16a1626682fec6da9a2503d62d1ee24865222 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Mon, 19 Dec 2022 20:43:55 +0100 Subject: [PATCH] Added test for ShortUrlStatus component --- .../helpers/ShortUrlStatus.test.tsx | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 test/short-urls/helpers/ShortUrlStatus.test.tsx diff --git a/test/short-urls/helpers/ShortUrlStatus.test.tsx b/test/short-urls/helpers/ShortUrlStatus.test.tsx new file mode 100644 index 00000000..8c689086 --- /dev/null +++ b/test/short-urls/helpers/ShortUrlStatus.test.tsx @@ -0,0 +1,48 @@ +import userEvent from '@testing-library/user-event'; +import { render, screen, waitFor } from '@testing-library/react'; +import { Mock } from 'ts-mockery'; +import { ShortUrlStatus } from '../../../src/short-urls/helpers/ShortUrlStatus'; +import { ShortUrl, ShortUrlMeta, ShortUrlVisitsSummary } from '../../../src/short-urls/data'; + +describe('', () => { + const setUp = (shortUrl: ShortUrl) => ({ + user: userEvent.setup(), + ...render(), + }); + + it.each([ + [ + Mock.of({ validSince: '2099-01-01T10:30:15' }), + {}, + 'This short URL will start working on 2099-01-01 10:30.', + ], + [ + Mock.of({ validUntil: '2020-01-01T10:30:15' }), + {}, + 'This short URL cannot be visited since 2020-01-01 10:30.', + ], + [ + Mock.of({ maxVisits: 10 }), + Mock.of({ total: 10 }), + 'This short URL cannot be currently visited because it has reached the maximum amount of 10 visits.', + ], + [ + Mock.of({ maxVisits: 1 }), + Mock.of({ total: 1 }), + 'This short URL cannot be currently visited because it has reached the maximum amount of 1 visit.', + ], + [{}, {}, 'This short URL can be visited normally.'], + [Mock.of({ validUntil: '2099-01-01T10:30:15' }), {}, 'This short URL can be visited normally.'], + [Mock.of({ validSince: '2020-01-01T10:30:15' }), {}, 'This short URL can be visited normally.'], + [ + Mock.of({ maxVisits: 10 }), + Mock.of({ total: 1 }), + 'This short URL can be visited normally.', + ], + ])('shows expected tooltip', async (meta, visitsSummary, expectedTooltip) => { + const { user } = setUp(Mock.of({ meta, visitsSummary })); + + await user.hover(screen.getByRole('img', { hidden: true })); + await waitFor(() => expect(screen.getByRole('tooltip')).toHaveTextContent(expectedTooltip)); + }); +});