-
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
[Security Solution][Test] Enzyme test for related events button #74411
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,10 @@ import { | |
ResolverEntityIndex, | ||
} from '../../../../common/endpoint/types'; | ||
import { mockEndpointEvent } from '../../store/mocks/endpoint_event'; | ||
import { mockTreeWithNoAncestorsAnd2Children } from '../../store/mocks/resolver_tree'; | ||
import { | ||
mockTreeWithNoAncestorsAnd2Children, | ||
withRelatedEventsOnOrigin, | ||
} from '../../store/mocks/resolver_tree'; | ||
import { DataAccessLayer } from '../../types'; | ||
|
||
interface Metadata { | ||
|
@@ -40,11 +43,26 @@ interface Metadata { | |
/** | ||
* A simple mock dataAccessLayer possible that returns a tree with 0 ancestors and 2 direct children. 1 related event is returned. The parameter to `entities` is ignored. | ||
*/ | ||
export function oneAncestorTwoChildren(): { dataAccessLayer: DataAccessLayer; metadata: Metadata } { | ||
export function oneAncestorTwoChildren( | ||
{ | ||
withRelatedEvents, | ||
}: { withRelatedEvents: Parameters<typeof withRelatedEventsOnOrigin>[1] | null } = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❔ Change back to It<string,string> There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
withRelatedEvents: null, | ||
} | ||
): { dataAccessLayer: DataAccessLayer; metadata: Metadata } { | ||
const metadata: Metadata = { | ||
databaseDocumentID: '_id', | ||
entityIDs: { origin: 'origin', firstChild: 'firstChild', secondChild: 'secondChild' }, | ||
}; | ||
const baseTree = mockTreeWithNoAncestorsAnd2Children({ | ||
originID: metadata.entityIDs.origin, | ||
firstChildID: metadata.entityIDs.firstChild, | ||
secondChildID: metadata.entityIDs.secondChild, | ||
}); | ||
const composedTree = withRelatedEvents | ||
? withRelatedEventsOnOrigin(baseTree, withRelatedEvents) | ||
: baseTree; | ||
|
||
return { | ||
metadata, | ||
dataAccessLayer: { | ||
|
@@ -54,13 +72,17 @@ export function oneAncestorTwoChildren(): { dataAccessLayer: DataAccessLayer; me | |
relatedEvents(entityID: string): Promise<ResolverRelatedEvents> { | ||
return Promise.resolve({ | ||
entityID, | ||
events: [ | ||
mockEndpointEvent({ | ||
entityID, | ||
name: 'event', | ||
timestamp: 0, | ||
}), | ||
], | ||
events: | ||
/* Respond with the mocked related events when the origin's related events are fetched*/ withRelatedEvents && | ||
entityID === metadata.entityIDs.origin | ||
? composedTree.relatedEvents.events | ||
: [ | ||
mockEndpointEvent({ | ||
entityID, | ||
name: 'event', | ||
timestamp: 0, | ||
}), | ||
], | ||
nextEvent: null, | ||
}); | ||
}, | ||
|
@@ -69,13 +91,7 @@ export function oneAncestorTwoChildren(): { dataAccessLayer: DataAccessLayer; me | |
* Fetch a ResolverTree for a entityID | ||
*/ | ||
resolverTree(): Promise<ResolverTree> { | ||
return Promise.resolve( | ||
mockTreeWithNoAncestorsAnd2Children({ | ||
originID: metadata.entityIDs.origin, | ||
firstChildID: metadata.entityIDs.firstChild, | ||
secondChildID: metadata.entityIDs.secondChild, | ||
}) | ||
); | ||
return Promise.resolve(composedTree); | ||
}, | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* 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 uuid from 'uuid'; | ||
import { EndpointEvent } from '../../../../common/endpoint/types'; | ||
|
||
/** | ||
* Simple mock related event. | ||
*/ | ||
export function mockRelatedEvent({ | ||
entityID, | ||
timestamp, | ||
category, | ||
type, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❔ add id There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
}: { | ||
entityID: string; | ||
timestamp: number; | ||
category: string; | ||
type: string; | ||
}): EndpointEvent { | ||
return { | ||
'@timestamp': timestamp, | ||
event: { | ||
kind: 'event', | ||
type, | ||
category, | ||
id: uuid.v4(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you make this non-random? maybe pass it in or just make it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
}, | ||
process: { | ||
entity_id: entityID, | ||
}, | ||
} as EndpointEvent; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -220,6 +220,33 @@ export class Simulator { | |
); | ||
} | ||
|
||
/** | ||
* For a render of the Enzyme wrapper (may help update if other concerns have effected the render). May be useful for debugging. | ||
*/ | ||
public updateWrapper() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you remove this for now (its unused) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
return this.wrapper.update(); | ||
} | ||
|
||
/** | ||
* Dump all contents of the outer ReactWrapper (to be `console.log`ged as appropriate) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❔ add comment about mixing React & DOM There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
*/ | ||
public debugWrapper() { | ||
return this.wrapper.debug(); | ||
} | ||
|
||
/** | ||
* Return an Enzyme ReactWrapper that includes the Related Events host button for a given process node | ||
* | ||
* @param entityID The entity ID of the proocess node to select in | ||
*/ | ||
public processNodeRelatedEventButton(entityID: string): ReactWrapper { | ||
return this.processNodeElements({ entityID }).findWhere( | ||
(wrapper) => | ||
typeof wrapper.type() === 'string' && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you add a comment here saying something like 'filter out React components'? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
wrapper.prop('data-test-subj') === 'resolver:submenu:button' | ||
); | ||
} | ||
|
||
/** | ||
* Return the selected node query string values. | ||
*/ | ||
|
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.
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.
a48a10a#diff-7ac6cbbaa178435982e90bea4352bdf2R47