From 0b5a886fc66bd0c10457d65390b380f14920174a Mon Sep 17 00:00:00 2001 From: ravi-kumar-pilla Date: Tue, 14 May 2024 18:06:47 -0500 Subject: [PATCH] update tests Signed-off-by: ravi-kumar-pilla --- src/actions/actions.test.js | 15 ++++++++++++++- src/reducers/reducers.test.js | 11 +++++++++++ src/store/initial-state.test.js | 15 ++++++++++++++- src/utils/utils.test.js | 18 ++++++++++++++++++ 4 files changed, 57 insertions(+), 2 deletions(-) diff --git a/src/actions/actions.test.js b/src/actions/actions.test.js index 4778ed741b..fde1e1b162 100644 --- a/src/actions/actions.test.js +++ b/src/actions/actions.test.js @@ -16,6 +16,7 @@ import { TOGGLE_CODE, TOGGLE_MODULAR_PIPELINE_FOCUS_MODE, TOGGLE_HOVERED_FOCUS_MODE, + TOGGLE_EXPAND_ALL_PIPELINES, changeFlag, resetData, toggleIgnoreLargeWarning, @@ -32,6 +33,7 @@ import { updateChartSize, toggleFocusMode, toggleHoveredFocusMode, + toggleExpandAllPipelines, } from '../actions'; import { TOGGLE_NODE_CLICKED, @@ -75,7 +77,18 @@ describe('actions', () => { expect(toggleLayers(visible)).toEqual(expectedAction); }); - it('should create an action to toggle whether to show layers', () => { + it('should create an action to toggle whether to expand all modular pipelines or collapse', () => { + const shouldExpandAllPipelines = false; + const expectedAction = { + type: TOGGLE_EXPAND_ALL_PIPELINES, + shouldExpandAllPipelines, + }; + expect(toggleExpandAllPipelines(shouldExpandAllPipelines)).toEqual( + expectedAction + ); + }); + + it('should create an action to toggle whether to show minimap', () => { const visible = false; const expectedAction = { type: TOGGLE_MINIMAP, diff --git a/src/reducers/reducers.test.js b/src/reducers/reducers.test.js index 48aeeb0409..5778001bff 100644 --- a/src/reducers/reducers.test.js +++ b/src/reducers/reducers.test.js @@ -19,6 +19,7 @@ import { TOGGLE_THEME, UPDATE_CHART_SIZE, TOGGLE_HOVERED_FOCUS_MODE, + TOGGLE_EXPAND_ALL_PIPELINES, } from '../actions'; import { TOGGLE_NODE_CLICKED, @@ -241,6 +242,16 @@ describe('Reducer', () => { }); }); + describe('TOGGLE_EXPAND_ALL_PIPELINES', () => { + it('should toggle whether to expand all modular pipelines or collapse', () => { + const newState = reducer(mockState.spaceflights, { + type: TOGGLE_EXPAND_ALL_PIPELINES, + shouldExpandAllPipelines: true, + }); + expect(newState.expandAllPipelines).toEqual(true); + }); + }); + describe('TOGGLE_SIDEBAR', () => { it('should toggle whether the sidebar is open', () => { const newState = reducer(mockState.spaceflights, { diff --git a/src/store/initial-state.test.js b/src/store/initial-state.test.js index 56b3458e93..2ac6a3fb5f 100644 --- a/src/store/initial-state.test.js +++ b/src/store/initial-state.test.js @@ -20,6 +20,7 @@ describe('mergeLocalStorage', () => { textLabels: false, theme: 'light', tag: { enabled: 'medium' }, + expandAllPipelines: true, }; saveLocalStorage(localStorageName, localStorageValues); expect( @@ -27,6 +28,7 @@ describe('mergeLocalStorage', () => { textLabels: true, theme: 'dark', tag: { enabled: 'large' }, + expandAllPipelines: false, }) ).toMatchObject(localStorageValues); window.localStorage.clear(); @@ -70,10 +72,13 @@ describe('preparePipelineState', () => { describe('prepareNonPipelineState', () => { it('applies localStorage values on top of initial state', () => { - const localStorageState = { theme: 'foo' }; + const localStorageState = { theme: 'foo', expandAllPipelines: true }; saveLocalStorage(localStorageName, localStorageState); const state = prepareNonPipelineState({}); expect(state.theme).toEqual(localStorageState.theme); + expect(state.expandAllPipelines).toEqual( + localStorageState.expandAllPipelines + ); window.localStorage.clear(); }); @@ -101,6 +106,13 @@ describe('prepareNonPipelineState', () => { prepareNonPipelineState({ data: spaceflights, ...props }) ).toMatchObject(props); }); + + it('overrides expandAllPipelines with values from URL', () => { + // In this case, location.href is not provided + expect(prepareNonPipelineState({ data: spaceflights })).toMatchObject({ + expandAllPipelines: expect.any(Boolean), + }); + }); }); describe('getInitialState', () => { @@ -119,6 +131,7 @@ describe('getInitialState', () => { chartSize: {}, textLabels: true, theme: 'dark', + expandAllPipelines: false, visible: { exportBtn: true, labelBtn: true, diff --git a/src/utils/utils.test.js b/src/utils/utils.test.js index 9f6c565a0c..d63b9f3e55 100644 --- a/src/utils/utils.test.js +++ b/src/utils/utils.test.js @@ -4,6 +4,7 @@ import { unique, replaceMatches, replaceAngleBracketMatches, + isValidBoolean, } from './index'; describe('utils', () => { @@ -77,4 +78,21 @@ describe('utils', () => { expect(replaceAngleBracketMatches('')).toEqual('<lambda>'); }); }); + + describe('isValidBoolean', () => { + it('validates if the inputString is valid boolean', () => { + // Valid booleans + expect(isValidBoolean('true')).toEqual(true); + expect(isValidBoolean('false')).toEqual(true); + expect(isValidBoolean(true)).toEqual(true); + expect(isValidBoolean(false)).toEqual(true); + + // Invalid booleans + expect(isValidBoolean('0')).toEqual(false); + expect(isValidBoolean('undefined')).toEqual(false); + expect(isValidBoolean(undefined)).toEqual(false); + expect(isValidBoolean('trueTesting')).toEqual(false); + expect(isValidBoolean('Testingfalse')).toEqual(false); + }); + }); });