mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-04-20 13:36:20 +00:00
Fix shlink-web-component tests
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { fromPartial } from '@total-typescript/shoehorn';
|
||||
import type { ShlinkApiClient } from '../../../../src/api/services/ShlinkApiClient';
|
||||
import type { GetState } from '../../../../src/container/types';
|
||||
import type { Settings } from '../../../src';
|
||||
import type { ShlinkApiClient } from '../../../src/api-contract';
|
||||
import { mercureInfoReducerCreator } from '../../../src/mercure/reducers/mercureInfo';
|
||||
|
||||
describe('mercureInfoReducer', () => {
|
||||
@@ -14,21 +14,21 @@ describe('mercureInfoReducer', () => {
|
||||
|
||||
describe('reducer', () => {
|
||||
it('returns loading on GET_MERCURE_INFO_START', () => {
|
||||
expect(reducer(undefined, loadMercureInfo.pending(''))).toEqual({
|
||||
expect(reducer(undefined, loadMercureInfo.pending('', {}))).toEqual({
|
||||
loading: true,
|
||||
error: false,
|
||||
});
|
||||
});
|
||||
|
||||
it('returns error on GET_MERCURE_INFO_ERROR', () => {
|
||||
expect(reducer(undefined, loadMercureInfo.rejected(null, ''))).toEqual({
|
||||
expect(reducer(undefined, loadMercureInfo.rejected(null, '', {}))).toEqual({
|
||||
loading: false,
|
||||
error: true,
|
||||
});
|
||||
});
|
||||
|
||||
it('returns mercure info on GET_MERCURE_INFO', () => {
|
||||
expect(reducer(undefined, loadMercureInfo.fulfilled(mercureInfo, ''))).toEqual(
|
||||
expect(reducer(undefined, loadMercureInfo.fulfilled(mercureInfo, '', {}))).toEqual(
|
||||
expect.objectContaining({ ...mercureInfo, loading: false, error: false }),
|
||||
);
|
||||
});
|
||||
@@ -36,17 +36,15 @@ describe('mercureInfoReducer', () => {
|
||||
|
||||
describe('loadMercureInfo', () => {
|
||||
const dispatch = vi.fn();
|
||||
const createGetStateMock = (enabled: boolean): GetState => vi.fn().mockReturnValue({
|
||||
settings: {
|
||||
realTimeUpdates: { enabled },
|
||||
},
|
||||
const createSettings = (enabled: boolean): Settings => fromPartial({
|
||||
realTimeUpdates: { enabled },
|
||||
});
|
||||
|
||||
it('dispatches error when real time updates are disabled', async () => {
|
||||
getMercureInfo.mockResolvedValue(mercureInfo);
|
||||
const getState = createGetStateMock(false);
|
||||
const settings = createSettings(false);
|
||||
|
||||
await loadMercureInfo()(dispatch, getState, {});
|
||||
await loadMercureInfo(settings)(dispatch, vi.fn(), {});
|
||||
|
||||
expect(getMercureInfo).not.toHaveBeenCalled();
|
||||
expect(dispatch).toHaveBeenCalledTimes(2);
|
||||
@@ -57,9 +55,9 @@ describe('mercureInfoReducer', () => {
|
||||
|
||||
it('calls API on success', async () => {
|
||||
getMercureInfo.mockResolvedValue(mercureInfo);
|
||||
const getState = createGetStateMock(true);
|
||||
const settings = createSettings(true);
|
||||
|
||||
await loadMercureInfo()(dispatch, getState, {});
|
||||
await loadMercureInfo(settings)(dispatch, vi.fn(), {});
|
||||
|
||||
expect(getMercureInfo).toHaveBeenCalledTimes(1);
|
||||
expect(dispatch).toHaveBeenCalledTimes(2);
|
||||
|
||||
Reference in New Issue
Block a user