Skip to content

Commit

Permalink
Added test (confirm.spec.js) for Redux Reducer file( confirm.js) (#5556)
Browse files Browse the repository at this point in the history
Part of #2082
  • Loading branch information
shruti862 authored Jan 5, 2024
1 parent 86ac0a2 commit d13f381
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions test/reducers/confirm.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import deepFreeze from 'deep-freeze';
import ui from '../../app/assets/javascripts/reducers/confirm';
import { CONFIRMATION_INITIATED, ACTION_CONFIRMED, ACTION_CANCELLED } from '../../app/assets/javascripts/constants';
import '../testHelper';

const initialState = {
explanation: null,
confirmationActive: false,
confirmMessage: null,
onConfirm: null,
showInput: false,
warningMessage: null,
};

describe('article_details reducer', () => {
test('should handle CONFIRMATION_INITIATED action by updating state', () => {
const action = {
type: CONFIRMATION_INITIATED,
explanation: 'Test explanation',
confirmationActive: true,
confirmMessage: 'Test confirm message',
onConfirm: jest.fn(),
showInput: true,
warningMessage: 'Test warning message',
};

const expectedState = {
explanation: 'Test explanation',
confirmationActive: true,
confirmMessage: 'Test confirm message',
onConfirm: expect.any(Function), // You can use expect.any(Function) for functions
showInput: true,
warningMessage: 'Test warning message',
};
deepFreeze(initialState);
const newState = ui(initialState, action);

expect(newState).toEqual(expectedState);
});

test('should handle ACTION_CONFIRMED action by resetting to initial state', () => {
const action = {
type: ACTION_CONFIRMED,
};

deepFreeze(initialState);
const expectedState = initialState;
const newState = ui(initialState, action);
expect(newState).toEqual(ui(undefined, expectedState));
});

test('should handle ACTION_CANCELLED action by resetting to initial state', () => {
const action = {
type: ACTION_CANCELLED,
};

deepFreeze(initialState);
const expectedState = initialState;
const newState = ui(initialState, action);
expect(newState).toEqual(ui(undefined, expectedState));
});
});

0 comments on commit d13f381

Please sign in to comment.