Skip to content

Commit

Permalink
Test reducer
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Apr 3, 2020
1 parent 408d7c3 commit 1b2a214
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Connector,
CasesConfigurationMapping,
} from '../../../../../containers/case/configure/types';
import { State } from '../reducer';

export const connectors: Connector[] = [
{
Expand Down Expand Up @@ -86,3 +87,10 @@ export const mapping: CasesConfigurationMapping[] = [

export const searchURL =
'?timerange=(global:(linkTo:!(),timerange:(from:1585487656371,fromStr:now-24h,kind:relative,to:1585574056371,toStr:now)),timeline:(linkTo:!(),timerange:(from:1585227005527,kind:absolute,to:1585313405527)))';

export const initialState: State = {
connectorId: 'none',
closureType: 'close-by-user',
mapping: null,
currentConfiguration: { connectorId: 'none', closureType: 'close-by-user' },
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { configureCasesReducer, Action, State } from './reducer';
import { initialState, mapping } from './__mock__';

describe('Reducer', () => {
let reducer: (state: State, action: Action) => State;

beforeAll(() => {
reducer = configureCasesReducer();
});

test('it should set the correct configuration', () => {
const action: Action = {
type: 'setCurrentConfiguration',
currentConfiguration: { connectorId: '123', closureType: 'close-by-user' },
};
const state = reducer(initialState, action);

expect(state).toEqual({
...state,
currentConfiguration: action.currentConfiguration,
});
});

test('it should set the correct connector id', () => {
const action: Action = {
type: 'setConnectorId',
connectorId: '456',
};
const state = reducer(initialState, action);

expect(state).toEqual({
...state,
connectorId: action.connectorId,
});
});

test('it should set the closure type', () => {
const action: Action = {
type: 'setClosureType',
closureType: 'close-by-pushing',
};
const state = reducer(initialState, action);

expect(state).toEqual({
...state,
closureType: action.closureType,
});
});

test('it should set the mapping', () => {
const action: Action = {
type: 'setMapping',
mapping,
};
const state = reducer(initialState, action);

expect(state).toEqual({
...state,
mapping: action.mapping,
});
});
});

0 comments on commit 1b2a214

Please sign in to comment.