Fix shlink-web-component tests

This commit is contained in:
Alejandro Celaya
2023-08-04 11:16:01 +02:00
parent bdcfcee60e
commit 4d8477a32c
54 changed files with 345 additions and 431 deletions

View File

@@ -1,9 +1,8 @@
import { fromPartial } from '@total-typescript/shoehorn';
import { addDays, formatISO, subDays } from 'date-fns';
import type { ShlinkApiClient } from '../../../../src/api/services/ShlinkApiClient';
import type { ShlinkState } from '../../../../src/container/types';
import { rangeOf } from '../../../../src/utils/utils';
import type { ShlinkVisits } from '../../../src/api/types';
import type { ShlinkApiClient, ShlinkVisits } from '../../../src/api-contract';
import type { RootState } from '../../../src/container/store';
import type { ShortUrl } from '../../../src/short-urls/data';
import { formatIsoDate } from '../../../src/utils/dates/helpers/date';
import type { DateInterval } from '../../../src/utils/dates/helpers/dateIntervals';
@@ -151,7 +150,7 @@ describe('domainVisitsReducer', () => {
describe('getDomainVisits', () => {
const dispatchMock = vi.fn();
const getState = () => fromPartial<ShlinkState>({
const getState = () => fromPartial<RootState>({
domainVisits: { cancelLoad: false },
});
const domain = 'foo.com';

View File

@@ -1,9 +1,8 @@
import { fromPartial } from '@total-typescript/shoehorn';
import { addDays, formatISO, subDays } from 'date-fns';
import type { ShlinkApiClient } from '../../../../src/api/services/ShlinkApiClient';
import type { ShlinkState } from '../../../../src/container/types';
import { rangeOf } from '../../../../src/utils/utils';
import type { ShlinkVisits } from '../../../src/api/types';
import type { ShlinkApiClient, ShlinkVisits } from '../../../src/api-contract';
import type { RootState } from '../../../src/container/store';
import { formatIsoDate } from '../../../src/utils/dates/helpers/date';
import type { DateInterval } from '../../../src/utils/dates/helpers/dateIntervals';
import {
@@ -118,7 +117,7 @@ describe('nonOrphanVisitsReducer', () => {
describe('getNonOrphanVisits', () => {
const dispatchMock = vi.fn();
const getState = () => fromPartial<ShlinkState>({
const getState = () => fromPartial<RootState>({
orphanVisits: { cancelLoad: false },
});

View File

@@ -1,9 +1,8 @@
import { fromPartial } from '@total-typescript/shoehorn';
import { addDays, formatISO, subDays } from 'date-fns';
import type { ShlinkApiClient } from '../../../../src/api/services/ShlinkApiClient';
import type { ShlinkState } from '../../../../src/container/types';
import { rangeOf } from '../../../../src/utils/utils';
import type { ShlinkVisits } from '../../../src/api/types';
import type { ShlinkApiClient, ShlinkVisits } from '../../../src/api-contract';
import type { RootState } from '../../../src/container/store';
import { formatIsoDate } from '../../../src/utils/dates/helpers/date';
import type { DateInterval } from '../../../src/utils/dates/helpers/dateIntervals';
import {
@@ -118,7 +117,7 @@ describe('orphanVisitsReducer', () => {
describe('getOrphanVisits', () => {
const dispatchMock = vi.fn();
const getState = () => fromPartial<ShlinkState>({
const getState = () => fromPartial<RootState>({
orphanVisits: { cancelLoad: false },
});

View File

@@ -1,9 +1,8 @@
import { fromPartial } from '@total-typescript/shoehorn';
import { addDays, formatISO, subDays } from 'date-fns';
import type { ShlinkApiClient } from '../../../../src/api/services/ShlinkApiClient';
import type { ShlinkState } from '../../../../src/container/types';
import { rangeOf } from '../../../../src/utils/utils';
import type { ShlinkVisits } from '../../../src/api/types';
import type { ShlinkApiClient, ShlinkVisits } from '../../../src/api-contract';
import type { RootState } from '../../../src/container/store';
import { formatIsoDate } from '../../../src/utils/dates/helpers/date';
import type { DateInterval } from '../../../src/utils/dates/helpers/dateIntervals';
import type {
@@ -142,7 +141,7 @@ describe('shortUrlVisitsReducer', () => {
describe('getShortUrlVisits', () => {
const dispatchMock = vi.fn();
const getState = () => fromPartial<ShlinkState>({
const getState = () => fromPartial<RootState>({
shortUrlVisits: { cancelLoad: false },
});

View File

@@ -1,9 +1,8 @@
import { fromPartial } from '@total-typescript/shoehorn';
import { addDays, formatISO, subDays } from 'date-fns';
import type { ShlinkApiClient } from '../../../../src/api/services/ShlinkApiClient';
import type { ShlinkState } from '../../../../src/container/types';
import { rangeOf } from '../../../../src/utils/utils';
import type { ShlinkVisits } from '../../../src/api/types';
import type { ShlinkApiClient, ShlinkVisits } from '../../../src/api-contract';
import type { RootState } from '../../../src/container/store';
import { formatIsoDate } from '../../../src/utils/dates/helpers/date';
import type { DateInterval } from '../../../src/utils/dates/helpers/dateIntervals';
import type {
@@ -142,7 +141,7 @@ describe('tagVisitsReducer', () => {
describe('getTagVisits', () => {
const dispatchMock = vi.fn();
const getState = () => fromPartial<ShlinkState>({
const getState = () => fromPartial<RootState>({
tagVisits: { cancelLoad: false },
});
const tag = 'foo';

View File

@@ -1,7 +1,6 @@
import { fromPartial } from '@total-typescript/shoehorn';
import type { ShlinkApiClient } from '../../../../src/api/services/ShlinkApiClient';
import type { ShlinkState } from '../../../../src/container/types';
import type { ShlinkVisitsOverview } from '../../../src/api/types';
import type { ShlinkApiClient, ShlinkVisitsOverview } from '../../../src/api-contract';
import type { RootState } from '../../../src/container/store';
import { createNewVisits } from '../../../src/visits/reducers/visitCreation';
import type {
PartialVisitsSummary,
@@ -25,7 +24,7 @@ describe('visitsOverviewReducer', () => {
it('returns loading on GET_OVERVIEW_START', () => {
const { loading } = reducer(
state({ loading: false, error: false }),
loadVisitsOverview.pending(''),
loadVisitsOverview.pending('', {}),
);
expect(loading).toEqual(true);
@@ -34,7 +33,7 @@ describe('visitsOverviewReducer', () => {
it('stops loading and returns error on GET_OVERVIEW_ERROR', () => {
const { loading, error } = reducer(
state({ loading: true, error: false }),
loadVisitsOverview.rejected(null, ''),
loadVisitsOverview.rejected(null, '', {}),
);
expect(loading).toEqual(false);
@@ -44,7 +43,7 @@ describe('visitsOverviewReducer', () => {
it('return visits overview on GET_OVERVIEW', () => {
const action = loadVisitsOverview.fulfilled(fromPartial({
nonOrphanVisits: { total: 100 },
}), 'requestId');
}), 'requestId', {});
const { loading, error, nonOrphanVisits } = reducer(state({ loading: true, error: false }), action);
expect(loading).toEqual(false);
@@ -127,7 +126,7 @@ describe('visitsOverviewReducer', () => {
describe('loadVisitsOverview', () => {
const dispatchMock = vi.fn();
const getState = () => fromPartial<ShlinkState>({});
const getState = () => fromPartial<RootState>({});
it.each([
[
@@ -155,7 +154,7 @@ describe('visitsOverviewReducer', () => {
const resolvedOverview = fromPartial<ShlinkVisitsOverview>(serverResult);
getVisitsOverview.mockResolvedValue(resolvedOverview);
await loadVisitsOverview()(dispatchMock, getState, {});
await loadVisitsOverview(buildApiClientMock)(dispatchMock, getState, {});
expect(dispatchMock).toHaveBeenCalledTimes(2);
expect(dispatchMock).toHaveBeenNthCalledWith(2, expect.objectContaining({ payload: dispatchedPayload }));