From 9fb11825596f35464dca8172ea34a46f94974665 Mon Sep 17 00:00:00 2001 From: Robert Austin Date: Tue, 30 Jun 2020 08:06:29 -0400 Subject: [PATCH] Resolver test coverage (#70246) (#70262) * Move AABB, Matrix3, and Vector2 modules from lib to models * Add tests for AABB * remove dead code --- .../resolver/lib/transformation.test.ts | 2 +- .../public/resolver/lib/tree_sequencers.ts | 14 ------ .../public/resolver/models/aabb.test.ts | 46 +++++++++++++++++++ .../public/resolver/{lib => models}/aabb.ts | 0 .../isometric_taxi_layout.ts | 2 +- .../resolver/{lib => models}/matrix3.test.ts | 0 .../resolver/{lib => models}/matrix3.ts | 0 .../resolver/{lib => models}/vector2.ts | 0 .../camera/inverse_projection_matrix.test.ts | 2 +- .../public/resolver/store/camera/methods.ts | 2 +- .../store/camera/projection_matrix.test.ts | 2 +- .../public/resolver/store/camera/reducer.ts | 2 +- .../public/resolver/store/camera/selectors.ts | 4 +- .../resolver/store/camera/zooming.test.ts | 2 +- .../public/resolver/store/data/selectors.ts | 2 +- .../public/resolver/view/edge_line.tsx | 2 +- .../resolver/view/process_event_dot.tsx | 2 +- .../public/resolver/view/use_camera.test.tsx | 2 +- 18 files changed, 59 insertions(+), 27 deletions(-) create mode 100644 x-pack/plugins/security_solution/public/resolver/models/aabb.test.ts rename x-pack/plugins/security_solution/public/resolver/{lib => models}/aabb.ts (100%) rename x-pack/plugins/security_solution/public/resolver/{lib => models}/matrix3.test.ts (100%) rename x-pack/plugins/security_solution/public/resolver/{lib => models}/matrix3.ts (100%) rename x-pack/plugins/security_solution/public/resolver/{lib => models}/vector2.ts (100%) diff --git a/x-pack/plugins/security_solution/public/resolver/lib/transformation.test.ts b/x-pack/plugins/security_solution/public/resolver/lib/transformation.test.ts index 3fe6941279bc53..3280bad4a81ff6 100644 --- a/x-pack/plugins/security_solution/public/resolver/lib/transformation.test.ts +++ b/x-pack/plugins/security_solution/public/resolver/lib/transformation.test.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { applyMatrix3 } from './vector2'; +import { applyMatrix3 } from '../models/vector2'; import { scalingTransformation } from './transformation'; describe('transforms', () => { diff --git a/x-pack/plugins/security_solution/public/resolver/lib/tree_sequencers.ts b/x-pack/plugins/security_solution/public/resolver/lib/tree_sequencers.ts index 219c58d6efc9c5..843126c0eef5a6 100644 --- a/x-pack/plugins/security_solution/public/resolver/lib/tree_sequencers.ts +++ b/x-pack/plugins/security_solution/public/resolver/lib/tree_sequencers.ts @@ -4,20 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -/** - * Sequences a tree, yielding children returned by the `children` function. Sequencing is done in 'depth first preorder' fashion. See https://en.wikipedia.org/wiki/Tree_traversal#Pre-order_(NLR) - */ -export function* depthFirstPreorder(root: T, children: (parent: T) => T[]): Iterable { - const nodesToVisit = [root]; - while (nodesToVisit.length !== 0) { - const currentNode = nodesToVisit.shift(); - if (currentNode !== undefined) { - nodesToVisit.unshift(...(children(currentNode) || [])); - yield currentNode; - } - } -} - /** * Sequences a tree, yielding children returned by the `children` function. Sequencing is done in 'level order' fashion. */ diff --git a/x-pack/plugins/security_solution/public/resolver/models/aabb.test.ts b/x-pack/plugins/security_solution/public/resolver/models/aabb.test.ts new file mode 100644 index 00000000000000..ce7d9eda6cca6e --- /dev/null +++ b/x-pack/plugins/security_solution/public/resolver/models/aabb.test.ts @@ -0,0 +1,46 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ +import { isEqual } from './aabb'; +import { AABB } from '../types'; + +describe('AABB', () => { + const minimumX = 0; + const minimumY = 0; + const maximumX = 0; + const maximumY = 0; + + let aabb: AABB; + + beforeEach(() => { + aabb = { minimum: [minimumX, minimumY], maximum: [maximumX, maximumY] }; + }); + it('should be equal to an AABB with the same values', () => { + expect(isEqual(aabb, { minimum: [minimumX, minimumY], maximum: [maximumX, maximumY] })).toBe( + true + ); + }); + + it('should not be equal to an AABB with a different minimum X value', () => { + expect( + isEqual(aabb, { minimum: [minimumX + 1, minimumY], maximum: [maximumX, maximumY] }) + ).toBe(false); + }); + it('should not be equal to an AABB with a different minimum Y value', () => { + expect( + isEqual(aabb, { minimum: [minimumX, minimumY + 1], maximum: [maximumX, maximumY] }) + ).toBe(false); + }); + it('should not be equal to an AABB with a different maximum X value', () => { + expect( + isEqual(aabb, { minimum: [minimumX, minimumY], maximum: [maximumX + 1, maximumY] }) + ).toBe(false); + }); + it('should not be equal to an AABB with a different maximum Y value', () => { + expect( + isEqual(aabb, { minimum: [minimumX, minimumY], maximum: [maximumX, maximumY + 1] }) + ).toBe(false); + }); +}); diff --git a/x-pack/plugins/security_solution/public/resolver/lib/aabb.ts b/x-pack/plugins/security_solution/public/resolver/models/aabb.ts similarity index 100% rename from x-pack/plugins/security_solution/public/resolver/lib/aabb.ts rename to x-pack/plugins/security_solution/public/resolver/models/aabb.ts diff --git a/x-pack/plugins/security_solution/public/resolver/models/indexed_process_tree/isometric_taxi_layout.ts b/x-pack/plugins/security_solution/public/resolver/models/indexed_process_tree/isometric_taxi_layout.ts index 9095f061ee73a7..61363ffa05d949 100644 --- a/x-pack/plugins/security_solution/public/resolver/models/indexed_process_tree/isometric_taxi_layout.ts +++ b/x-pack/plugins/security_solution/public/resolver/models/indexed_process_tree/isometric_taxi_layout.ts @@ -3,7 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import * as vector2 from '../../lib/vector2'; +import * as vector2 from '../../models/vector2'; import { IndexedProcessTree, Vector2, diff --git a/x-pack/plugins/security_solution/public/resolver/lib/matrix3.test.ts b/x-pack/plugins/security_solution/public/resolver/models/matrix3.test.ts similarity index 100% rename from x-pack/plugins/security_solution/public/resolver/lib/matrix3.test.ts rename to x-pack/plugins/security_solution/public/resolver/models/matrix3.test.ts diff --git a/x-pack/plugins/security_solution/public/resolver/lib/matrix3.ts b/x-pack/plugins/security_solution/public/resolver/models/matrix3.ts similarity index 100% rename from x-pack/plugins/security_solution/public/resolver/lib/matrix3.ts rename to x-pack/plugins/security_solution/public/resolver/models/matrix3.ts diff --git a/x-pack/plugins/security_solution/public/resolver/lib/vector2.ts b/x-pack/plugins/security_solution/public/resolver/models/vector2.ts similarity index 100% rename from x-pack/plugins/security_solution/public/resolver/lib/vector2.ts rename to x-pack/plugins/security_solution/public/resolver/models/vector2.ts diff --git a/x-pack/plugins/security_solution/public/resolver/store/camera/inverse_projection_matrix.test.ts b/x-pack/plugins/security_solution/public/resolver/store/camera/inverse_projection_matrix.test.ts index 000dbb8d52841d..4eda0743636477 100644 --- a/x-pack/plugins/security_solution/public/resolver/store/camera/inverse_projection_matrix.test.ts +++ b/x-pack/plugins/security_solution/public/resolver/store/camera/inverse_projection_matrix.test.ts @@ -9,7 +9,7 @@ import { CameraAction } from './action'; import { CameraState } from '../../types'; import { cameraReducer } from './reducer'; import { inverseProjectionMatrix } from './selectors'; -import { applyMatrix3 } from '../../lib/vector2'; +import { applyMatrix3 } from '../../models/vector2'; import { scaleToZoom } from './scale_to_zoom'; describe('inverseProjectionMatrix', () => { diff --git a/x-pack/plugins/security_solution/public/resolver/store/camera/methods.ts b/x-pack/plugins/security_solution/public/resolver/store/camera/methods.ts index 3288b91ffbb508..a1410430049c44 100644 --- a/x-pack/plugins/security_solution/public/resolver/store/camera/methods.ts +++ b/x-pack/plugins/security_solution/public/resolver/store/camera/methods.ts @@ -6,7 +6,7 @@ import { translation } from './selectors'; import { CameraState, Vector2 } from '../../types'; -import { distance } from '../../lib/vector2'; +import { distance } from '../../models/vector2'; /** * Return a new `CameraState` with the `animation` property diff --git a/x-pack/plugins/security_solution/public/resolver/store/camera/projection_matrix.test.ts b/x-pack/plugins/security_solution/public/resolver/store/camera/projection_matrix.test.ts index e868424d06c94d..63abb57626e93c 100644 --- a/x-pack/plugins/security_solution/public/resolver/store/camera/projection_matrix.test.ts +++ b/x-pack/plugins/security_solution/public/resolver/store/camera/projection_matrix.test.ts @@ -9,7 +9,7 @@ import { CameraAction } from './action'; import { CameraState } from '../../types'; import { cameraReducer } from './reducer'; import { projectionMatrix } from './selectors'; -import { applyMatrix3 } from '../../lib/vector2'; +import { applyMatrix3 } from '../../models/vector2'; import { scaleToZoom } from './scale_to_zoom'; describe('projectionMatrix', () => { diff --git a/x-pack/plugins/security_solution/public/resolver/store/camera/reducer.ts b/x-pack/plugins/security_solution/public/resolver/store/camera/reducer.ts index f64864edab5b33..03b0e3e11c4fc0 100644 --- a/x-pack/plugins/security_solution/public/resolver/store/camera/reducer.ts +++ b/x-pack/plugins/security_solution/public/resolver/store/camera/reducer.ts @@ -7,7 +7,7 @@ import { Reducer } from 'redux'; import { unitsPerNudge, nudgeAnimationDuration } from './scaling_constants'; import { animatePanning } from './methods'; -import * as vector2 from '../../lib/vector2'; +import * as vector2 from '../../models/vector2'; import * as selectors from './selectors'; import { clamp } from '../../lib/math'; diff --git a/x-pack/plugins/security_solution/public/resolver/store/camera/selectors.ts b/x-pack/plugins/security_solution/public/resolver/store/camera/selectors.ts index 49c157ec8e0f50..86d934bd956637 100644 --- a/x-pack/plugins/security_solution/public/resolver/store/camera/selectors.ts +++ b/x-pack/plugins/security_solution/public/resolver/store/camera/selectors.ts @@ -7,8 +7,8 @@ import { createSelector, defaultMemoize } from 'reselect'; import { easing } from 'ts-easing'; import { clamp, lerp } from '../../lib/math'; -import * as vector2 from '../../lib/vector2'; -import { multiply, add as addMatrix } from '../../lib/matrix3'; +import * as vector2 from '../../models/vector2'; +import { multiply, add as addMatrix } from '../../models/matrix3'; import { inverseOrthographicProjection, scalingTransformation, diff --git a/x-pack/plugins/security_solution/public/resolver/store/camera/zooming.test.ts b/x-pack/plugins/security_solution/public/resolver/store/camera/zooming.test.ts index ff03b0baf01aaf..3b6749cf841fae 100644 --- a/x-pack/plugins/security_solution/public/resolver/store/camera/zooming.test.ts +++ b/x-pack/plugins/security_solution/public/resolver/store/camera/zooming.test.ts @@ -11,7 +11,7 @@ import { CameraState, AABB } from '../../types'; import { viewableBoundingBox, inverseProjectionMatrix, scalingFactor } from './selectors'; import { expectVectorsToBeClose } from './test_helpers'; import { scaleToZoom } from './scale_to_zoom'; -import { applyMatrix3 } from '../../lib/vector2'; +import { applyMatrix3 } from '../../models/vector2'; describe('zooming', () => { let store: Store; diff --git a/x-pack/plugins/security_solution/public/resolver/store/data/selectors.ts b/x-pack/plugins/security_solution/public/resolver/store/data/selectors.ts index f15cb6427dccf9..e45101e97e6c13 100644 --- a/x-pack/plugins/security_solution/public/resolver/store/data/selectors.ts +++ b/x-pack/plugins/security_solution/public/resolver/store/data/selectors.ts @@ -22,7 +22,7 @@ import { uniquePidForProcess, } from '../../models/process_event'; import { factory as indexedProcessTreeFactory } from '../../models/indexed_process_tree'; -import { isEqual } from '../../lib/aabb'; +import { isEqual } from '../../models/aabb'; import { ResolverEvent, diff --git a/x-pack/plugins/security_solution/public/resolver/view/edge_line.tsx b/x-pack/plugins/security_solution/public/resolver/view/edge_line.tsx index 4eccb4f5602209..65c70f94432c79 100644 --- a/x-pack/plugins/security_solution/public/resolver/view/edge_line.tsx +++ b/x-pack/plugins/security_solution/public/resolver/view/edge_line.tsx @@ -7,7 +7,7 @@ import React from 'react'; import styled from 'styled-components'; import { FormattedMessage } from '@kbn/i18n/react'; -import { applyMatrix3, distance, angle } from '../lib/vector2'; +import { applyMatrix3, distance, angle } from '../models/vector2'; import { Vector2, Matrix3, EdgeLineMetadata } from '../types'; import { useResolverTheme, calculateResolverFontSize } from './assets'; diff --git a/x-pack/plugins/security_solution/public/resolver/view/process_event_dot.tsx b/x-pack/plugins/security_solution/public/resolver/view/process_event_dot.tsx index a2249e1920bc4f..9df9ed84f3010d 100644 --- a/x-pack/plugins/security_solution/public/resolver/view/process_event_dot.tsx +++ b/x-pack/plugins/security_solution/public/resolver/view/process_event_dot.tsx @@ -13,7 +13,7 @@ import { useHistory } from 'react-router-dom'; // eslint-disable-next-line import/no-nodejs-modules import querystring from 'querystring'; import { NodeSubMenu, subMenuAssets } from './submenu'; -import { applyMatrix3 } from '../lib/vector2'; +import { applyMatrix3 } from '../models/vector2'; import { Vector2, Matrix3, AdjacentProcessMap } from '../types'; import { SymbolIds, useResolverTheme, calculateResolverFontSize } from './assets'; import { ResolverEvent, ResolverNodeStats } from '../../../common/endpoint/types'; diff --git a/x-pack/plugins/security_solution/public/resolver/view/use_camera.test.tsx b/x-pack/plugins/security_solution/public/resolver/view/use_camera.test.tsx index f772c20f8cf160..3476764a887330 100644 --- a/x-pack/plugins/security_solution/public/resolver/view/use_camera.test.tsx +++ b/x-pack/plugins/security_solution/public/resolver/view/use_camera.test.tsx @@ -14,7 +14,7 @@ import { storeFactory } from '../store'; import { Matrix3, ResolverStore, SideEffectSimulator } from '../types'; import { ResolverEvent } from '../../../common/endpoint/types'; import { SideEffectContext } from './side_effect_context'; -import { applyMatrix3 } from '../lib/vector2'; +import { applyMatrix3 } from '../models/vector2'; import { sideEffectSimulator } from './side_effect_simulator'; import { mockProcessEvent } from '../models/process_event_test_helpers'; import { mock as mockResolverTree } from '../models/resolver_tree';