Extract shlink-web-component outside of src folder

This commit is contained in:
Alejandro Celaya
2023-07-24 20:14:59 +02:00
parent 768fb1992f
commit 3a0cea1268
230 changed files with 485 additions and 524 deletions

View File

@@ -1,8 +1,8 @@
import { screen, waitFor } from '@testing-library/react';
import { fromPartial } from '@total-typescript/shoehorn';
import { MemoryRouter } from 'react-router-dom';
import type { MercureInfo } from '../../src/shlink-web-component/mercure/reducers/mercureInfo';
import { Overview as overviewCreator } from '../../src/shlink-web-component/overview/Overview';
import type { MercureInfo } from '../../shlink-web-component/mercure/reducers/mercureInfo';
import { Overview as overviewCreator } from '../../shlink-web-component/overview/Overview';
import { prettify } from '../../src/utils/helpers/numbers';
import { renderWithEvents } from '../__helpers__/setUpTest';

View File

@@ -1,8 +1,8 @@
import { screen, waitFor } from '@testing-library/react';
import type { ReactNode } from 'react';
import { MemoryRouter } from 'react-router-dom';
import type { HighlightCardProps } from '../../../src/shlink-web-component/overview/helpers/HighlightCard';
import { HighlightCard } from '../../../src/shlink-web-component/overview/helpers/HighlightCard';
import type { HighlightCardProps } from '../../../shlink-web-component/overview/helpers/HighlightCard';
import { HighlightCard } from '../../../shlink-web-component/overview/helpers/HighlightCard';
import { renderWithEvents } from '../../__helpers__/setUpTest';
describe('<HighlightCard />', () => {

View File

@@ -1,6 +1,6 @@
import { screen, waitFor } from '@testing-library/react';
import type { VisitsHighlightCardProps } from '../../../src/shlink-web-component/overview/helpers/VisitsHighlightCard';
import { VisitsHighlightCard } from '../../../src/shlink-web-component/overview/helpers/VisitsHighlightCard';
import type { VisitsHighlightCardProps } from '../../../shlink-web-component/overview/helpers/VisitsHighlightCard';
import { VisitsHighlightCard } from '../../../shlink-web-component/overview/helpers/VisitsHighlightCard';
import { renderWithEvents } from '../../__helpers__/setUpTest';
describe('<VisitsHighlightCard />', () => {

View File

@@ -2,14 +2,13 @@ import { fromPartial } from '@total-typescript/shoehorn';
import { v4 as uuid } from 'uuid';
import type { ShlinkApiClient } from '../../../src/api/services/ShlinkApiClient';
import type { ShlinkState } from '../../../src/container/types';
import type { NonReachableServer, NotFoundServer, ReachableServer, RegularServer } from '../../../src/servers/data';
import type { NonReachableServer, NotFoundServer, RegularServer } from '../../../src/servers/data';
import {
MAX_FALLBACK_VERSION,
MIN_FALLBACK_VERSION,
resetSelectedServer,
selectedServerReducerCreator,
selectServer as selectServerCreator,
selectServerListener,
} from '../../../src/servers/reducers/selectedServer';
describe('selectedServerReducer', () => {
@@ -85,34 +84,4 @@ describe('selectedServerReducer', () => {
expect(dispatch).toHaveBeenLastCalledWith(expect.objectContaining({ payload: expectedSelectedServer }));
});
});
describe('selectServerListener', () => {
const getState = vi.fn(() => ({}));
const loadMercureInfo = vi.fn();
const { middleware } = selectServerListener(selectServer, loadMercureInfo);
it.each([
[fromPartial<ReachableServer>({ version: '1.2.3' }), 1],
[fromPartial<NotFoundServer>({ serverNotFound: true }), 0],
[fromPartial<NonReachableServer>({ serverNotReachable: true }), 0],
])('dispatches loadMercureInfo when provided server is reachable', (payload, expectedCalls) => {
middleware({ dispatch, getState })(vi.fn())({
payload,
type: selectServer.fulfilled.toString(),
});
expect(dispatch).toHaveBeenCalledTimes(expectedCalls);
expect(loadMercureInfo).toHaveBeenCalledTimes(expectedCalls);
});
it('does not dispatch loadMercureInfo when action is not of the proper type', () => {
middleware({ dispatch, getState })(vi.fn())({
payload: fromPartial<ReachableServer>({ version: '1.2.3' }),
type: 'something_else',
});
expect(dispatch).not.toHaveBeenCalled();
expect(loadMercureInfo).not.toHaveBeenCalled();
});
});
});