mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-10 02:07:26 +03:00
Migrated selectedServer test to typescript
This commit is contained in:
parent
294888454d
commit
3e2fee0df5
1 changed files with 10 additions and 7 deletions
|
@ -1,4 +1,5 @@
|
||||||
import { v4 as uuid } from 'uuid';
|
import { v4 as uuid } from 'uuid';
|
||||||
|
import { Mock } from 'ts-mockery';
|
||||||
import reducer, {
|
import reducer, {
|
||||||
selectServer,
|
selectServer,
|
||||||
resetSelectedServer,
|
resetSelectedServer,
|
||||||
|
@ -8,16 +9,18 @@ import reducer, {
|
||||||
MIN_FALLBACK_VERSION,
|
MIN_FALLBACK_VERSION,
|
||||||
} from '../../../src/servers/reducers/selectedServer';
|
} from '../../../src/servers/reducers/selectedServer';
|
||||||
import { RESET_SHORT_URL_PARAMS } from '../../../src/short-urls/reducers/shortUrlsListParams';
|
import { RESET_SHORT_URL_PARAMS } from '../../../src/short-urls/reducers/shortUrlsListParams';
|
||||||
|
import { ShlinkState } from '../../../src/container/types';
|
||||||
|
import { NonReachableServer, NotFoundServer } from '../../../src/servers/data';
|
||||||
|
|
||||||
describe('selectedServerReducer', () => {
|
describe('selectedServerReducer', () => {
|
||||||
describe('reducer', () => {
|
describe('reducer', () => {
|
||||||
it('returns default when action is RESET_SELECTED_SERVER', () =>
|
it('returns default when action is RESET_SELECTED_SERVER', () =>
|
||||||
expect(reducer(null, { type: RESET_SELECTED_SERVER })).toEqual(null));
|
expect(reducer(null, { type: RESET_SELECTED_SERVER } as any)).toEqual(null));
|
||||||
|
|
||||||
it('returns selected server when action is SELECT_SERVER', () => {
|
it('returns selected server when action is SELECT_SERVER', () => {
|
||||||
const selectedServer = { id: 'abc123' };
|
const selectedServer = { id: 'abc123' };
|
||||||
|
|
||||||
expect(reducer(null, { type: SELECT_SERVER, selectedServer })).toEqual(selectedServer);
|
expect(reducer(null, { type: SELECT_SERVER, selectedServer } as any)).toEqual(selectedServer);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -32,7 +35,7 @@ describe('selectedServerReducer', () => {
|
||||||
id: 'abc123',
|
id: 'abc123',
|
||||||
};
|
};
|
||||||
const version = '1.19.0';
|
const version = '1.19.0';
|
||||||
const createGetStateMock = (id) => jest.fn().mockReturnValue({ servers: { [id]: selectedServer } });
|
const createGetStateMock = (id: string) => jest.fn().mockReturnValue({ servers: { [id]: selectedServer } });
|
||||||
const apiClientMock = {
|
const apiClientMock = {
|
||||||
health: jest.fn(),
|
health: jest.fn(),
|
||||||
};
|
};
|
||||||
|
@ -70,7 +73,7 @@ describe('selectedServerReducer', () => {
|
||||||
const id = uuid();
|
const id = uuid();
|
||||||
const getState = createGetStateMock(id);
|
const getState = createGetStateMock(id);
|
||||||
|
|
||||||
await selectServer(buildApiClient, loadMercureInfo)(id)(() => {}, getState);
|
await selectServer(buildApiClient, loadMercureInfo)(id)(jest.fn(), getState);
|
||||||
|
|
||||||
expect(getState).toHaveBeenCalledTimes(1);
|
expect(getState).toHaveBeenCalledTimes(1);
|
||||||
expect(buildApiClient).toHaveBeenCalledTimes(1);
|
expect(buildApiClient).toHaveBeenCalledTimes(1);
|
||||||
|
@ -79,7 +82,7 @@ describe('selectedServerReducer', () => {
|
||||||
it('dispatches error when health endpoint fails', async () => {
|
it('dispatches error when health endpoint fails', async () => {
|
||||||
const id = uuid();
|
const id = uuid();
|
||||||
const getState = createGetStateMock(id);
|
const getState = createGetStateMock(id);
|
||||||
const expectedSelectedServer = { ...selectedServer, serverNotReachable: true };
|
const expectedSelectedServer: NonReachableServer = { ...selectedServer, serverNotReachable: true };
|
||||||
|
|
||||||
apiClientMock.health.mockRejectedValue({});
|
apiClientMock.health.mockRejectedValue({});
|
||||||
|
|
||||||
|
@ -92,8 +95,8 @@ describe('selectedServerReducer', () => {
|
||||||
|
|
||||||
it('dispatches error when server is not found', async () => {
|
it('dispatches error when server is not found', async () => {
|
||||||
const id = uuid();
|
const id = uuid();
|
||||||
const getState = jest.fn(() => ({ servers: {} }));
|
const getState = jest.fn(() => Mock.of<ShlinkState>({ servers: {} }));
|
||||||
const expectedSelectedServer = { serverNotFound: true };
|
const expectedSelectedServer: NotFoundServer = { serverNotFound: true };
|
||||||
|
|
||||||
await selectServer(buildApiClient, loadMercureInfo)(id)(dispatch, getState);
|
await selectServer(buildApiClient, loadMercureInfo)(id)(dispatch, getState);
|
||||||
|
|
Loading…
Reference in a new issue