-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Graph control tests more #74884
Closed
+387
−18
Closed
Graph control tests more #74884
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
91a0e8f
initialized graph control tests
michaelolo24 9b3b5bb
added zoom tests
michaelolo24 daa2592
fix comments
michaelolo24 3c430b4
make graph control tests more explicit
michaelolo24 e788b45
refactor to use domNodes and map
michaelolo24 cf33fd5
slider, not button
michaelolo24 3de7be9
Add .toYieldObjectEqualTo matcher. resolve graph control test wrapper…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
221 changes: 221 additions & 0 deletions
221
x-pack/plugins/security_solution/public/resolver/view/graph_controls.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,221 @@ | ||
/* | ||
* 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 { Simulator } from '../test_utilities/simulator'; | ||
import { noAncestorsTwoChildren } from '../data_access_layer/mocks/no_ancestors_two_children'; | ||
import { nudgeAnimationDuration } from '../store/camera/scaling_constants'; | ||
import '../test_utilities/extend_jest'; | ||
|
||
describe('graph controls: when relsover is loaded with an origin node', () => { | ||
let simulator: Simulator; | ||
let originEntityID: string; | ||
let originNodeStyle: () => AsyncIterable<CSSStyleDeclaration | null>; | ||
const resolverComponentInstanceID = 'graph-controls-test'; | ||
|
||
const originalPositionStyle: Readonly<{ left: string; top: string }> = { | ||
left: '746.93132px', | ||
top: '535.5792px', | ||
}; | ||
const originalSizeStyle: Readonly<{ width: string; height: string }> = { | ||
width: '360px', | ||
height: '120px', | ||
}; | ||
|
||
beforeEach(async () => { | ||
const { | ||
metadata: { databaseDocumentID, entityIDs }, | ||
dataAccessLayer, | ||
} = noAncestorsTwoChildren(); | ||
|
||
simulator = new Simulator({ | ||
dataAccessLayer, | ||
databaseDocumentID, | ||
resolverComponentInstanceID, | ||
}); | ||
originEntityID = entityIDs.origin; | ||
|
||
originNodeStyle = () => | ||
simulator.map(() => { | ||
const wrapper = simulator.processNodeElements({ entityID: originEntityID }); | ||
// `getDOMNode` can only be called on a wrapper of a single node: https://enzymejs.github.io/enzyme/docs/api/ReactWrapper/getDOMNode.html | ||
if (wrapper.length === 1) { | ||
return wrapper.getDOMNode<HTMLElement>().style; | ||
} | ||
return null; | ||
}); | ||
}); | ||
|
||
it('should display all cardinal panning buttons and the center button', async () => { | ||
await expect( | ||
simulator.map(() => ({ | ||
westPanButton: simulator.westPanElement().length, | ||
southPanButton: simulator.southPanElement().length, | ||
eastPanButton: simulator.eastPanElement().length, | ||
northPanButton: simulator.northPanElement().length, | ||
centerButton: simulator.centerPanElement().length, | ||
})) | ||
).toYieldEqualTo({ | ||
westPanButton: 1, | ||
southPanButton: 1, | ||
eastPanButton: 1, | ||
northPanButton: 1, | ||
centerButton: 1, | ||
}); | ||
}); | ||
|
||
it('should display the zoom buttons and slider', async () => { | ||
await expect( | ||
simulator.map(() => ({ | ||
zoomInButton: simulator.zoomInElement().length, | ||
zoomOutButton: simulator.zoomOutElement().length, | ||
zoomSlider: simulator.zoomSliderElement().length, | ||
})) | ||
).toYieldEqualTo({ | ||
zoomInButton: 1, | ||
zoomOutButton: 1, | ||
zoomSlider: 1, | ||
}); | ||
}); | ||
|
||
it("should show the origin node in it's original position", async () => { | ||
await expect(originNodeStyle()).toYieldObjectEqualTo(originalPositionStyle); | ||
}); | ||
|
||
describe('when the user clicks the west panning button', () => { | ||
beforeEach(async () => { | ||
(await simulator.resolveWrapper(() => simulator.westPanElement()))!.simulate('click'); | ||
simulator.runAnimationFramesTimeFromNow(nudgeAnimationDuration); | ||
}); | ||
|
||
it('should show the origin node further left on the screen', async () => { | ||
await expect(originNodeStyle()).toYieldObjectEqualTo({ | ||
left: '796.93132px', | ||
top: '535.5792px', | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when the user clicks the south panning button', () => { | ||
beforeEach(async () => { | ||
(await simulator.resolveWrapper(() => simulator.southPanElement()))!.simulate('click'); | ||
simulator.runAnimationFramesTimeFromNow(nudgeAnimationDuration); | ||
}); | ||
|
||
it('should show the origin node lower on the screen', async () => { | ||
await expect(originNodeStyle()).toYieldObjectEqualTo({ | ||
left: '746.93132px', | ||
top: '485.5792px', | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when the user clicks the east panning button', () => { | ||
beforeEach(async () => { | ||
(await simulator.resolveWrapper(() => simulator.eastPanElement()))!.simulate('click'); | ||
simulator.runAnimationFramesTimeFromNow(nudgeAnimationDuration); | ||
}); | ||
|
||
it('should show the origin node further right on the screen', async () => { | ||
await expect(originNodeStyle()).toYieldObjectEqualTo({ | ||
left: '696.93132px', | ||
top: '535.5792px', | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when the user clicks the north panning button', () => { | ||
beforeEach(async () => { | ||
(await simulator.resolveWrapper(() => simulator.northPanElement()))!.simulate('click'); | ||
simulator.runAnimationFramesTimeFromNow(nudgeAnimationDuration); | ||
}); | ||
|
||
it('should show the origin node higher on the screen', async () => { | ||
await expect(originNodeStyle()).toYieldObjectEqualTo({ | ||
left: '746.93132px', | ||
top: '585.5792px', | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when the user clicks the center panning button', () => { | ||
beforeEach(async () => { | ||
(await simulator.resolveWrapper(() => simulator.northPanElement()))!.simulate('click'); | ||
simulator.runAnimationFramesTimeFromNow(nudgeAnimationDuration); | ||
(await simulator.resolveWrapper(() => simulator.centerPanElement()))!.simulate('click'); | ||
simulator.runAnimationFramesTimeFromNow(nudgeAnimationDuration); | ||
}); | ||
|
||
it("should return the origin node to it's original position", async () => { | ||
await expect(originNodeStyle()).toYieldObjectEqualTo(originalPositionStyle); | ||
}); | ||
}); | ||
|
||
it('should show the origin node as larger on the screen', async () => { | ||
await expect(originNodeStyle()).toYieldObjectEqualTo(originalSizeStyle); | ||
}); | ||
|
||
describe('when the zoom in button is clicked', () => { | ||
beforeEach(async () => { | ||
(await simulator.resolveWrapper(() => simulator.zoomInElement()))!.simulate('click'); | ||
simulator.runAnimationFramesTimeFromNow(nudgeAnimationDuration); | ||
}); | ||
|
||
it('should show the origin node as larger on the screen', async () => { | ||
await expect(originNodeStyle()).toYieldObjectEqualTo({ | ||
width: '427.7538290724795px', | ||
height: '142.5846096908265px', | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when the zoom out button is clicked', () => { | ||
beforeEach(async () => { | ||
(await simulator.resolveWrapper(() => simulator.zoomOutElement()))!.simulate('click'); | ||
simulator.runAnimationFramesTimeFromNow(nudgeAnimationDuration); | ||
}); | ||
|
||
it('should show the origin node as smaller on the screen', async () => { | ||
await expect(originNodeStyle()).toYieldObjectEqualTo({ | ||
width: '303.0461709275204px', | ||
height: '101.01539030917347px', | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when the slider is moved upwards', () => { | ||
beforeEach(async () => { | ||
await expect(originNodeStyle()).toYieldObjectEqualTo(originalSizeStyle); | ||
|
||
(await simulator.resolveWrapper(() => simulator.zoomSliderElement()))!.simulate('change', { | ||
target: { value: 0.8 }, | ||
}); | ||
simulator.runAnimationFramesTimeFromNow(nudgeAnimationDuration); | ||
}); | ||
|
||
it('should show the origin node as large on the screen', async () => { | ||
await expect(originNodeStyle()).toYieldObjectEqualTo({ | ||
width: '525.6000000000001px', | ||
height: '175.20000000000005px', | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when the slider is moved downwards', () => { | ||
beforeEach(async () => { | ||
(await simulator.resolveWrapper(() => simulator.zoomSliderElement()))!.simulate('change', { | ||
target: { value: 0.2 }, | ||
}); | ||
simulator.runAnimationFramesTimeFromNow(nudgeAnimationDuration); | ||
}); | ||
|
||
it('should show the origin node as smaller on the screen', async () => { | ||
await expect(originNodeStyle()).toYieldObjectEqualTo({ | ||
width: '201.60000000000002px', | ||
height: '67.2px', | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❔ Not sure about making this even more complicated. What does it do that toYieldEqualTo doesn't? Would be helpful to read in a comment here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes