import { render, screen } from '@testing-library/react'; import { Mock } from 'ts-mockery'; import { MemoryRouter } from 'react-router-dom'; import { ShortUrlDetailLink, LinkSuffix } from '../../../src/short-urls/helpers/ShortUrlDetailLink'; import { NotFoundServer, ReachableServer } from '../../../src/servers/data'; import { ShortUrl } from '../../../src/short-urls/data'; describe('', () => { it.each([ [undefined, undefined], [null, null], [Mock.of({ id: '1' }), null], [Mock.of({ id: '1' }), undefined], [Mock.of(), Mock.all()], [null, Mock.all()], [undefined, Mock.all()], ])('only renders a plain span when either server or short URL are not set', (selectedServer, shortUrl) => { render( Something , ); expect(screen.queryByRole('link')).not.toBeInTheDocument(); expect(screen.getByText('Something')).toBeInTheDocument(); }); it.each([ [ Mock.of({ id: '1' }), Mock.of({ shortCode: 'abc123' }), 'visits' as LinkSuffix, '/server/1/short-code/abc123/visits', ], [ Mock.of({ id: '3' }), Mock.of({ shortCode: 'def456', domain: 'example.com' }), 'visits' as LinkSuffix, '/server/3/short-code/def456/visits?domain=example.com', ], [ Mock.of({ id: '1' }), Mock.of({ shortCode: 'abc123' }), 'edit' as LinkSuffix, '/server/1/short-code/abc123/edit', ], [ Mock.of({ id: '3' }), Mock.of({ shortCode: 'def456', domain: 'example.com' }), 'edit' as LinkSuffix, '/server/3/short-code/def456/edit?domain=example.com', ], ])('renders link with expected query when', (selectedServer, shortUrl, suffix, expectedLink) => { render( Something , ); expect(screen.getByRole('link')).toHaveProperty('href', expect.stringContaining(expectedLink)); }); });