From 04e1950591b99560ea5da04b7188a547b1095a68 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Thu, 13 Apr 2023 22:47:13 +0200 Subject: [PATCH] Migrate more tests to shoehorn --- .../reducers/shortUrlCreation.test.ts | 16 ++-- .../reducers/shortUrlDeletion.test.ts | 12 ++- .../reducers/shortUrlDetail.test.ts | 24 ++--- .../reducers/shortUrlEdition.test.ts | 15 +-- .../short-urls/reducers/shortUrlsList.test.ts | 95 +++++++++---------- test/tags/TagsList.test.tsx | 11 +-- test/tags/TagsTable.test.tsx | 8 +- test/tags/TagsTableRow.test.tsx | 5 +- test/tags/helpers/EditTagModal.test.tsx | 10 +- test/tags/helpers/Tag.test.tsx | 4 +- test/tags/helpers/TagsSelector.test.tsx | 7 +- test/tags/reducers/tagDelete.test.ts | 6 +- test/tags/reducers/tagEdit.test.ts | 15 ++- test/tags/reducers/tagsList.test.ts | 44 ++++----- test/utils/DropdownBtnMenu.test.tsx | 6 +- test/utils/dates/DateInput.test.tsx | 4 +- test/utils/dates/DateRangeSelector.test.tsx | 4 +- test/utils/helpers/version.test.ts | 28 +++--- test/utils/services/ColorGenerator.test.ts | 4 +- test/utils/services/LocalStorage.test.ts | 4 +- .../services/__mocks__/ColorGenerator.mock.ts | 4 +- test/visits/DomainVisits.test.tsx | 13 +-- test/visits/NonOrphanVisits.test.tsx | 13 +-- test/visits/OrphanVisits.test.tsx | 13 +-- test/visits/ShortUrlVisits.test.tsx | 18 ++-- test/visits/ShortUrlVisitsHeader.test.tsx | 6 +- test/visits/TagVisits.test.tsx | 18 ++-- test/visits/TagVisitsHeader.test.tsx | 6 +- test/visits/VisitsHeader.test.tsx | 4 +- test/visits/VisitsStats.test.tsx | 9 +- test/visits/VisitsTable.test.tsx | 20 ++-- .../charts/DoughnutChartLegend.test.tsx | 6 +- test/visits/charts/LineChartCard.test.tsx | 12 +-- 33 files changed, 218 insertions(+), 246 deletions(-) diff --git a/test/short-urls/reducers/shortUrlCreation.test.ts b/test/short-urls/reducers/shortUrlCreation.test.ts index deeda1fe..e1e14a9e 100644 --- a/test/short-urls/reducers/shortUrlCreation.test.ts +++ b/test/short-urls/reducers/shortUrlCreation.test.ts @@ -1,16 +1,16 @@ -import { Mock } from 'ts-mockery'; +import { fromPartial } from '@total-typescript/shoehorn'; import type { ShlinkApiClient } from '../../../src/api/services/ShlinkApiClient'; import type { ShlinkState } from '../../../src/container/types'; -import type { ShortUrl, ShortUrlData } from '../../../src/short-urls/data'; +import type { ShortUrl } from '../../../src/short-urls/data'; import { createShortUrl as createShortUrlCreator, shortUrlCreationReducerCreator, } from '../../../src/short-urls/reducers/shortUrlCreation'; describe('shortUrlCreationReducer', () => { - const shortUrl = Mock.of(); + const shortUrl = fromPartial({}); const createShortUrlCall = jest.fn(); - const buildShlinkApiClient = () => Mock.of({ createShortUrl: createShortUrlCall }); + const buildShlinkApiClient = () => fromPartial({ createShortUrl: createShortUrlCall }); const createShortUrl = createShortUrlCreator(buildShlinkApiClient); const { reducer, resetCreateShortUrl } = shortUrlCreationReducerCreator(createShortUrl); @@ -18,7 +18,7 @@ describe('shortUrlCreationReducer', () => { describe('reducer', () => { it('returns loading on CREATE_SHORT_URL_START', () => { - expect(reducer(undefined, createShortUrl.pending('', Mock.all()))).toEqual({ + expect(reducer(undefined, createShortUrl.pending('', fromPartial({})))).toEqual({ saving: true, saved: false, error: false, @@ -26,7 +26,7 @@ describe('shortUrlCreationReducer', () => { }); it('returns error on CREATE_SHORT_URL_ERROR', () => { - expect(reducer(undefined, createShortUrl.rejected(null, '', Mock.all()))).toEqual({ + expect(reducer(undefined, createShortUrl.rejected(null, '', fromPartial({})))).toEqual({ saving: false, saved: false, error: true, @@ -34,7 +34,7 @@ describe('shortUrlCreationReducer', () => { }); it('returns result on CREATE_SHORT_URL', () => { - expect(reducer(undefined, createShortUrl.fulfilled(shortUrl, '', Mock.all()))).toEqual({ + expect(reducer(undefined, createShortUrl.fulfilled(shortUrl, '', fromPartial({})))).toEqual({ result: shortUrl, saving: false, saved: true, @@ -53,7 +53,7 @@ describe('shortUrlCreationReducer', () => { describe('createShortUrl', () => { const dispatch = jest.fn(); - const getState = () => Mock.all(); + const getState = () => fromPartial({}); it('calls API on success', async () => { createShortUrlCall.mockResolvedValue(shortUrl); diff --git a/test/short-urls/reducers/shortUrlDeletion.test.ts b/test/short-urls/reducers/shortUrlDeletion.test.ts index 1db369a6..74f7017b 100644 --- a/test/short-urls/reducers/shortUrlDeletion.test.ts +++ b/test/short-urls/reducers/shortUrlDeletion.test.ts @@ -1,15 +1,15 @@ -import { Mock } from 'ts-mockery'; +import { fromPartial } from '@total-typescript/shoehorn'; import type { ShlinkApiClient } from '../../../src/api/services/ShlinkApiClient'; import type { ProblemDetailsError } from '../../../src/api/types/errors'; import { - deleteShortUrl as deleteShortUrlCretor, + deleteShortUrl as deleteShortUrlCreator, shortUrlDeletionReducerCreator, } from '../../../src/short-urls/reducers/shortUrlDeletion'; describe('shortUrlDeletionReducer', () => { const deleteShortUrlCall = jest.fn(); - const buildShlinkApiClient = () => Mock.of({ deleteShortUrl: deleteShortUrlCall }); - const deleteShortUrl = deleteShortUrlCretor(buildShlinkApiClient); + const buildShlinkApiClient = () => fromPartial({ deleteShortUrl: deleteShortUrlCall }); + const deleteShortUrl = deleteShortUrlCreator(buildShlinkApiClient); const { reducer, resetDeleteShortUrl } = shortUrlDeletionReducerCreator(deleteShortUrl); beforeEach(jest.clearAllMocks); @@ -40,7 +40,9 @@ describe('shortUrlDeletionReducer', () => { })); it('returns errorData on DELETE_SHORT_URL_ERROR', () => { - const errorData = Mock.of({ type: 'bar', detail: 'detail', title: 'title', status: 400 }); + const errorData = fromPartial( + { type: 'bar', detail: 'detail', title: 'title', status: 400 }, + ); const error = errorData as unknown as Error; expect(reducer(undefined, deleteShortUrl.rejected(error, '', { shortCode: '' }))).toEqual({ diff --git a/test/short-urls/reducers/shortUrlDetail.test.ts b/test/short-urls/reducers/shortUrlDetail.test.ts index 52ffa603..5aee45b2 100644 --- a/test/short-urls/reducers/shortUrlDetail.test.ts +++ b/test/short-urls/reducers/shortUrlDetail.test.ts @@ -1,4 +1,4 @@ -import { Mock } from 'ts-mockery'; +import { fromPartial } from '@total-typescript/shoehorn'; import type { ShlinkApiClient } from '../../../src/api/services/ShlinkApiClient'; import type { ShlinkState } from '../../../src/container/types'; import type { ShortUrl } from '../../../src/short-urls/data'; @@ -7,7 +7,7 @@ import type { ShortUrlsList } from '../../../src/short-urls/reducers/shortUrlsLi describe('shortUrlDetailReducer', () => { const getShortUrlCall = jest.fn(); - const buildShlinkApiClient = () => Mock.of({ getShortUrl: getShortUrlCall }); + const buildShlinkApiClient = () => fromPartial({ getShortUrl: getShortUrlCall }); const { reducer, getShortUrlDetail } = shortUrlDetailReducerCreator(buildShlinkApiClient); beforeEach(jest.clearAllMocks); @@ -27,7 +27,7 @@ describe('shortUrlDetailReducer', () => { }); it('return short URL on GET_SHORT_URL_DETAIL', () => { - const actionShortUrl = Mock.of({ longUrl: 'foo', shortCode: 'bar' }); + const actionShortUrl = fromPartial({ longUrl: 'foo', shortCode: 'bar' }); const state = reducer( { loading: true, error: false }, getShortUrlDetail.fulfilled(actionShortUrl, '', { shortCode: '' }), @@ -42,25 +42,25 @@ describe('shortUrlDetailReducer', () => { describe('getShortUrlDetail', () => { const dispatchMock = jest.fn(); - const buildGetState = (shortUrlsList?: ShortUrlsList) => () => Mock.of({ shortUrlsList }); + const buildGetState = (shortUrlsList?: ShortUrlsList) => () => fromPartial({ shortUrlsList }); it.each([ [undefined], - [Mock.all()], + [fromPartial({})], [ - Mock.of({ + fromPartial({ shortUrls: { data: [] }, }), ], [ - Mock.of({ + fromPartial({ shortUrls: { - data: [Mock.of({ shortCode: 'this_will_not_match' })], + data: [{ shortCode: 'this_will_not_match' }], }, }), ], ])('performs API call when short URL is not found in local state', async (shortUrlsList?: ShortUrlsList) => { - const resolvedShortUrl = Mock.of({ longUrl: 'foo', shortCode: 'abc123' }); + const resolvedShortUrl = fromPartial({ longUrl: 'foo', shortCode: 'abc123' }); getShortUrlCall.mockResolvedValue(resolvedShortUrl); await getShortUrlDetail({ shortCode: 'abc123', domain: '' })(dispatchMock, buildGetState(shortUrlsList), {}); @@ -71,12 +71,12 @@ describe('shortUrlDetailReducer', () => { }); it('avoids API calls when short URL is found in local state', async () => { - const foundShortUrl = Mock.of({ longUrl: 'foo', shortCode: 'abc123' }); - getShortUrlCall.mockResolvedValue(Mock.all()); + const foundShortUrl = fromPartial({ longUrl: 'foo', shortCode: 'abc123' }); + getShortUrlCall.mockResolvedValue(fromPartial({})); await getShortUrlDetail(foundShortUrl)( dispatchMock, - buildGetState(Mock.of({ + buildGetState(fromPartial({ shortUrls: { data: [foundShortUrl], }, diff --git a/test/short-urls/reducers/shortUrlEdition.test.ts b/test/short-urls/reducers/shortUrlEdition.test.ts index c5ef958b..e1f143f2 100644 --- a/test/short-urls/reducers/shortUrlEdition.test.ts +++ b/test/short-urls/reducers/shortUrlEdition.test.ts @@ -1,8 +1,7 @@ -import { Mock } from 'ts-mockery'; +import { fromPartial } from '@total-typescript/shoehorn'; import type { ShlinkState } from '../../../src/container/types'; import type { SelectedServer } from '../../../src/servers/data'; import type { ShortUrl } from '../../../src/short-urls/data'; -import type { EditShortUrl } from '../../../src/short-urls/reducers/shortUrlEdition'; import { editShortUrl as editShortUrlCreator, shortUrlEditionReducerCreator, @@ -11,7 +10,7 @@ import { describe('shortUrlEditionReducer', () => { const longUrl = 'https://shlink.io'; const shortCode = 'abc123'; - const shortUrl = Mock.of({ longUrl, shortCode }); + const shortUrl = fromPartial({ longUrl, shortCode }); const updateShortUrl = jest.fn().mockResolvedValue(shortUrl); const buildShlinkApiClient = jest.fn().mockReturnValue({ updateShortUrl }); const editShortUrl = editShortUrlCreator(buildShlinkApiClient); @@ -21,7 +20,7 @@ describe('shortUrlEditionReducer', () => { describe('reducer', () => { it('returns loading on EDIT_SHORT_URL_START', () => { - expect(reducer(undefined, editShortUrl.pending('', Mock.all()))).toEqual({ + expect(reducer(undefined, editShortUrl.pending('', fromPartial({})))).toEqual({ saving: true, saved: false, error: false, @@ -29,7 +28,7 @@ describe('shortUrlEditionReducer', () => { }); it('returns error on EDIT_SHORT_URL_ERROR', () => { - expect(reducer(undefined, editShortUrl.rejected(null, '', Mock.all()))).toEqual({ + expect(reducer(undefined, editShortUrl.rejected(null, '', fromPartial({})))).toEqual({ saving: false, saved: false, error: true, @@ -37,7 +36,7 @@ describe('shortUrlEditionReducer', () => { }); it('returns provided tags and shortCode on SHORT_URL_EDITED', () => { - expect(reducer(undefined, editShortUrl.fulfilled(shortUrl, '', Mock.all()))).toEqual({ + expect(reducer(undefined, editShortUrl.fulfilled(shortUrl, '', fromPartial({})))).toEqual({ shortUrl, saving: false, saved: true, @@ -48,7 +47,9 @@ describe('shortUrlEditionReducer', () => { describe('editShortUrl', () => { const dispatch = jest.fn(); - const createGetState = (selectedServer: SelectedServer = null) => () => Mock.of({ selectedServer }); + const createGetState = (selectedServer: SelectedServer = null) => () => fromPartial({ + selectedServer, + }); afterEach(jest.clearAllMocks); diff --git a/test/short-urls/reducers/shortUrlsList.test.ts b/test/short-urls/reducers/shortUrlsList.test.ts index f03aea60..2954ac8f 100644 --- a/test/short-urls/reducers/shortUrlsList.test.ts +++ b/test/short-urls/reducers/shortUrlsList.test.ts @@ -1,10 +1,9 @@ -import { Mock } from 'ts-mockery'; +import { fromPartial } from '@total-typescript/shoehorn'; import type { ShlinkApiClient } from '../../../src/api/services/ShlinkApiClient'; -import type { ShlinkPaginator, ShlinkShortUrlsResponse } from '../../../src/api/types'; -import type { ShortUrl, ShortUrlData } from '../../../src/short-urls/data'; +import type { ShlinkShortUrlsResponse } from '../../../src/api/types'; +import type { ShortUrl } from '../../../src/short-urls/data'; import { createShortUrl as createShortUrlCreator } from '../../../src/short-urls/reducers/shortUrlCreation'; import { shortUrlDeleted } from '../../../src/short-urls/reducers/shortUrlDeletion'; -import type { EditShortUrl } from '../../../src/short-urls/reducers/shortUrlEdition'; import { editShortUrl as editShortUrlCreator } from '../../../src/short-urls/reducers/shortUrlEdition'; import { listShortUrls as listShortUrlsCreator, @@ -16,7 +15,7 @@ import type { CreateVisit } from '../../../src/visits/types'; describe('shortUrlsListReducer', () => { const shortCode = 'abc123'; const listShortUrlsMock = jest.fn(); - const buildShlinkApiClient = () => Mock.of({ listShortUrls: listShortUrlsMock }); + const buildShlinkApiClient = () => fromPartial({ listShortUrls: listShortUrlsMock }); const listShortUrls = listShortUrlsCreator(buildShlinkApiClient); const editShortUrl = editShortUrlCreator(buildShlinkApiClient); const createShortUrl = createShortUrlCreator(buildShlinkApiClient); @@ -32,7 +31,7 @@ describe('shortUrlsListReducer', () => { })); it('returns short URLs on LIST_SHORT_URLS', () => - expect(reducer(undefined, listShortUrls.fulfilled(Mock.of({ data: [] }), ''))).toEqual({ + expect(reducer(undefined, listShortUrls.fulfilled(fromPartial({ data: [] }), ''))).toEqual({ shortUrls: { data: [] }, loading: false, error: false, @@ -46,21 +45,19 @@ describe('shortUrlsListReducer', () => { it('removes matching URL and reduces total on SHORT_URL_DELETED', () => { const state = { - shortUrls: Mock.of({ + shortUrls: fromPartial({ data: [ - Mock.of({ shortCode }), - Mock.of({ shortCode, domain: 'example.com' }), - Mock.of({ shortCode: 'foo' }), + { shortCode }, + { shortCode, domain: 'example.com' }, + { shortCode: 'foo' }, ], - pagination: Mock.of({ - totalItems: 10, - }), + pagination: { totalItems: 10 }, }), loading: false, error: false, }; - expect(reducer(state, shortUrlDeleted(Mock.of({ shortCode })))).toEqual({ + expect(reducer(state, shortUrlDeleted(fromPartial({ shortCode })))).toEqual({ shortUrls: { data: [{ shortCode, domain: 'example.com' }, { shortCode: 'foo' }], pagination: { totalItems: 9 }, @@ -70,7 +67,7 @@ describe('shortUrlsListReducer', () => { }); }); - const createNewShortUrlVisit = (visitsCount: number) => Mock.of({ + const createNewShortUrlVisit = (visitsCount: number) => fromPartial({ shortUrl: { shortCode: 'abc123', visitsCount }, }); @@ -81,11 +78,11 @@ describe('shortUrlsListReducer', () => { [[], 10], ])('updates visits count on CREATE_VISITS', (createdVisits, expectedCount) => { const state = { - shortUrls: Mock.of({ + shortUrls: fromPartial({ data: [ - Mock.of({ shortCode, domain: 'example.com', visitsCount: 5 }), - Mock.of({ shortCode, visitsCount: 10 }), - Mock.of({ shortCode: 'foo', visitsCount: 8 }), + { shortCode, domain: 'example.com', visitsCount: 5 }, + { shortCode, visitsCount: 10 }, + { shortCode: 'foo', visitsCount: 8 }, ], }), loading: false, @@ -108,48 +105,46 @@ describe('shortUrlsListReducer', () => { it.each([ [ [ - Mock.of({ shortCode }), - Mock.of({ shortCode, domain: 'example.com' }), - Mock.of({ shortCode: 'foo' }), + fromPartial({ shortCode }), + fromPartial({ shortCode, domain: 'example.com' }), + fromPartial({ shortCode: 'foo' }), ], [{ shortCode: 'newOne' }, { shortCode }, { shortCode, domain: 'example.com' }, { shortCode: 'foo' }], ], [ [ - Mock.of({ shortCode }), - Mock.of({ shortCode: 'code' }), - Mock.of({ shortCode: 'foo' }), - Mock.of({ shortCode: 'bar' }), - Mock.of({ shortCode: 'baz' }), + fromPartial({ shortCode }), + fromPartial({ shortCode: 'code' }), + fromPartial({ shortCode: 'foo' }), + fromPartial({ shortCode: 'bar' }), + fromPartial({ shortCode: 'baz' }), ], [{ shortCode: 'newOne' }, { shortCode }, { shortCode: 'code' }, { shortCode: 'foo' }, { shortCode: 'bar' }], ], [ [ - Mock.of({ shortCode }), - Mock.of({ shortCode: 'code' }), - Mock.of({ shortCode: 'foo' }), - Mock.of({ shortCode: 'bar' }), - Mock.of({ shortCode: 'baz1' }), - Mock.of({ shortCode: 'baz2' }), - Mock.of({ shortCode: 'baz3' }), + fromPartial({ shortCode }), + fromPartial({ shortCode: 'code' }), + fromPartial({ shortCode: 'foo' }), + fromPartial({ shortCode: 'bar' }), + fromPartial({ shortCode: 'baz1' }), + fromPartial({ shortCode: 'baz2' }), + fromPartial({ shortCode: 'baz3' }), ], [{ shortCode: 'newOne' }, { shortCode }, { shortCode: 'code' }, { shortCode: 'foo' }, { shortCode: 'bar' }], ], ])('prepends new short URL and increases total on CREATE_SHORT_URL', (data, expectedData) => { - const newShortUrl = Mock.of({ shortCode: 'newOne' }); + const newShortUrl = fromPartial({ shortCode: 'newOne' }); const state = { - shortUrls: Mock.of({ + shortUrls: fromPartial({ data, - pagination: Mock.of({ - totalItems: 15, - }), + pagination: { totalItems: 15 }, }), loading: false, error: false, }; - expect(reducer(state, createShortUrl.fulfilled(newShortUrl, '', Mock.all()))).toEqual({ + expect(reducer(state, createShortUrl.fulfilled(newShortUrl, '', fromPartial({})))).toEqual({ shortUrls: { data: expectedData, pagination: { totalItems: 16 }, @@ -161,16 +156,16 @@ describe('shortUrlsListReducer', () => { it.each([ ((): [ShortUrl, ShortUrl[], ShortUrl[]] => { - const editedShortUrl = Mock.of({ shortCode: 'notMatching' }); - const list = [Mock.of({ shortCode: 'foo' }), Mock.of({ shortCode: 'bar' })]; + const editedShortUrl = fromPartial({ shortCode: 'notMatching' }); + const list: ShortUrl[] = [fromPartial({ shortCode: 'foo' }), fromPartial({ shortCode: 'bar' })]; return [editedShortUrl, list, list]; })(), ((): [ShortUrl, ShortUrl[], ShortUrl[]] => { - const editedShortUrl = Mock.of({ shortCode: 'matching', longUrl: 'new_one' }); - const list = [ - Mock.of({ shortCode: 'matching', longUrl: 'old_one' }), - Mock.of({ shortCode: 'bar' }), + const editedShortUrl = fromPartial({ shortCode: 'matching', longUrl: 'new_one' }); + const list: ShortUrl[] = [ + fromPartial({ shortCode: 'matching', longUrl: 'old_one' }), + fromPartial({ shortCode: 'bar' }), ]; const expectedList = [editedShortUrl, list[1]]; @@ -178,17 +173,15 @@ describe('shortUrlsListReducer', () => { })(), ])('updates matching short URL on SHORT_URL_EDITED', (editedShortUrl, initialList, expectedList) => { const state = { - shortUrls: Mock.of({ + shortUrls: fromPartial({ data: initialList, - pagination: Mock.of({ - totalItems: 15, - }), + pagination: { totalItems: 15 }, }), loading: false, error: false, }; - const result = reducer(state, editShortUrl.fulfilled(editedShortUrl, '', Mock.of())); + const result = reducer(state, editShortUrl.fulfilled(editedShortUrl, '', fromPartial({}))); expect(result.shortUrls?.data).toEqual(expectedList); }); diff --git a/test/tags/TagsList.test.tsx b/test/tags/TagsList.test.tsx index 19f59b25..f486054b 100644 --- a/test/tags/TagsList.test.tsx +++ b/test/tags/TagsList.test.tsx @@ -1,8 +1,7 @@ import { screen, waitFor } from '@testing-library/react'; +import { fromPartial } from '@total-typescript/shoehorn'; import { identity } from 'ramda'; -import { Mock } from 'ts-mockery'; import type { MercureBoundProps } from '../../src/mercure/helpers/boundToMercureHub'; -import type { Settings } from '../../src/settings/reducers/settings'; import type { TagsList } from '../../src/tags/reducers/tagsList'; import type { TagsListProps } from '../../src/tags/TagsList'; import { TagsList as createTagsList } from '../../src/tags/TagsList'; @@ -13,12 +12,12 @@ describe('', () => { const TagsListComp = createTagsList(({ sortedTags }) => <>TagsTable ({sortedTags.map((t) => t.visits).join(',')})); const setUp = (tagsList: Partial, excludeBots = false) => renderWithEvents( ()} - {...Mock.of({ mercureInfo: {} })} + {...fromPartial({})} + {...fromPartial({ mercureInfo: {} })} forceListTags={identity} filterTags={filterTags} - tagsList={Mock.of(tagsList)} - settings={Mock.of({ visits: { excludeBots } })} + tagsList={fromPartial(tagsList)} + settings={fromPartial({ visits: { excludeBots } })} />, ); diff --git a/test/tags/TagsTable.test.tsx b/test/tags/TagsTable.test.tsx index da187a6a..ad41c4ce 100644 --- a/test/tags/TagsTable.test.tsx +++ b/test/tags/TagsTable.test.tsx @@ -1,8 +1,6 @@ import { screen } from '@testing-library/react'; +import { fromPartial } from '@total-typescript/shoehorn'; import { useLocation } from 'react-router-dom'; -import { Mock } from 'ts-mockery'; -import type { SelectedServer } from '../../src/servers/data'; -import type { SimplifiedTag } from '../../src/tags/data'; import { TagsTable as createTagsTable } from '../../src/tags/TagsTable'; import { rangeOf } from '../../src/utils/utils'; import { renderWithEvents } from '../__helpers__/setUpTest'; @@ -17,8 +15,8 @@ describe('', () => { (useLocation as any).mockReturnValue({ search }); return renderWithEvents( Mock.of({ tag }))} - selectedServer={Mock.all()} + sortedTags={sortedTags.map((tag) => fromPartial({ tag }))} + selectedServer={fromPartial({})} currentOrder={{}} orderByColumn={() => orderByColumn} />, diff --git a/test/tags/TagsTableRow.test.tsx b/test/tags/TagsTableRow.test.tsx index 4f3a133a..ec2c4e8a 100644 --- a/test/tags/TagsTableRow.test.tsx +++ b/test/tags/TagsTableRow.test.tsx @@ -1,7 +1,6 @@ import { screen } from '@testing-library/react'; +import { fromPartial } from '@total-typescript/shoehorn'; import { MemoryRouter } from 'react-router-dom'; -import { Mock } from 'ts-mockery'; -import type { ReachableServer } from '../../src/servers/data'; import { TagsTableRow as createTagsTableRow } from '../../src/tags/TagsTableRow'; import { renderWithEvents } from '../__helpers__/setUpTest'; import { colorGeneratorMock } from '../utils/services/__mocks__/ColorGenerator.mock'; @@ -18,7 +17,7 @@ describe('', () => { ({ id: 'abc123' })} + selectedServer={fromPartial({ id: 'abc123' })} /> diff --git a/test/tags/helpers/EditTagModal.test.tsx b/test/tags/helpers/EditTagModal.test.tsx index 0b6a96b7..674f4fd5 100644 --- a/test/tags/helpers/EditTagModal.test.tsx +++ b/test/tags/helpers/EditTagModal.test.tsx @@ -1,17 +1,15 @@ import { screen, waitFor } from '@testing-library/react'; -import { Mock } from 'ts-mockery'; -import type { ProblemDetailsError } from '../../../src/api/types/errors'; +import { fromPartial } from '@total-typescript/shoehorn'; import { EditTagModal as createEditTagModal } from '../../../src/tags/helpers/EditTagModal'; import type { TagEdition } from '../../../src/tags/reducers/tagEdit'; -import type { ColorGenerator } from '../../../src/utils/services/ColorGenerator'; import { renderWithEvents } from '../../__helpers__/setUpTest'; describe('', () => { - const EditTagModal = createEditTagModal(Mock.of({ getColorForKey: jest.fn(() => 'green') })); + const EditTagModal = createEditTagModal(fromPartial({ getColorForKey: jest.fn(() => 'green') })); const editTag = jest.fn().mockReturnValue(Promise.resolve()); const toggle = jest.fn(); const setUp = (tagEdit: Partial = {}) => { - const edition = Mock.of(tagEdit); + const edition = fromPartial(tagEdit); return renderWithEvents( , ); @@ -43,7 +41,7 @@ describe('', () => { [true, 1], [false, 0], ])('displays error result in case of error', (error, expectedResultCount) => { - setUp({ error, errorData: Mock.all() }); + setUp({ error, errorData: fromPartial({}) }); expect(screen.queryAllByText('Something went wrong while editing the tag :(')).toHaveLength(expectedResultCount); }); diff --git a/test/tags/helpers/Tag.test.tsx b/test/tags/helpers/Tag.test.tsx index 46f224e7..d754aebd 100644 --- a/test/tags/helpers/Tag.test.tsx +++ b/test/tags/helpers/Tag.test.tsx @@ -1,6 +1,6 @@ import { screen } from '@testing-library/react'; +import { fromPartial } from '@total-typescript/shoehorn'; import type { ReactNode } from 'react'; -import { Mock } from 'ts-mockery'; import { Tag } from '../../../src/tags/helpers/Tag'; import type { ColorGenerator } from '../../../src/utils/services/ColorGenerator'; import { MAIN_COLOR } from '../../../src/utils/theme'; @@ -24,7 +24,7 @@ describe('', () => { const onClose = jest.fn(); const isColorLightForKey = jest.fn(() => false); const getColorForKey = jest.fn(() => MAIN_COLOR); - const colorGenerator = Mock.of({ getColorForKey, isColorLightForKey }); + const colorGenerator = fromPartial({ getColorForKey, isColorLightForKey }); const setUp = (text: string, clearable?: boolean, children?: ReactNode) => renderWithEvents( {children} diff --git a/test/tags/helpers/TagsSelector.test.tsx b/test/tags/helpers/TagsSelector.test.tsx index 398a0e93..f0a6fd3a 100644 --- a/test/tags/helpers/TagsSelector.test.tsx +++ b/test/tags/helpers/TagsSelector.test.tsx @@ -1,6 +1,5 @@ import { screen } from '@testing-library/react'; -import { Mock } from 'ts-mockery'; -import type { Settings } from '../../../src/settings/reducers/settings'; +import { fromPartial } from '@total-typescript/shoehorn'; import { TagsSelector as createTagsSelector } from '../../../src/tags/helpers/TagsSelector'; import type { TagsList } from '../../../src/tags/reducers/tagsList'; import { renderWithEvents } from '../../__helpers__/setUpTest'; @@ -10,12 +9,12 @@ describe('', () => { const onChange = jest.fn(); const TagsSelector = createTagsSelector(colorGeneratorMock); const tags = ['foo', 'bar']; - const tagsList = Mock.of({ tags: [...tags, 'baz'] }); + const tagsList = fromPartial({ tags: [...tags, 'baz'] }); const setUp = () => renderWithEvents( ()} + settings={fromPartial({})} listTags={jest.fn()} onChange={onChange} />, diff --git a/test/tags/reducers/tagDelete.test.ts b/test/tags/reducers/tagDelete.test.ts index e07b964d..640cd88c 100644 --- a/test/tags/reducers/tagDelete.test.ts +++ b/test/tags/reducers/tagDelete.test.ts @@ -1,11 +1,11 @@ -import { Mock } from 'ts-mockery'; +import { fromPartial } from '@total-typescript/shoehorn'; import type { ShlinkApiClient } from '../../../src/api/services/ShlinkApiClient'; import type { ShlinkState } from '../../../src/container/types'; import { tagDeleted, tagDeleteReducerCreator } from '../../../src/tags/reducers/tagDelete'; describe('tagDeleteReducer', () => { const deleteTagsCall = jest.fn(); - const buildShlinkApiClient = () => Mock.of({ deleteTags: deleteTagsCall }); + const buildShlinkApiClient = () => fromPartial({ deleteTags: deleteTagsCall }); const { reducer, deleteTag } = tagDeleteReducerCreator(buildShlinkApiClient); beforeEach(jest.clearAllMocks); @@ -44,7 +44,7 @@ describe('tagDeleteReducer', () => { describe('deleteTag', () => { const dispatch = jest.fn(); - const getState = () => Mock.all(); + const getState = () => fromPartial({}); it('calls API on success', async () => { const tag = 'foo'; diff --git a/test/tags/reducers/tagEdit.test.ts b/test/tags/reducers/tagEdit.test.ts index 8e3f0ba2..f5b4426c 100644 --- a/test/tags/reducers/tagEdit.test.ts +++ b/test/tags/reducers/tagEdit.test.ts @@ -1,7 +1,6 @@ -import { Mock } from 'ts-mockery'; +import { fromPartial } from '@total-typescript/shoehorn'; import type { ShlinkApiClient } from '../../../src/api/services/ShlinkApiClient'; import type { ShlinkState } from '../../../src/container/types'; -import type { EditTag } from '../../../src/tags/reducers/tagEdit'; import { editTag as editTagCreator, tagEdited, tagEditReducerCreator } from '../../../src/tags/reducers/tagEdit'; import type { ColorGenerator } from '../../../src/utils/services/ColorGenerator'; @@ -10,14 +9,14 @@ describe('tagEditReducer', () => { const newName = 'bar'; const color = '#ff0000'; const editTagCall = jest.fn(); - const buildShlinkApiClient = () => Mock.of({ editTag: editTagCall }); - const colorGenerator = Mock.of({ setColorForKey: jest.fn() }); + const buildShlinkApiClient = () => fromPartial({ editTag: editTagCall }); + const colorGenerator = fromPartial({ setColorForKey: jest.fn() }); const editTag = editTagCreator(buildShlinkApiClient, colorGenerator); const { reducer } = tagEditReducerCreator(editTag); describe('reducer', () => { it('returns loading on EDIT_TAG_START', () => { - expect(reducer(undefined, editTag.pending('', Mock.all()))).toEqual({ + expect(reducer(undefined, editTag.pending('', fromPartial({})))).toEqual({ editing: true, edited: false, error: false, @@ -25,7 +24,7 @@ describe('tagEditReducer', () => { }); it('returns error on EDIT_TAG_ERROR', () => { - expect(reducer(undefined, editTag.rejected(null, '', Mock.all()))).toEqual({ + expect(reducer(undefined, editTag.rejected(null, '', fromPartial({})))).toEqual({ editing: false, edited: false, error: true, @@ -33,7 +32,7 @@ describe('tagEditReducer', () => { }); it('returns tag names on EDIT_TAG', () => { - expect(reducer(undefined, editTag.fulfilled({ oldName, newName, color }, '', Mock.all()))).toEqual({ + expect(reducer(undefined, editTag.fulfilled({ oldName, newName, color }, '', fromPartial({})))).toEqual({ editing: false, edited: true, error: false, @@ -52,7 +51,7 @@ describe('tagEditReducer', () => { describe('editTag', () => { const dispatch = jest.fn(); - const getState = () => Mock.of(); + const getState = () => fromPartial({}); afterEach(jest.clearAllMocks); diff --git a/test/tags/reducers/tagsList.test.ts b/test/tags/reducers/tagsList.test.ts index d8f9cfe1..09936db2 100644 --- a/test/tags/reducers/tagsList.test.ts +++ b/test/tags/reducers/tagsList.test.ts @@ -1,6 +1,6 @@ -import { Mock } from 'ts-mockery'; +import { fromPartial } from '@total-typescript/shoehorn'; import type { ShlinkState } from '../../../src/container/types'; -import type { ShortUrl, ShortUrlData } from '../../../src/short-urls/data'; +import type { ShortUrl } from '../../../src/short-urls/data'; import { createShortUrl as createShortUrlCreator } from '../../../src/short-urls/reducers/shortUrlCreation'; import { tagDeleted } from '../../../src/tags/reducers/tagDelete'; import { tagEdited } from '../../../src/tags/reducers/tagEdit'; @@ -12,10 +12,10 @@ import { tagsListReducerCreator, } from '../../../src/tags/reducers/tagsList'; import { createNewVisits } from '../../../src/visits/reducers/visitCreation'; -import type { CreateVisit, Visit } from '../../../src/visits/types'; +import type { CreateVisit } from '../../../src/visits/types'; describe('tagsListReducer', () => { - const state = (props: Partial) => Mock.of(props); + const state = (props: Partial) => fromPartial(props); const buildShlinkApiClient = jest.fn(); const listTags = listTagsCreator(buildShlinkApiClient, true); const createShortUrl = createShortUrlCreator(buildShlinkApiClient); @@ -41,7 +41,7 @@ describe('tagsListReducer', () => { it('returns provided tags as filtered and regular tags on LIST_TAGS', () => { const tags = ['foo', 'bar', 'baz']; - expect(reducer(undefined, listTags.fulfilled(Mock.of({ tags }), ''))).toEqual({ + expect(reducer(undefined, listTags.fulfilled(fromPartial({ tags }), ''))).toEqual({ tags, filteredTags: tags, loading: false, @@ -114,30 +114,30 @@ describe('tagsListReducer', () => { [['new', 'tag'], ['foo', 'bar', 'baz', 'foo2', 'fo', 'new', 'tag']], ])('appends new short URL\'s tags to the list of tags on CREATE_SHORT_URL', (shortUrlTags, expectedTags) => { const tags = ['foo', 'bar', 'baz', 'foo2', 'fo']; - const payload = Mock.of({ tags: shortUrlTags }); + const payload = fromPartial({ tags: shortUrlTags }); - expect(reducer(state({ tags }), createShortUrl.fulfilled(payload, '', Mock.of()))).toEqual({ + expect(reducer(state({ tags }), createShortUrl.fulfilled(payload, '', fromPartial({})))).toEqual({ tags: expectedTags, }); }); it('increases amounts when visits are created', () => { - const createdVisits = [ - Mock.of({ - shortUrl: Mock.of({ tags: ['foo', 'bar'] }), - visit: Mock.of({ potentialBot: true }), + const createdVisits: CreateVisit[] = [ + fromPartial({ + shortUrl: { tags: ['foo', 'bar'] }, + visit: { potentialBot: true }, }), - Mock.of({ - shortUrl: Mock.of({ tags: ['foo', 'bar'] }), - visit: Mock.all(), + fromPartial({ + shortUrl: { tags: ['foo', 'bar'] }, + visit: {}, }), - Mock.of({ - shortUrl: Mock.of({ tags: ['bar'] }), - visit: Mock.all(), + fromPartial({ + shortUrl: { tags: ['bar'] }, + visit: {}, }), - Mock.of({ - shortUrl: Mock.of({ tags: ['baz'] }), - visit: Mock.of({ potentialBot: true }), + fromPartial({ + shortUrl: { tags: ['baz'] }, + visit: { potentialBot: true }, }), ]; const tagStats = (total: number) => ({ @@ -197,11 +197,11 @@ describe('tagsListReducer', () => { describe('listTags', () => { const dispatch = jest.fn(); - const getState = jest.fn(() => Mock.all()); + const getState = jest.fn(() => fromPartial({})); const listTagsMock = jest.fn(); const assertNoAction = async (tagsList: TagsList) => { - getState.mockReturnValue(Mock.of({ tagsList })); + getState.mockReturnValue(fromPartial({ tagsList })); await listTagsCreator(buildShlinkApiClient, false)()(dispatch, getState, {}); diff --git a/test/utils/DropdownBtnMenu.test.tsx b/test/utils/DropdownBtnMenu.test.tsx index c38d0c7d..22741fde 100644 --- a/test/utils/DropdownBtnMenu.test.tsx +++ b/test/utils/DropdownBtnMenu.test.tsx @@ -1,12 +1,14 @@ import { screen } from '@testing-library/react'; -import { Mock } from 'ts-mockery'; +import { fromPartial } from '@total-typescript/shoehorn'; import type { DropdownBtnMenuProps } from '../../src/utils/DropdownBtnMenu'; import { DropdownBtnMenu } from '../../src/utils/DropdownBtnMenu'; import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { const setUp = (props: Partial = {}) => renderWithEvents( - ({ toggle: jest.fn(), ...props })}>the children, + ({ toggle: jest.fn(), ...props })}> + the children + , ); it('renders expected components', () => { diff --git a/test/utils/dates/DateInput.test.tsx b/test/utils/dates/DateInput.test.tsx index 1e648089..b37e3409 100644 --- a/test/utils/dates/DateInput.test.tsx +++ b/test/utils/dates/DateInput.test.tsx @@ -1,13 +1,13 @@ import { screen, waitFor } from '@testing-library/react'; +import { fromPartial } from '@total-typescript/shoehorn'; import { parseISO } from 'date-fns'; -import { Mock } from 'ts-mockery'; import type { DateInputProps } from '../../../src/utils/dates/DateInput'; import { DateInput } from '../../../src/utils/dates/DateInput'; import { renderWithEvents } from '../../__helpers__/setUpTest'; describe('', () => { const setUp = (props: Partial = {}) => renderWithEvents( - (props)} />, + (props)} />, ); it('shows calendar icon when input is not clearable', () => { diff --git a/test/utils/dates/DateRangeSelector.test.tsx b/test/utils/dates/DateRangeSelector.test.tsx index ed4429fa..08047483 100644 --- a/test/utils/dates/DateRangeSelector.test.tsx +++ b/test/utils/dates/DateRangeSelector.test.tsx @@ -1,5 +1,5 @@ import { screen, waitFor } from '@testing-library/react'; -import { Mock } from 'ts-mockery'; +import { fromPartial } from '@total-typescript/shoehorn'; import type { DateRangeSelectorProps } from '../../../src/utils/dates/DateRangeSelector'; import { DateRangeSelector } from '../../../src/utils/dates/DateRangeSelector'; import type { DateInterval } from '../../../src/utils/helpers/dateIntervals'; @@ -10,7 +10,7 @@ describe('', () => { const setUp = async (props: Partial = {}) => { const result = renderWithEvents( (props)} + {...fromPartial(props)} defaultText="Default text" onDatesChange={onDatesChange} />, diff --git a/test/utils/helpers/version.test.ts b/test/utils/helpers/version.test.ts index a0f8ce21..44888723 100644 --- a/test/utils/helpers/version.test.ts +++ b/test/utils/helpers/version.test.ts @@ -1,4 +1,4 @@ -import { Mock } from 'ts-mockery'; +import { fromPartial } from '@total-typescript/shoehorn'; import type { SemVer, Versions } from '../../../src/utils/helpers/version'; import { versionMatch } from '../../../src/utils/helpers/version'; import type { Empty } from '../../../src/utils/utils'; @@ -6,19 +6,19 @@ import type { Empty } from '../../../src/utils/utils'; describe('version', () => { describe('versionMatch', () => { it.each([ - [undefined, Mock.all(), false], - [null, Mock.all(), false], - ['' as Empty, Mock.all(), false], - [[], Mock.all(), false], - ['2.8.3' as SemVer, Mock.all(), true], - ['2.8.3' as SemVer, Mock.of({ minVersion: '2.0.0' }), true], - ['2.0.0' as SemVer, Mock.of({ minVersion: '2.0.0' }), true], - ['1.8.0' as SemVer, Mock.of({ maxVersion: '1.8.0' }), true], - ['1.7.1' as SemVer, Mock.of({ maxVersion: '1.8.0' }), true], - ['1.7.3' as SemVer, Mock.of({ minVersion: '1.7.0', maxVersion: '1.8.0' }), true], - ['1.8.3' as SemVer, Mock.of({ minVersion: '2.0.0' }), false], - ['1.8.3' as SemVer, Mock.of({ maxVersion: '1.8.0' }), false], - ['1.8.3' as SemVer, Mock.of({ minVersion: '1.7.0', maxVersion: '1.8.0' }), false], + [undefined, fromPartial({}), false], + [null, fromPartial({}), false], + ['' as Empty, fromPartial({}), false], + [[], fromPartial({}), false], + ['2.8.3' as SemVer, fromPartial({}), true], + ['2.8.3' as SemVer, fromPartial({ minVersion: '2.0.0' }), true], + ['2.0.0' as SemVer, fromPartial({ minVersion: '2.0.0' }), true], + ['1.8.0' as SemVer, fromPartial({ maxVersion: '1.8.0' }), true], + ['1.7.1' as SemVer, fromPartial({ maxVersion: '1.8.0' }), true], + ['1.7.3' as SemVer, fromPartial({ minVersion: '1.7.0', maxVersion: '1.8.0' }), true], + ['1.8.3' as SemVer, fromPartial({ minVersion: '2.0.0' }), false], + ['1.8.3' as SemVer, fromPartial({ maxVersion: '1.8.0' }), false], + ['1.8.3' as SemVer, fromPartial({ minVersion: '1.7.0', maxVersion: '1.8.0' }), false], ])('properly matches versions based on what is provided', (version, versionConstraints, expected) => { expect(versionMatch(version, versionConstraints)).toEqual(expected); }); diff --git a/test/utils/services/ColorGenerator.test.ts b/test/utils/services/ColorGenerator.test.ts index c6a04084..50c85b0c 100644 --- a/test/utils/services/ColorGenerator.test.ts +++ b/test/utils/services/ColorGenerator.test.ts @@ -1,11 +1,11 @@ -import { Mock } from 'ts-mockery'; +import { fromPartial } from '@total-typescript/shoehorn'; import { ColorGenerator } from '../../../src/utils/services/ColorGenerator'; import type { LocalStorage } from '../../../src/utils/services/LocalStorage'; import { MAIN_COLOR } from '../../../src/utils/theme'; describe('ColorGenerator', () => { let colorGenerator: ColorGenerator; - const storageMock = Mock.of({ + const storageMock = fromPartial({ set: jest.fn(), get: jest.fn(), }); diff --git a/test/utils/services/LocalStorage.test.ts b/test/utils/services/LocalStorage.test.ts index 4f59cc1d..dd866efa 100644 --- a/test/utils/services/LocalStorage.test.ts +++ b/test/utils/services/LocalStorage.test.ts @@ -1,10 +1,10 @@ -import { Mock } from 'ts-mockery'; +import { fromPartial } from '@total-typescript/shoehorn'; import { LocalStorage } from '../../../src/utils/services/LocalStorage'; describe('LocalStorage', () => { const getItem = jest.fn((key) => (key === 'shlink.foo' ? JSON.stringify({ foo: 'bar' }) : null)); const setItem = jest.fn(); - const localStorageMock = Mock.of({ getItem, setItem }); + const localStorageMock = fromPartial({ getItem, setItem }); let storage: LocalStorage; beforeEach(() => { diff --git a/test/utils/services/__mocks__/ColorGenerator.mock.ts b/test/utils/services/__mocks__/ColorGenerator.mock.ts index 19cde63c..2c68c4d6 100644 --- a/test/utils/services/__mocks__/ColorGenerator.mock.ts +++ b/test/utils/services/__mocks__/ColorGenerator.mock.ts @@ -1,7 +1,7 @@ -import { Mock } from 'ts-mockery'; +import { fromPartial } from '@total-typescript/shoehorn'; import type { ColorGenerator } from '../../../../src/utils/services/ColorGenerator'; -export const colorGeneratorMock = Mock.of({ +export const colorGeneratorMock = fromPartial({ getColorForKey: jest.fn(() => 'red'), setColorForKey: jest.fn(), isColorLightForKey: jest.fn(() => false), diff --git a/test/visits/DomainVisits.test.tsx b/test/visits/DomainVisits.test.tsx index 7cfa5b6d..7323a76f 100644 --- a/test/visits/DomainVisits.test.tsx +++ b/test/visits/DomainVisits.test.tsx @@ -1,13 +1,10 @@ import { screen } from '@testing-library/react'; +import { fromPartial } from '@total-typescript/shoehorn'; import { formatISO } from 'date-fns'; import { MemoryRouter } from 'react-router-dom'; -import { Mock } from 'ts-mockery'; -import type { ReportExporter } from '../../src/common/services/ReportExporter'; import type { MercureBoundProps } from '../../src/mercure/helpers/boundToMercureHub'; -import type { Settings } from '../../src/settings/reducers/settings'; import { DomainVisits as createDomainVisits } from '../../src/visits/DomainVisits'; import type { DomainVisits } from '../../src/visits/reducers/domainVisits'; -import type { Visit } from '../../src/visits/types'; import { renderWithEvents } from '../__helpers__/setUpTest'; jest.mock('react-router-dom', () => ({ @@ -19,16 +16,16 @@ describe('', () => { const exportVisits = jest.fn(); const getDomainVisits = jest.fn(); const cancelGetDomainVisits = jest.fn(); - const domainVisits = Mock.of({ visits: [Mock.of({ date: formatISO(new Date()) })] }); - const DomainVisits = createDomainVisits(Mock.of({ exportVisits })); + const domainVisits = fromPartial({ visits: [{ date: formatISO(new Date()) }] }); + const DomainVisits = createDomainVisits(fromPartial({ exportVisits })); const setUp = () => renderWithEvents( ({ mercureInfo: {} })} + {...fromPartial({ mercureInfo: {} })} getDomainVisits={getDomainVisits} cancelGetDomainVisits={cancelGetDomainVisits} domainVisits={domainVisits} - settings={Mock.all()} + settings={fromPartial({})} /> , ); diff --git a/test/visits/NonOrphanVisits.test.tsx b/test/visits/NonOrphanVisits.test.tsx index 413ea32f..c60160ff 100644 --- a/test/visits/NonOrphanVisits.test.tsx +++ b/test/visits/NonOrphanVisits.test.tsx @@ -1,29 +1,26 @@ import { screen } from '@testing-library/react'; +import { fromPartial } from '@total-typescript/shoehorn'; import { formatISO } from 'date-fns'; import { MemoryRouter } from 'react-router-dom'; -import { Mock } from 'ts-mockery'; -import type { ReportExporter } from '../../src/common/services/ReportExporter'; import type { MercureBoundProps } from '../../src/mercure/helpers/boundToMercureHub'; -import type { Settings } from '../../src/settings/reducers/settings'; import { NonOrphanVisits as createNonOrphanVisits } from '../../src/visits/NonOrphanVisits'; import type { VisitsInfo } from '../../src/visits/reducers/types'; -import type { Visit } from '../../src/visits/types'; import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { const exportVisits = jest.fn(); const getNonOrphanVisits = jest.fn(); const cancelGetNonOrphanVisits = jest.fn(); - const nonOrphanVisits = Mock.of({ visits: [Mock.of({ date: formatISO(new Date()) })] }); - const NonOrphanVisits = createNonOrphanVisits(Mock.of({ exportVisits })); + const nonOrphanVisits = fromPartial({ visits: [{ date: formatISO(new Date()) }] }); + const NonOrphanVisits = createNonOrphanVisits(fromPartial({ exportVisits })); const setUp = () => renderWithEvents( ({ mercureInfo: {} })} + {...fromPartial({ mercureInfo: {} })} getNonOrphanVisits={getNonOrphanVisits} cancelGetNonOrphanVisits={cancelGetNonOrphanVisits} nonOrphanVisits={nonOrphanVisits} - settings={Mock.all()} + settings={fromPartial({})} /> , ); diff --git a/test/visits/OrphanVisits.test.tsx b/test/visits/OrphanVisits.test.tsx index a8a76cf7..87f46f72 100644 --- a/test/visits/OrphanVisits.test.tsx +++ b/test/visits/OrphanVisits.test.tsx @@ -1,28 +1,25 @@ import { screen } from '@testing-library/react'; +import { fromPartial } from '@total-typescript/shoehorn'; import { formatISO } from 'date-fns'; import { MemoryRouter } from 'react-router-dom'; -import { Mock } from 'ts-mockery'; -import type { ReportExporter } from '../../src/common/services/ReportExporter'; import type { MercureBoundProps } from '../../src/mercure/helpers/boundToMercureHub'; -import type { Settings } from '../../src/settings/reducers/settings'; import { OrphanVisits as createOrphanVisits } from '../../src/visits/OrphanVisits'; import type { VisitsInfo } from '../../src/visits/reducers/types'; -import type { Visit } from '../../src/visits/types'; import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { const getOrphanVisits = jest.fn(); const exportVisits = jest.fn(); - const orphanVisits = Mock.of({ visits: [Mock.of({ date: formatISO(new Date()) })] }); - const OrphanVisits = createOrphanVisits(Mock.of({ exportVisits })); + const orphanVisits = fromPartial({ visits: [{ date: formatISO(new Date()) }] }); + const OrphanVisits = createOrphanVisits(fromPartial({ exportVisits })); const setUp = () => renderWithEvents( ({ mercureInfo: {} })} + {...fromPartial({ mercureInfo: {} })} getOrphanVisits={getOrphanVisits} orphanVisits={orphanVisits} cancelGetOrphanVisits={jest.fn()} - settings={Mock.all()} + settings={fromPartial({})} /> , ); diff --git a/test/visits/ShortUrlVisits.test.tsx b/test/visits/ShortUrlVisits.test.tsx index 8b34d951..b36dadbe 100644 --- a/test/visits/ShortUrlVisits.test.tsx +++ b/test/visits/ShortUrlVisits.test.tsx @@ -1,33 +1,29 @@ import { screen } from '@testing-library/react'; +import { fromPartial } from '@total-typescript/shoehorn'; import { formatISO } from 'date-fns'; import { identity } from 'ramda'; import { MemoryRouter } from 'react-router-dom'; -import { Mock } from 'ts-mockery'; -import type { ReportExporter } from '../../src/common/services/ReportExporter'; import type { MercureBoundProps } from '../../src/mercure/helpers/boundToMercureHub'; -import type { Settings } from '../../src/settings/reducers/settings'; -import type { ShortUrlDetail } from '../../src/short-urls/reducers/shortUrlDetail'; import type { ShortUrlVisits as ShortUrlVisitsState } from '../../src/visits/reducers/shortUrlVisits'; import type { ShortUrlVisitsProps } from '../../src/visits/ShortUrlVisits'; import { ShortUrlVisits as createShortUrlVisits } from '../../src/visits/ShortUrlVisits'; -import type { Visit } from '../../src/visits/types'; import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { const getShortUrlVisitsMock = jest.fn(); const exportVisits = jest.fn(); - const shortUrlVisits = Mock.of({ visits: [Mock.of({ date: formatISO(new Date()) })] }); - const ShortUrlVisits = createShortUrlVisits(Mock.of({ exportVisits })); + const shortUrlVisits = fromPartial({ visits: [{ date: formatISO(new Date()) }] }); + const ShortUrlVisits = createShortUrlVisits(fromPartial({ exportVisits })); const setUp = () => renderWithEvents( ()} - {...Mock.of({ mercureInfo: {} })} + {...fromPartial({})} + {...fromPartial({ mercureInfo: {} })} getShortUrlDetail={identity} getShortUrlVisits={getShortUrlVisitsMock} shortUrlVisits={shortUrlVisits} - shortUrlDetail={Mock.all()} - settings={Mock.all()} + shortUrlDetail={fromPartial({})} + settings={fromPartial({})} cancelGetShortUrlVisits={() => {}} /> , diff --git a/test/visits/ShortUrlVisitsHeader.test.tsx b/test/visits/ShortUrlVisitsHeader.test.tsx index ff4cea75..a9ec7756 100644 --- a/test/visits/ShortUrlVisitsHeader.test.tsx +++ b/test/visits/ShortUrlVisitsHeader.test.tsx @@ -1,6 +1,6 @@ import { screen, waitFor } from '@testing-library/react'; +import { fromPartial } from '@total-typescript/shoehorn'; import { formatDistance, parseISO } from 'date-fns'; -import { Mock } from 'ts-mockery'; import type { ShortUrlDetail } from '../../src/short-urls/reducers/shortUrlDetail'; import type { ShortUrlVisits } from '../../src/visits/reducers/shortUrlVisits'; import { ShortUrlVisitsHeader } from '../../src/visits/ShortUrlVisitsHeader'; @@ -9,12 +9,12 @@ import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { const dateCreated = '2018-01-01T10:00:00+00:00'; const longUrl = 'https://foo.bar/bar/foo'; - const shortUrlVisits = Mock.of({ + const shortUrlVisits = fromPartial({ visits: [{}, {}, {}], }); const goBack = jest.fn(); const setUp = (title?: string | null) => { - const shortUrlDetail = Mock.of({ + const shortUrlDetail = fromPartial({ shortUrl: { shortUrl: 'https://s.test/abc123', longUrl, diff --git a/test/visits/TagVisits.test.tsx b/test/visits/TagVisits.test.tsx index d08ce2c5..492fb577 100644 --- a/test/visits/TagVisits.test.tsx +++ b/test/visits/TagVisits.test.tsx @@ -1,15 +1,11 @@ import { screen } from '@testing-library/react'; +import { fromPartial } from '@total-typescript/shoehorn'; import { formatISO } from 'date-fns'; import { MemoryRouter } from 'react-router-dom'; -import { Mock } from 'ts-mockery'; -import type { ReportExporter } from '../../src/common/services/ReportExporter'; import type { MercureBoundProps } from '../../src/mercure/helpers/boundToMercureHub'; -import type { Settings } from '../../src/settings/reducers/settings'; -import type { ColorGenerator } from '../../src/utils/services/ColorGenerator'; import type { TagVisits as TagVisitsStats } from '../../src/visits/reducers/tagVisits'; import type { TagVisitsProps } from '../../src/visits/TagVisits'; import { TagVisits as createTagVisits } from '../../src/visits/TagVisits'; -import type { Visit } from '../../src/visits/types'; import { renderWithEvents } from '../__helpers__/setUpTest'; jest.mock('react-router-dom', () => ({ @@ -20,19 +16,19 @@ jest.mock('react-router-dom', () => ({ describe('', () => { const getTagVisitsMock = jest.fn(); const exportVisits = jest.fn(); - const tagVisits = Mock.of({ visits: [Mock.of({ date: formatISO(new Date()) })] }); + const tagVisits = fromPartial({ visits: [{ date: formatISO(new Date()) }] }); const TagVisits = createTagVisits( - Mock.of({ isColorLightForKey: () => false, getColorForKey: () => 'red' }), - Mock.of({ exportVisits }), + fromPartial({ isColorLightForKey: () => false, getColorForKey: () => 'red' }), + fromPartial({ exportVisits }), ); const setUp = () => renderWithEvents( ()} - {...Mock.of({ mercureInfo: {} })} + {...fromPartial({})} + {...fromPartial({ mercureInfo: {} })} getTagVisits={getTagVisitsMock} tagVisits={tagVisits} - settings={Mock.all()} + settings={fromPartial({})} cancelGetTagVisits={() => {}} /> , diff --git a/test/visits/TagVisitsHeader.test.tsx b/test/visits/TagVisitsHeader.test.tsx index 1040dc50..1905d121 100644 --- a/test/visits/TagVisitsHeader.test.tsx +++ b/test/visits/TagVisitsHeader.test.tsx @@ -1,16 +1,16 @@ import { render, screen } from '@testing-library/react'; -import { Mock } from 'ts-mockery'; +import { fromPartial } from '@total-typescript/shoehorn'; import type { ColorGenerator } from '../../src/utils/services/ColorGenerator'; import type { TagVisits } from '../../src/visits/reducers/tagVisits'; import { TagVisitsHeader } from '../../src/visits/TagVisitsHeader'; describe('', () => { - const tagVisits = Mock.of({ + const tagVisits = fromPartial({ tag: 'foo', visits: [{}, {}, {}, {}], }); const goBack = jest.fn(); - const colorGenerator = Mock.of({ isColorLightForKey: () => false, getColorForKey: () => 'red' }); + const colorGenerator = fromPartial({ isColorLightForKey: () => false, getColorForKey: () => 'red' }); const setUp = () => render(); it('shows expected visits', () => { diff --git a/test/visits/VisitsHeader.test.tsx b/test/visits/VisitsHeader.test.tsx index 66da11c9..64887d20 100644 --- a/test/visits/VisitsHeader.test.tsx +++ b/test/visits/VisitsHeader.test.tsx @@ -1,10 +1,10 @@ import { render, screen } from '@testing-library/react'; -import { Mock } from 'ts-mockery'; +import { fromPartial } from '@total-typescript/shoehorn'; import type { Visit } from '../../src/visits/types'; import { VisitsHeader } from '../../src/visits/VisitsHeader'; describe('', () => { - const visits = [Mock.all(), Mock.all(), Mock.all()]; + const visits: Visit[] = [fromPartial({}), fromPartial({}), fromPartial({})]; const title = 'My header title'; const goBack = jest.fn(); const setUp = () => render(); diff --git a/test/visits/VisitsStats.test.tsx b/test/visits/VisitsStats.test.tsx index 8afde4e9..eb8cc1b8 100644 --- a/test/visits/VisitsStats.test.tsx +++ b/test/visits/VisitsStats.test.tsx @@ -1,8 +1,7 @@ import { screen, waitFor } from '@testing-library/react'; +import { fromPartial } from '@total-typescript/shoehorn'; import { createMemoryHistory } from 'history'; import { Router } from 'react-router-dom'; -import { Mock } from 'ts-mockery'; -import type { Settings } from '../../src/settings/reducers/settings'; import { rangeOf } from '../../src/utils/utils'; import type { VisitsInfo } from '../../src/visits/reducers/types'; import type { Visit } from '../../src/visits/types'; @@ -10,7 +9,7 @@ import { VisitsStats } from '../../src/visits/VisitsStats'; import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { - const visits = rangeOf(3, () => Mock.of({ date: '2020-01-01' })); + const visits = rangeOf(3, () => fromPartial({ date: '2020-01-01' })); const getVisitsMock = jest.fn(); const exportCsv = jest.fn(); const setUp = (visitsInfo: Partial, activeRoute = '/by-time') => { @@ -23,9 +22,9 @@ describe('', () => { (visitsInfo)} + visitsInfo={fromPartial(visitsInfo)} cancelGetVisits={() => {}} - settings={Mock.all()} + settings={fromPartial({})} exportCsv={exportCsv} /> , diff --git a/test/visits/VisitsTable.test.tsx b/test/visits/VisitsTable.test.tsx index e62da685..eb59deda 100644 --- a/test/visits/VisitsTable.test.tsx +++ b/test/visits/VisitsTable.test.tsx @@ -1,5 +1,5 @@ import { screen, waitFor } from '@testing-library/react'; -import { Mock } from 'ts-mockery'; +import { fromPartial } from '@total-typescript/shoehorn'; import { rangeOf } from '../../src/utils/utils'; import type { NormalizedVisit } from '../../src/visits/types'; import type { VisitsTableProps } from '../../src/visits/VisitsTable'; @@ -7,7 +7,7 @@ import { VisitsTable } from '../../src/visits/VisitsTable'; import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { - const matchMedia = () => Mock.of({ matches: false }); + const matchMedia = () => fromPartial({ matches: false }); const setSelectedVisits = jest.fn(); const setUpFactory = (props: Partial = {}) => renderWithEvents( ', () => { const setUpForOrphanVisits = (isOrphanVisits: boolean) => setUpFactory({ isOrphanVisits }); const setUpWithBots = () => setUpFactory({ visits: [ - Mock.of({ potentialBot: false, date: '2022-05-05' }), - Mock.of({ potentialBot: true, date: '2022-05-05' }), + fromPartial({ potentialBot: false, date: '2022-05-05' }), + fromPartial({ potentialBot: true, date: '2022-05-05' }), ], }); @@ -48,7 +48,7 @@ describe('', () => { [115, 7, 2], // This one will have ellipsis ])('renders the expected amount of pages', (visitsCount, expectedAmountOfPageItems, expectedDisabledItems) => { const { container } = setUp( - rangeOf(visitsCount, () => Mock.of({ browser: '', date: '2022-01-01', referer: '' })), + rangeOf(visitsCount, () => fromPartial({ browser: '', date: '2022-01-01', referer: '' })), ); expect(container.querySelectorAll('.page-item')).toHaveLength(expectedAmountOfPageItems); expect(container.querySelectorAll('.disabled')).toHaveLength(expectedDisabledItems); @@ -58,7 +58,7 @@ describe('', () => { rangeOf(20, (value) => [value]), )('does not render footer when there is only one page to render', (visitsCount) => { const { container } = setUp( - rangeOf(visitsCount, () => Mock.of({ browser: '', date: '2022-01-01', referer: '' })), + rangeOf(visitsCount, () => fromPartial({ browser: '', date: '2022-01-01', referer: '' })), ); expect(container.querySelector('tfoot')).not.toBeInTheDocument(); @@ -66,7 +66,7 @@ describe('', () => { }); it('selected rows are highlighted', async () => { - const visits = rangeOf(10, () => Mock.of({ browser: '', date: '2022-01-01', referer: '' })); + const visits = rangeOf(10, () => fromPartial({ browser: '', date: '2022-01-01', referer: '' })); const { container, user } = setUp(visits, [visits[1], visits[2]]); // Initial situation @@ -86,7 +86,7 @@ describe('', () => { }); it('orders visits when column is clicked', async () => { - const { user } = setUp(rangeOf(9, (index) => Mock.of({ + const { user } = setUp(rangeOf(9, (index) => fromPartial({ browser: '', date: `2022-01-0${10 - index}`, referer: `${index}`, @@ -108,8 +108,8 @@ describe('', () => { it('filters list when writing in search box', async () => { const { user } = setUp([ - ...rangeOf(7, () => Mock.of({ browser: 'aaa', date: '2022-01-01', referer: 'aaa' })), - ...rangeOf(2, () => Mock.of({ browser: 'bbb', date: '2022-01-01', referer: 'bbb' })), + ...rangeOf(7, () => fromPartial({ browser: 'aaa', date: '2022-01-01', referer: 'aaa' })), + ...rangeOf(2, () => fromPartial({ browser: 'bbb', date: '2022-01-01', referer: 'bbb' })), ]); const searchField = screen.getByPlaceholderText('Search...'); const searchText = async (text: string) => { diff --git a/test/visits/charts/DoughnutChartLegend.test.tsx b/test/visits/charts/DoughnutChartLegend.test.tsx index 093bc161..27cac205 100644 --- a/test/visits/charts/DoughnutChartLegend.test.tsx +++ b/test/visits/charts/DoughnutChartLegend.test.tsx @@ -1,14 +1,14 @@ import { render, screen } from '@testing-library/react'; +import { fromPartial } from '@total-typescript/shoehorn'; import type { Chart, ChartDataset } from 'chart.js'; -import { Mock } from 'ts-mockery'; import { DoughnutChartLegend } from '../../../src/visits/charts/DoughnutChartLegend'; describe('', () => { const labels = ['foo', 'bar', 'baz', 'foo2', 'bar2']; const colors = ['green', 'blue', 'yellow']; const defaultColor = 'red'; - const datasets = [Mock.of({ backgroundColor: colors })]; - const chart = Mock.of({ + const datasets = [fromPartial({ backgroundColor: colors })]; + const chart = fromPartial({ config: { data: { labels, datasets }, options: { defaultColor } as any, diff --git a/test/visits/charts/LineChartCard.test.tsx b/test/visits/charts/LineChartCard.test.tsx index 622eece2..64f3af52 100644 --- a/test/visits/charts/LineChartCard.test.tsx +++ b/test/visits/charts/LineChartCard.test.tsx @@ -1,7 +1,7 @@ import { screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; +import { fromPartial } from '@total-typescript/shoehorn'; import { formatISO, subDays, subMonths, subYears } from 'date-fns'; -import { Mock } from 'ts-mockery'; import { LineChartCard } from '../../../src/visits/charts/LineChartCard'; import type { NormalizedVisit } from '../../../src/visits/types'; import { setUpCanvas } from '../../__helpers__/setUpTest'; @@ -29,7 +29,7 @@ describe('', () => { visits, expectedActiveIndex, ) => { - const { user } = setUp(visits.map((visit) => Mock.of(visit))); + const { user } = setUp(visits.map((visit) => fromPartial(visit))); await user.click(screen.getByRole('button', { name: /Group by/ })); @@ -46,8 +46,8 @@ describe('', () => { it.each([ [undefined, undefined], [[], []], - [[Mock.of({ date: '2016-04-01' })], []], - [[Mock.of({ date: '2016-04-01' })], [Mock.of({ date: '2016-04-01' })]], + [[fromPartial({ date: '2016-04-01' })], []], + [[fromPartial({ date: '2016-04-01' })], [fromPartial({ date: '2016-04-01' })]], ])('renders chart with expected data', (visits, highlightedVisits) => { const { events } = setUp(visits, highlightedVisits); @@ -57,8 +57,8 @@ describe('', () => { it('includes stats for visits with no dates if selected', async () => { const { getEvents, user } = setUp([ - Mock.of({ date: '2016-04-01' }), - Mock.of({ date: '2016-01-01' }), + fromPartial({ date: '2016-04-01' }), + fromPartial({ date: '2016-01-01' }), ]); const eventsBefore = getEvents();