Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
Signed-off-by: ravi-kumar-pilla <[email protected]>
  • Loading branch information
ravi-kumar-pilla committed May 14, 2024
1 parent 478031a commit 0b5a886
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/actions/actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
TOGGLE_CODE,
TOGGLE_MODULAR_PIPELINE_FOCUS_MODE,
TOGGLE_HOVERED_FOCUS_MODE,
TOGGLE_EXPAND_ALL_PIPELINES,
changeFlag,
resetData,
toggleIgnoreLargeWarning,
Expand All @@ -32,6 +33,7 @@ import {
updateChartSize,
toggleFocusMode,
toggleHoveredFocusMode,
toggleExpandAllPipelines,
} from '../actions';
import {
TOGGLE_NODE_CLICKED,
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions src/reducers/reducers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
TOGGLE_THEME,
UPDATE_CHART_SIZE,
TOGGLE_HOVERED_FOCUS_MODE,
TOGGLE_EXPAND_ALL_PIPELINES,
} from '../actions';
import {
TOGGLE_NODE_CLICKED,
Expand Down Expand Up @@ -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, {
Expand Down
15 changes: 14 additions & 1 deletion src/store/initial-state.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ describe('mergeLocalStorage', () => {
textLabels: false,
theme: 'light',
tag: { enabled: 'medium' },
expandAllPipelines: true,
};
saveLocalStorage(localStorageName, localStorageValues);
expect(
mergeLocalStorage({
textLabels: true,
theme: 'dark',
tag: { enabled: 'large' },
expandAllPipelines: false,
})
).toMatchObject(localStorageValues);
window.localStorage.clear();
Expand Down Expand Up @@ -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();
});

Expand Down Expand Up @@ -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', () => {
Expand All @@ -119,6 +131,7 @@ describe('getInitialState', () => {
chartSize: {},
textLabels: true,
theme: 'dark',
expandAllPipelines: false,
visible: {
exportBtn: true,
labelBtn: true,
Expand Down
18 changes: 18 additions & 0 deletions src/utils/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
unique,
replaceMatches,
replaceAngleBracketMatches,
isValidBoolean,
} from './index';

describe('utils', () => {
Expand Down Expand Up @@ -77,4 +78,21 @@ describe('utils', () => {
expect(replaceAngleBracketMatches('<lambda>')).toEqual('&lt;lambda&gt;');
});
});

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);
});
});
});

0 comments on commit 0b5a886

Please sign in to comment.