mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-04-20 13:36:20 +00:00
Migrated tagVisits reducer to RTK
This commit is contained in:
@@ -1,48 +0,0 @@
|
||||
import { Action } from 'redux';
|
||||
import { buildReducer } from '../../../src/utils/helpers/redux';
|
||||
|
||||
describe('redux', () => {
|
||||
beforeEach(jest.clearAllMocks);
|
||||
|
||||
describe('buildReducer', () => {
|
||||
const fooActionHandler = jest.fn(() => 'foo result');
|
||||
const barActionHandler = jest.fn(() => 'bar result');
|
||||
const initialState = 'initial state';
|
||||
let reducer: Function;
|
||||
|
||||
beforeEach(() => {
|
||||
reducer = buildReducer<string, Action>({
|
||||
foo: fooActionHandler,
|
||||
bar: barActionHandler,
|
||||
}, initialState);
|
||||
});
|
||||
|
||||
it('returns a reducer which returns initial state when provided with unknown action', () => {
|
||||
expect(reducer(undefined, { type: 'unknown action' })).toEqual(initialState);
|
||||
expect(fooActionHandler).not.toHaveBeenCalled();
|
||||
expect(barActionHandler).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it.each([
|
||||
['foo', 'foo result', fooActionHandler, barActionHandler],
|
||||
['bar', 'bar result', barActionHandler, fooActionHandler],
|
||||
])(
|
||||
'returns a reducer which calls corresponding action handler',
|
||||
(type, expected, invokedActionHandler, notInvokedActionHandler) => {
|
||||
expect(reducer(undefined, { type })).toEqual(expected);
|
||||
expect(invokedActionHandler).toHaveBeenCalled();
|
||||
expect(notInvokedActionHandler).not.toHaveBeenCalled();
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
[undefined, initialState],
|
||||
['foo', 'foo'],
|
||||
['something', 'something'],
|
||||
])('returns a reducer which calls action handler with provided state or initial', (state, expected) => {
|
||||
reducer(state, { type: 'foo' });
|
||||
|
||||
expect(fooActionHandler).toHaveBeenCalledWith(expected, expect.anything());
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user