mirror of
https://github.com/weaveworks/scope.git
synced 2026-08-18 03:46:45 +00:00
unit test added
This commit is contained in:
@@ -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 (
|
||||
<div className="topology-option" key={optionId}>
|
||||
<div className="topology-option-wrapper">
|
||||
{option.get('options').map(item => <TopologyOptionAction
|
||||
optionId={optionId} topologyId={topologyId} key={item.get('value')}
|
||||
activeValue={activeValue} item={item} />)}
|
||||
{option.get('options').map(item => (
|
||||
<TopologyOptionAction
|
||||
optionId={optionId}
|
||||
topologyId={topologyId}
|
||||
key={item.get('value')}
|
||||
activeValue={activeValue}
|
||||
item={item}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user