Skip to content

Commit

Permalink
[Resolver] Remove useless check that breaks when tree has no nodes (e…
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Austin authored Jul 29, 2020
1 parent 58d97f5 commit a5e1720
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
mockTreeWith2AncestorsAndNoChildren,
mockTreeWith1AncestorAnd2ChildrenAndAllNodesHave2GraphableEvents,
mockTreeWithAllProcessesTerminated,
mockTreeWithNoProcessEvents,
} from '../mocks/resolver_tree';
import { uniquePidForProcess } from '../../models/process_event';
import { EndpointEvent } from '../../../../common/endpoint/types';
Expand Down Expand Up @@ -408,4 +409,26 @@ describe('data state', () => {
expect(selectors.graphableProcesses(state()).length).toBe(4);
});
});
describe('with a tree with no process events', () => {
beforeEach(() => {
const tree = mockTreeWithNoProcessEvents();
actions.push({
type: 'serverReturnedResolverData',
payload: {
result: tree,
// this value doesn't matter
databaseDocumentID: '',
},
});
});
it('should return an empty layout', () => {
expect(selectors.layout(state())).toMatchInlineSnapshot(`
Object {
"ariaLevels": Map {},
"edgeLineSegments": Array [],
"processNodePositions": Map {},
}
`);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,9 @@ export const layout = createSelector(
// find the origin node
const originNode = indexedProcessTreeModel.processEvent(indexedProcessTree, originID);

if (!originNode) {
// this should only happen if the `ResolverTree` from the server has an entity ID with no matching lifecycle events.
throw new Error('Origin node not found in ResolverTree');
if (originNode === null) {
// If a tree is returned that has no process events for the origin, this can happen.
return taxiLayout;
}

// Find the position of the origin, we'll center the map on it intrinsically
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,33 @@ export function mockTreeWith1AncestorAnd2ChildrenAndAllNodesHave2GraphableEvents
lifecycle: [origin, originClone],
} as unknown) as ResolverTree;
}

export function mockTreeWithNoProcessEvents(): ResolverTree {
return {
entityID: 'entityID',
children: {
childNodes: [],
nextChild: null,
},
relatedEvents: {
events: [],
nextEvent: null,
},
relatedAlerts: {
alerts: [],
nextAlert: null,
},
lifecycle: [],
ancestry: {
ancestors: [],
nextAncestor: null,
},
stats: {
totalAlerts: 0,
events: {
total: 0,
byCategory: {},
},
},
};
}

0 comments on commit a5e1720

Please sign in to comment.