mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-04-11 17:16:20 +00:00
Introduce shoehorn as a possible replacement for ts-mockery
This commit is contained in:
@@ -1,17 +1,16 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { Mock } from 'ts-mockery';
|
||||
import { fromPartial } from '@total-typescript/shoehorn';
|
||||
import type { ShlinkDomainRedirects } from '../../src/api/types';
|
||||
import type { Domain } from '../../src/domains/data';
|
||||
import { DomainRow } from '../../src/domains/DomainRow';
|
||||
import type { SelectedServer } from '../../src/servers/data';
|
||||
|
||||
describe('<DomainRow />', () => {
|
||||
const redirectsCombinations = [
|
||||
[Mock.of<ShlinkDomainRedirects>({ baseUrlRedirect: 'foo' })],
|
||||
[Mock.of<ShlinkDomainRedirects>({ invalidShortUrlRedirect: 'bar' })],
|
||||
[Mock.of<ShlinkDomainRedirects>({ baseUrlRedirect: 'baz', regular404Redirect: 'foo' })],
|
||||
[fromPartial<ShlinkDomainRedirects>({ baseUrlRedirect: 'foo' })],
|
||||
[fromPartial<ShlinkDomainRedirects>({ invalidShortUrlRedirect: 'bar' })],
|
||||
[fromPartial<ShlinkDomainRedirects>({ baseUrlRedirect: 'baz', regular404Redirect: 'foo' })],
|
||||
[
|
||||
Mock.of<ShlinkDomainRedirects>(
|
||||
fromPartial<ShlinkDomainRedirects>(
|
||||
{ baseUrlRedirect: 'baz', regular404Redirect: 'bar', invalidShortUrlRedirect: 'foo' },
|
||||
),
|
||||
],
|
||||
@@ -22,7 +21,7 @@ describe('<DomainRow />', () => {
|
||||
<DomainRow
|
||||
domain={domain}
|
||||
defaultRedirects={defaultRedirects}
|
||||
selectedServer={Mock.all<SelectedServer>()}
|
||||
selectedServer={fromPartial({})}
|
||||
editDomainRedirects={jest.fn()}
|
||||
checkDomainHealth={jest.fn()}
|
||||
/>
|
||||
@@ -31,7 +30,7 @@ describe('<DomainRow />', () => {
|
||||
);
|
||||
|
||||
it.each(redirectsCombinations)('shows expected redirects', (redirects) => {
|
||||
setUp(Mock.of<Domain>({ domain: '', isDefault: true, redirects }));
|
||||
setUp(fromPartial({ domain: '', isDefault: true, redirects }));
|
||||
const cells = screen.getAllByRole('cell');
|
||||
|
||||
redirects?.baseUrlRedirect && expect(cells[1]).toHaveTextContent(redirects.baseUrlRedirect);
|
||||
@@ -42,9 +41,9 @@ describe('<DomainRow />', () => {
|
||||
|
||||
it.each([
|
||||
[undefined],
|
||||
[Mock.of<ShlinkDomainRedirects>()],
|
||||
[fromPartial<ShlinkDomainRedirects>({})],
|
||||
])('shows expected "no redirects"', (redirects) => {
|
||||
setUp(Mock.of<Domain>({ domain: '', isDefault: true, redirects }));
|
||||
setUp(fromPartial({ domain: '', isDefault: true, redirects }));
|
||||
const cells = screen.getAllByRole('cell');
|
||||
|
||||
expect(cells[1]).toHaveTextContent('No redirect');
|
||||
@@ -54,7 +53,7 @@ describe('<DomainRow />', () => {
|
||||
});
|
||||
|
||||
it.each(redirectsCombinations)('shows expected fallback redirects', (fallbackRedirects) => {
|
||||
setUp(Mock.of<Domain>({ domain: '', isDefault: true }), fallbackRedirects);
|
||||
setUp(fromPartial({ domain: '', isDefault: true }), fallbackRedirects);
|
||||
const cells = screen.getAllByRole('cell');
|
||||
|
||||
fallbackRedirects?.baseUrlRedirect && expect(cells[1]).toHaveTextContent(
|
||||
@@ -69,7 +68,7 @@ describe('<DomainRow />', () => {
|
||||
});
|
||||
|
||||
it.each([[true], [false]])('shows icon on default domain only', (isDefault) => {
|
||||
const { container } = setUp(Mock.of<Domain>({ domain: '', isDefault }));
|
||||
const { container } = setUp(fromPartial({ domain: '', isDefault }));
|
||||
|
||||
if (isDefault) {
|
||||
expect(container.querySelector('#defaultDomainIcon')).toBeInTheDocument();
|
||||
|
||||
Reference in New Issue
Block a user