From 828d50fba06373b6c70ddf788b8c02cf76e78c7d Mon Sep 17 00:00:00 2001 From: jpellizzari Date: Tue, 21 Mar 2017 16:41:05 -0700 Subject: [PATCH] unit test added --- .../scripts/components/topology-options.js | 15 +- .../scripts/reducers/__tests__/root-test.js | 158 +++++++++++++++--- client/app/scripts/reducers/root.js | 3 +- 3 files changed, 146 insertions(+), 30 deletions(-) diff --git a/client/app/scripts/components/topology-options.js b/client/app/scripts/components/topology-options.js index 2c572060a..4d7210211 100644 --- a/client/app/scripts/components/topology-options.js +++ b/client/app/scripts/components/topology-options.js @@ -11,14 +11,21 @@ class TopologyOptions extends React.Component { const { activeOptions, topologyId } = this.props; const optionId = option.get('id'); const activeValue = activeOptions && activeOptions.has(optionId) - ? activeOptions.get(optionId) : option.get('defaultValue'); + ? activeOptions.get(optionId) + : option.get('defaultValue'); return (
- {option.get('options').map(item => )} + {option.get('options').map(item => ( + + ))}
); diff --git a/client/app/scripts/reducers/__tests__/root-test.js b/client/app/scripts/reducers/__tests__/root-test.js index 58441f5f2..ccefa0827 100644 --- a/client/app/scripts/reducers/__tests__/root-test.js +++ b/client/app/scripts/reducers/__tests__/root-test.js @@ -46,33 +46,118 @@ describe('RootReducer', () => { } }; - const topologies = [{ - hide_if_empty: true, - name: 'Processes', - rank: 1, - sub_topologies: [], - url: '/api/topology/processes', - fullName: 'Processes', - id: 'processes', - options: [ - { - defaultValue: 'hide', - id: 'unconnected', - options: [ - { - label: 'Unconnected nodes hidden', - value: 'hide' - } - ] + const topologies = [ + { + hide_if_empty: true, + name: 'Processes', + rank: 1, + sub_topologies: [], + url: '/api/topology/processes', + fullName: 'Processes', + id: 'processes', + options: [ + { + defaultValue: 'hide', + id: 'unconnected', + selectType: 'one', + options: [ + { + label: 'Unconnected nodes hidden', + value: 'hide' + } + ] + } + ], + stats: { + edge_count: 379, + filtered_nodes: 214, + node_count: 320, + nonpseudo_node_count: 320 } - ], - stats: { - edge_count: 379, - filtered_nodes: 214, - node_count: 320, - nonpseudo_node_count: 320 + }, + { + hide_if_empty: true, + name: 'Pods', + options: [ + { + defaultValue: 'default', + id: 'namespace', + selectType: 'many', + options: [ + { + label: 'monitoring', + value: 'monitoring' + }, + { + label: 'scope', + value: 'scope' + }, + { + label: 'All Namespaces', + value: 'all' + } + ] + }, + { + defaultValue: 'hide', + id: 'pseudo', + options: [ + { + label: 'Show Unmanaged', + value: 'show' + }, + { + label: 'Hide Unmanaged', + value: 'hide' + } + ] + } + ], + rank: 3, + stats: { + edge_count: 15, + filtered_nodes: 16, + node_count: 32, + nonpseudo_node_count: 27 + }, + sub_topologies: [ + { + hide_if_empty: true, + name: 'services', + options: [ + { + defaultValue: 'default', + id: 'namespace', + selectType: 'many', + options: [ + { + label: 'monitoring', + value: 'monitoring' + }, + { + label: 'scope', + value: 'scope' + }, + { + label: 'All Namespaces', + value: 'all' + } + ] + } + ], + rank: 0, + stats: { + edge_count: 14, + filtered_nodes: 16, + node_count: 159, + nonpseudo_node_count: 154 + }, + url: '/api/topology/services' + } + ], + url: '/api/topology/pods' } - }]; + ]; // actions @@ -268,6 +353,29 @@ describe('RootReducer', () => { expect(activeTopologyOptionsSelector(nextState)).toBeUndefined(); expect(getUrlState(nextState).topologyOptions.topo1.option1).toBe('off'); }); + it('changes topologyOptions for selectType "many"', () => { + const action = { + type: ActionTypes.CHANGE_TOPOLOGY_OPTION, + topologyId: 'services', + option: 'namespace', + value: ['scope', 'monitoring'] + }; + let nextState = initialState; + nextState = reducer(nextState, { + type: ActionTypes.RECEIVE_TOPOLOGIES, + topologies + }); + nextState = reducer(nextState, { + type: ActionTypes.CLICK_TOPOLOGY, + topologyId: 'services' + }); + + nextState = reducer(nextState, action); + expect(activeTopologyOptionsSelector(nextState).toJS()).toEqual({ + namespace: ['scope', 'monitoring'], + pseudo: 'hide' + }); + }); it('sets topology options from route', () => { RouteAction.state = { diff --git a/client/app/scripts/reducers/root.js b/client/app/scripts/reducers/root.js index 7221a1d41..ebe271b95 100644 --- a/client/app/scripts/reducers/root.js +++ b/client/app/scripts/reducers/root.js @@ -179,7 +179,8 @@ export function rootReducer(state = initialState, action) { const topology = findTopologyById(state.get('topologies'), action.topologyId); if (topology) { const topologyId = topology.get('parentId') || topology.get('id'); - if (state.getIn(['topologyOptions', topologyId, action.option]) !== action.value) { + const currentOption = state.getIn(['topologyOptions', topologyId, action.option]); + if (currentOption !== action.value) { state = clearNodes(state); } state = state.setIn(