123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- import { reducerTester } from '../../../../test/core/redux/reducerTester';
- import { TransactionStatus } from '../types';
- import {
- initialKeyedVariablesState,
- keyedVariablesReducer,
- KeyedVariablesState,
- toKeyedAction,
- } from './keyedVariablesReducer';
- import { getInitialTemplatingState } from './reducers';
- import { initialTransactionState, variablesCompleteTransaction, variablesInitTransaction } from './transactionReducer';
- describe('dashboardVariablesReducer', () => {
- describe('when an toUidAction is dispatched', () => {
- it('then state should be correct', () => {
- const key = 'key';
- reducerTester<KeyedVariablesState>()
- .givenReducer(keyedVariablesReducer, {
- ...initialKeyedVariablesState,
- lastKey: key,
- keys: {
- [key]: {
- ...getInitialTemplatingState(),
- transaction: {
- ...initialTransactionState,
- uid: key,
- },
- },
- },
- })
- .whenActionIsDispatched(toKeyedAction(key, variablesCompleteTransaction({ uid: key })))
- .thenStateShouldEqual({
- ...initialKeyedVariablesState,
- lastKey: key,
- keys: {
- [key]: {
- ...getInitialTemplatingState(),
- transaction: {
- ...initialTransactionState,
- uid: key,
- status: TransactionStatus.Completed,
- },
- },
- },
- });
- });
- });
- describe('when an toUidAction with variablesInitTransaction is dispatched', () => {
- it('then lastUid property should be correct', () => {
- const lastUid = 'lastUid';
- const key = 'key';
- reducerTester<KeyedVariablesState>()
- .givenReducer(keyedVariablesReducer, {
- ...initialKeyedVariablesState,
- lastKey: lastUid,
- keys: {
- [lastUid]: {
- ...getInitialTemplatingState(),
- transaction: {
- ...initialTransactionState,
- uid: lastUid,
- status: TransactionStatus.Completed,
- },
- },
- },
- })
- .whenActionIsDispatched(toKeyedAction(key, variablesInitTransaction({ uid: key })))
- .thenStateShouldEqual({
- ...initialKeyedVariablesState,
- lastKey: key,
- keys: {
- [key]: {
- ...getInitialTemplatingState(),
- transaction: {
- ...initialTransactionState,
- uid: key,
- status: TransactionStatus.Fetching,
- },
- },
- [lastUid]: {
- ...getInitialTemplatingState(),
- transaction: {
- ...initialTransactionState,
- uid: lastUid,
- status: TransactionStatus.Completed,
- },
- },
- },
- });
- });
- });
- describe('when action other than toUidAction is dispatched', () => {
- it('then state should not be affected', () => {
- const key = 'key';
- reducerTester<KeyedVariablesState>()
- .givenReducer(keyedVariablesReducer, {
- ...initialKeyedVariablesState,
- lastKey: key,
- keys: {
- [key]: {
- ...getInitialTemplatingState(),
- transaction: {
- ...initialTransactionState,
- uid: key,
- status: TransactionStatus.Completed,
- },
- },
- },
- })
- .whenActionIsDispatched(variablesInitTransaction({ uid: 'newUid' }))
- .thenStateShouldEqual({
- ...initialKeyedVariablesState,
- lastKey: key,
- keys: {
- [key]: {
- ...getInitialTemplatingState(),
- transaction: {
- ...initialTransactionState,
- uid: key,
- status: TransactionStatus.Completed,
- },
- },
- },
- });
- });
- });
- });
|