mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-23 09:30:31 +03:00
Created domainRedirects reducer test
This commit is contained in:
parent
8e71b2e2b1
commit
dce1cefd49
1 changed files with 44 additions and 0 deletions
44
test/domains/reducers/domainRedirects.test.ts
Normal file
44
test/domains/reducers/domainRedirects.test.ts
Normal file
|
@ -0,0 +1,44 @@
|
|||
import { Mock } from 'ts-mockery';
|
||||
import ShlinkApiClient from '../../../src/api/services/ShlinkApiClient';
|
||||
import {
|
||||
EDIT_DOMAIN_REDIRECTS,
|
||||
EDIT_DOMAIN_REDIRECTS_ERROR,
|
||||
EDIT_DOMAIN_REDIRECTS_START,
|
||||
editDomainRedirects as editDomainRedirectsAction,
|
||||
} from '../../../src/domains/reducers/domainRedirects';
|
||||
import { ShlinkDomainRedirects } from '../../../src/api/types';
|
||||
|
||||
describe('domainRedirectsReducer', () => {
|
||||
beforeEach(jest.clearAllMocks);
|
||||
|
||||
describe('editDomainRedirects', () => {
|
||||
const domain = 'example.com';
|
||||
const redirects = Mock.all<ShlinkDomainRedirects>();
|
||||
const dispatch = jest.fn();
|
||||
const getState = jest.fn();
|
||||
const editDomainRedirects = jest.fn();
|
||||
const buildShlinkApiClient = () => Mock.of<ShlinkApiClient>({ editDomainRedirects });
|
||||
|
||||
it('dispatches error when loading domains fails', async () => {
|
||||
editDomainRedirects.mockRejectedValue(new Error('error'));
|
||||
|
||||
await editDomainRedirectsAction(buildShlinkApiClient)(domain, {})(dispatch, getState);
|
||||
|
||||
expect(dispatch).toHaveBeenCalledTimes(2);
|
||||
expect(dispatch).toHaveBeenNthCalledWith(1, { type: EDIT_DOMAIN_REDIRECTS_START });
|
||||
expect(dispatch).toHaveBeenNthCalledWith(2, { type: EDIT_DOMAIN_REDIRECTS_ERROR });
|
||||
expect(editDomainRedirects).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('dispatches domain and redirects once loaded', async () => {
|
||||
editDomainRedirects.mockResolvedValue(redirects);
|
||||
|
||||
await editDomainRedirectsAction(buildShlinkApiClient)(domain, {})(dispatch, getState);
|
||||
|
||||
expect(dispatch).toHaveBeenCalledTimes(2);
|
||||
expect(dispatch).toHaveBeenNthCalledWith(1, { type: EDIT_DOMAIN_REDIRECTS_START });
|
||||
expect(dispatch).toHaveBeenNthCalledWith(2, { type: EDIT_DOMAIN_REDIRECTS, domain, redirects });
|
||||
expect(editDomainRedirects).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue