mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-03-10 09:33:51 +00:00
Introduce shoehorn as a possible replacement for ts-mockery
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { screen } from '@testing-library/react';
|
||||
import { Mock } from 'ts-mockery';
|
||||
import { fromPartial } from '@total-typescript/shoehorn';
|
||||
import type { ServerData } from '../../../src/servers/data';
|
||||
import { DuplicatedServersModal } from '../../../src/servers/helpers/DuplicatedServersModal';
|
||||
import { renderWithEvents } from '../../__helpers__/setUpTest';
|
||||
@@ -10,15 +10,16 @@ describe('<DuplicatedServersModal />', () => {
|
||||
const setUp = (duplicatedServers: ServerData[] = []) => renderWithEvents(
|
||||
<DuplicatedServersModal isOpen duplicatedServers={duplicatedServers} onDiscard={onDiscard} onSave={onSave} />,
|
||||
);
|
||||
const mockServer = (data: Partial<ServerData> = {}) => fromPartial<ServerData>(data);
|
||||
|
||||
beforeEach(jest.clearAllMocks);
|
||||
|
||||
it.each([
|
||||
[[], 0],
|
||||
[[Mock.all<ServerData>()], 2],
|
||||
[[Mock.all<ServerData>(), Mock.all<ServerData>()], 2],
|
||||
[[Mock.all<ServerData>(), Mock.all<ServerData>(), Mock.all<ServerData>()], 3],
|
||||
[[Mock.all<ServerData>(), Mock.all<ServerData>(), Mock.all<ServerData>(), Mock.all<ServerData>()], 4],
|
||||
[[mockServer()], 2],
|
||||
[[mockServer(), mockServer()], 2],
|
||||
[[mockServer(), mockServer(), mockServer()], 3],
|
||||
[[mockServer(), mockServer(), mockServer(), mockServer()], 4],
|
||||
])('renders expected amount of items', (duplicatedServers, expectedItems) => {
|
||||
setUp(duplicatedServers);
|
||||
expect(screen.queryAllByRole('listitem')).toHaveLength(expectedItems);
|
||||
@@ -26,7 +27,7 @@ describe('<DuplicatedServersModal />', () => {
|
||||
|
||||
it.each([
|
||||
[
|
||||
[Mock.all<ServerData>()],
|
||||
[mockServer()],
|
||||
{
|
||||
header: 'Duplicated server',
|
||||
firstParagraph: 'There is already a server with:',
|
||||
@@ -35,7 +36,7 @@ describe('<DuplicatedServersModal />', () => {
|
||||
},
|
||||
],
|
||||
[
|
||||
[Mock.all<ServerData>(), Mock.all<ServerData>()],
|
||||
[mockServer(), mockServer()],
|
||||
{
|
||||
header: 'Duplicated servers',
|
||||
firstParagraph: 'The next servers already exist:',
|
||||
@@ -54,10 +55,10 @@ describe('<DuplicatedServersModal />', () => {
|
||||
|
||||
it.each([
|
||||
[[]],
|
||||
[[Mock.of<ServerData>({ url: 'url', apiKey: 'apiKey' })]],
|
||||
[[mockServer({ url: 'url', apiKey: 'apiKey' })]],
|
||||
[[
|
||||
Mock.of<ServerData>({ url: 'url_1', apiKey: 'apiKey_1' }),
|
||||
Mock.of<ServerData>({ url: 'url_2', apiKey: 'apiKey_2' }),
|
||||
mockServer({ url: 'url_1', apiKey: 'apiKey_1' }),
|
||||
mockServer({ url: 'url_2', apiKey: 'apiKey_2' }),
|
||||
]],
|
||||
])('displays provided server data', (duplicatedServers) => {
|
||||
setUp(duplicatedServers);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { fireEvent, screen, waitFor } from '@testing-library/react';
|
||||
import { Mock } from 'ts-mockery';
|
||||
import { fromPartial } from '@total-typescript/shoehorn';
|
||||
import type { ServersMap, ServerWithId } from '../../../src/servers/data';
|
||||
import type {
|
||||
ImportServersBtnProps } from '../../../src/servers/helpers/ImportServersBtn';
|
||||
@@ -13,7 +13,7 @@ describe('<ImportServersBtn />', () => {
|
||||
const onImportMock = jest.fn();
|
||||
const createServersMock = jest.fn();
|
||||
const importServersFromFile = jest.fn().mockResolvedValue([]);
|
||||
const serversImporterMock = Mock.of<ServersImporter>({ importServersFromFile });
|
||||
const serversImporterMock = fromPartial<ServersImporter>({ importServersFromFile });
|
||||
const ImportServersBtn = createImportServersBtn(serversImporterMock);
|
||||
const setUp = (props: Partial<ImportServersBtnProps> = {}, servers: ServersMap = {}) => renderWithEvents(
|
||||
<ImportServersBtn
|
||||
@@ -67,8 +67,8 @@ describe('<ImportServersBtn />', () => {
|
||||
['Save anyway', true],
|
||||
['Discard', false],
|
||||
])('creates expected servers depending on selected option in modal', async (btnName, savesDuplicatedServers) => {
|
||||
const existingServer = Mock.of<ServerWithId>({ id: 'abc', url: 'existingUrl', apiKey: 'existingApiKey' });
|
||||
const newServer = Mock.of<ServerWithId>({ url: 'newUrl', apiKey: 'newApiKey' });
|
||||
const existingServer = fromPartial<ServerWithId>({ id: 'abc', url: 'existingUrl', apiKey: 'existingApiKey' });
|
||||
const newServer = fromPartial<ServerWithId>({ url: 'newUrl', apiKey: 'newApiKey' });
|
||||
const { container, user } = setUp({}, { abc: existingServer });
|
||||
const input = container.querySelector('[type=file]');
|
||||
importServersFromFile.mockResolvedValue([existingServer, newServer]);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { fromPartial } from '@total-typescript/shoehorn';
|
||||
import { MemoryRouter } from 'react-router-dom';
|
||||
import { Mock } from 'ts-mockery';
|
||||
import type { NonReachableServer, NotFoundServer } from '../../../src/servers/data';
|
||||
import { ServerError as createServerError } from '../../../src/servers/helpers/ServerError';
|
||||
|
||||
@@ -9,7 +9,7 @@ describe('<ServerError />', () => {
|
||||
|
||||
it.each([
|
||||
[
|
||||
Mock.all<NotFoundServer>(),
|
||||
fromPartial<NotFoundServer>({}),
|
||||
{
|
||||
found: ['Could not find this Shlink server.'],
|
||||
notFound: [
|
||||
@@ -20,7 +20,7 @@ describe('<ServerError />', () => {
|
||||
},
|
||||
],
|
||||
[
|
||||
Mock.of<NonReachableServer>({ id: 'abc123' }),
|
||||
fromPartial<NonReachableServer>({ id: 'abc123' }),
|
||||
{
|
||||
found: [
|
||||
'Oops! Could not connect to this Shlink server.',
|
||||
|
||||
Reference in New Issue
Block a user