mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-03-11 01:53:51 +00:00
Moved short URL detail reducer to short-urls module
This commit is contained in:
@@ -6,7 +6,7 @@ import { match } from 'react-router'; // eslint-disable-line @typescript-eslint/
|
||||
import ShortUrlVisits, { ShortUrlVisitsProps } from '../../src/visits/ShortUrlVisits';
|
||||
import ShortUrlVisitsHeader from '../../src/visits/ShortUrlVisitsHeader';
|
||||
import { ShortUrlVisits as ShortUrlVisitsState } from '../../src/visits/reducers/shortUrlVisits';
|
||||
import { ShortUrlDetail } from '../../src/visits/reducers/shortUrlDetail';
|
||||
import { ShortUrlDetail } from '../../src/short-urls/reducers/shortUrlDetail';
|
||||
import VisitsStats from '../../src/visits/VisitsStats';
|
||||
import { MercureBoundProps } from '../../src/mercure/helpers/boundToMercureHub';
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import Moment from 'react-moment';
|
||||
import { ExternalLink } from 'react-external-link';
|
||||
import { Mock } from 'ts-mockery';
|
||||
import ShortUrlVisitsHeader from '../../src/visits/ShortUrlVisitsHeader';
|
||||
import { ShortUrlDetail } from '../../src/visits/reducers/shortUrlDetail';
|
||||
import { ShortUrlDetail } from '../../src/short-urls/reducers/shortUrlDetail';
|
||||
import { ShortUrlVisits } from '../../src/visits/reducers/shortUrlVisits';
|
||||
|
||||
describe('<ShortUrlVisitsHeader />', () => {
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
import { Mock } from 'ts-mockery';
|
||||
import reducer, {
|
||||
getShortUrlDetail,
|
||||
GET_SHORT_URL_DETAIL_START,
|
||||
GET_SHORT_URL_DETAIL_ERROR,
|
||||
GET_SHORT_URL_DETAIL,
|
||||
ShortUrlDetailAction,
|
||||
} from '../../../src/visits/reducers/shortUrlDetail';
|
||||
import { ShortUrl } from '../../../src/short-urls/data';
|
||||
import ShlinkApiClient from '../../../src/api/services/ShlinkApiClient';
|
||||
import { ShlinkState } from '../../../src/container/types';
|
||||
|
||||
describe('shortUrlDetailReducer', () => {
|
||||
describe('reducer', () => {
|
||||
const action = (type: string) => Mock.of<ShortUrlDetailAction>({ type });
|
||||
|
||||
it('returns loading on GET_SHORT_URL_DETAIL_START', () => {
|
||||
const state = reducer({ loading: false, error: false }, action(GET_SHORT_URL_DETAIL_START));
|
||||
const { loading } = state;
|
||||
|
||||
expect(loading).toEqual(true);
|
||||
});
|
||||
|
||||
it('stops loading and returns error on GET_SHORT_URL_DETAIL_ERROR', () => {
|
||||
const state = reducer({ loading: true, error: false }, action(GET_SHORT_URL_DETAIL_ERROR));
|
||||
const { loading, error } = state;
|
||||
|
||||
expect(loading).toEqual(false);
|
||||
expect(error).toEqual(true);
|
||||
});
|
||||
|
||||
it('return short URL on GET_SHORT_URL_DETAIL', () => {
|
||||
const actionShortUrl = Mock.of<ShortUrl>({ longUrl: 'foo', shortCode: 'bar' });
|
||||
const state = reducer({ loading: true, error: false }, { type: GET_SHORT_URL_DETAIL, shortUrl: actionShortUrl });
|
||||
const { loading, error, shortUrl } = state;
|
||||
|
||||
expect(loading).toEqual(false);
|
||||
expect(error).toEqual(false);
|
||||
expect(shortUrl).toEqual(actionShortUrl);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getShortUrlDetail', () => {
|
||||
const buildApiClientMock = (returned: Promise<ShortUrl>) => Mock.of<ShlinkApiClient>({
|
||||
getShortUrl: jest.fn(async () => returned),
|
||||
});
|
||||
const dispatchMock = jest.fn();
|
||||
const getState = () => Mock.of<ShlinkState>();
|
||||
|
||||
beforeEach(() => dispatchMock.mockReset());
|
||||
|
||||
it('dispatches start and error when promise is rejected', async () => {
|
||||
const ShlinkApiClient = buildApiClientMock(Promise.reject());
|
||||
|
||||
await getShortUrlDetail(() => ShlinkApiClient)('abc123', '')(dispatchMock, getState);
|
||||
|
||||
expect(dispatchMock).toHaveBeenCalledTimes(2);
|
||||
expect(dispatchMock).toHaveBeenNthCalledWith(1, { type: GET_SHORT_URL_DETAIL_START });
|
||||
expect(dispatchMock).toHaveBeenNthCalledWith(2, { type: GET_SHORT_URL_DETAIL_ERROR });
|
||||
expect(ShlinkApiClient.getShortUrl).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('dispatches start and success when promise is resolved', async () => {
|
||||
const resolvedShortUrl = Mock.of<ShortUrl>({ longUrl: 'foo', shortCode: 'bar' });
|
||||
const ShlinkApiClient = buildApiClientMock(Promise.resolve(resolvedShortUrl));
|
||||
|
||||
await getShortUrlDetail(() => ShlinkApiClient)('abc123', '')(dispatchMock, getState);
|
||||
|
||||
expect(dispatchMock).toHaveBeenCalledTimes(2);
|
||||
expect(dispatchMock).toHaveBeenNthCalledWith(1, { type: GET_SHORT_URL_DETAIL_START });
|
||||
expect(dispatchMock).toHaveBeenNthCalledWith(2, { type: GET_SHORT_URL_DETAIL, shortUrl: resolvedShortUrl });
|
||||
expect(ShlinkApiClient.getShortUrl).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user