Skip to content

Commit

Permalink
[Security Solution][Resolver] enzyme semantics (#75311)
Browse files Browse the repository at this point in the history
* remove old edgeline method on simulator

* [Security Solution][Resolver] Enzyme test treeitem/tree roles
  • Loading branch information
bkimmel committed Aug 19, 2020
1 parent fb2cac9 commit 7ac929b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,6 @@ export class Simulator {
return this.wrapper.debug();
}

/**
* Lines that connect the nodes in the graph
*/
public edgeLines(): ReactWrapper {
return this.domNodes('[data-test-subj="resolver:graph:edgeline"]');
}

/**
* This manually runs the animation frames tied to a configurable timestamp in the future.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,32 @@ describe('Resolver, when analyzing a tree that has no ancestors and 2 children',
});
});

it('should render 3 elements with "treeitem" roles, each owned by an element with a "tree" role', async () => {
await expect(
simulator.map(() => ({
nodesOwnedByTrees: simulator.testSubject('resolver:node').filterWhere((domNode) => {
/**
* This test verifies corectness w.r.t. the tree/treeitem roles
* From W3C: `Authors MUST ensure elements with role treeitem are contained in, or owned by, an element with the role group or tree.`
*
* https://www.w3.org/TR/wai-aria-1.1/#tree
* https://www.w3.org/TR/wai-aria-1.1/#treeitem
*
* w3c defines two ways for an element to be an "owned element"
* 1. Any DOM descendant
* 2. Any element specified as a child via aria-owns
* (see: https://www.w3.org/TR/wai-aria-1.1/#dfn-owned-element)
*
* In the context of Resolver (as of this writing) nodes/treeitems are children of the tree,
* but they could be moved out of the tree, provided that the tree is given an `aria-owns`
* attribute referring to them (method 2 above).
*/
return domNode.closest('[role="tree"]').length === 1;
}).length,
}))
).toYieldEqualTo({ nodesOwnedByTrees: 3 });
});

it(`should show links to the 3 nodes (with icons) in the node list.`, async () => {
await expect(
simulator.map(() => simulator.testSubject('resolver:node-list:node-link:title').length)
Expand Down Expand Up @@ -252,7 +278,7 @@ function computedNodeBoundaries(entityID: string): AABB {
* Coordinates for where the edgelines "start"
*/
function computedEdgeStartingCoordinates(): Vector2[] {
return simulator.edgeLines().map((edge) => {
return simulator.testSubject('resolver:graph:edgeline').map((edge) => {
const { left, top } = getComputedStyle(edge.getDOMNode());
return [pxNum(left), pxNum(top)];
});
Expand All @@ -262,7 +288,7 @@ function computedEdgeStartingCoordinates(): Vector2[] {
* Coordinates for where edgelines "end" (after application of transform)
*/
function computedEdgeTerminalCoordinates(): Vector2[] {
return simulator.edgeLines().map((edge) => {
return simulator.testSubject('resolver:graph:edgeline').map((edge) => {
const { left, top, width, transform } = getComputedStyle(edge.getDOMNode());
/**
* Without the transform in the rotation, edgelines lay flat across the x-axis.
Expand Down

0 comments on commit 7ac929b

Please sign in to comment.