@@ -14,8 +14,9 @@ import { spyMiddlewareFactory } from '../spy_middleware_factory';
1414import { resolverMiddlewareFactory } from '../../store/middleware' ;
1515import { resolverReducer } from '../../store/reducer' ;
1616import { MockResolver } from './mock_resolver' ;
17- import { ResolverState , DataAccessLayer , SpyMiddleware } from '../../types' ;
17+ import { ResolverState , DataAccessLayer , SpyMiddleware , SideEffectSimulator } from '../../types' ;
1818import { ResolverAction } from '../../store/actions' ;
19+ import { sideEffectSimulatorFactory } from '../../view/side_effect_simulator_factory' ;
1920
2021/**
2122 * Test a Resolver instance using jest, enzyme, and a mock data layer.
@@ -43,6 +44,11 @@ export class Simulator {
4344 * This is used by `debugActions`.
4445 */
4546 private readonly spyMiddleware : SpyMiddleware ;
47+ /**
48+ * Simulator which allows you to explicitly simulate resize events and trigger animation frames
49+ */
50+ private readonly sideEffectSimulator : SideEffectSimulator ;
51+
4652 constructor ( {
4753 dataAccessLayer,
4854 resolverComponentInstanceID,
@@ -87,11 +93,14 @@ export class Simulator {
8793 // Used for `KibanaContextProvider`
8894 const coreStart : CoreStart = coreMock . createStart ( ) ;
8995
96+ this . sideEffectSimulator = sideEffectSimulatorFactory ( ) ;
97+
9098 // Render Resolver via the `MockResolver` component, using `enzyme`.
9199 this . wrapper = mount (
92100 < MockResolver
93101 resolverComponentInstanceID = { this . resolverComponentInstanceID }
94102 history = { this . history }
103+ sideEffectSimulator = { this . sideEffectSimulator }
95104 store = { this . store }
96105 coreStart = { coreStart }
97106 databaseDocumentID = { databaseDocumentID }
@@ -149,6 +158,18 @@ export class Simulator {
149158 return this . domNodes ( processNodeElementSelector ( options ) ) ;
150159 }
151160
161+ /**
162+ * Return an Enzyme ReactWrapper for any child elements of a specific processNodeElement
163+ *
164+ * @param entityID The entity ID of the proocess node to select in
165+ * @param selector The selector for the child element of the process node
166+ */
167+ public processNodeChildElements ( entityID : string , selector : string ) : ReactWrapper {
168+ return this . domNodes (
169+ `${ processNodeElementSelector ( { entityID } ) } [data-test-subj="${ selector } "]`
170+ ) ;
171+ }
172+
152173 /**
153174 * Return the node element with the given `entityID`.
154175 */
@@ -174,21 +195,11 @@ export class Simulator {
174195 }
175196
176197 /**
177- * Return an Enzyme ReactWrapper that includes the Related Events host button for a given process node
178- *
179- * @param entityID The entity ID of the proocess node to select in
198+ * This manually runs the animation frames tied to a configurable timestamp in the future
180199 */
181- public processNodeRelatedEventButton ( entityID : string ) : ReactWrapper {
182- return this . domNodes (
183- `${ processNodeElementSelector ( { entityID } ) } [data-test-subj="resolver:submenu:button"]`
184- ) ;
185- }
186-
187- /**
188- * The items in the submenu that is opened by expanding a node in the map.
189- */
190- public processNodeSubmenuItems ( ) : ReactWrapper {
191- return this . domNodes ( '[data-test-subj="resolver:map:node-submenu-item"]' ) ;
200+ public runAnimationFramesTimeFromNow ( time : number = 0 ) {
201+ this . sideEffectSimulator . controls . time = time ;
202+ this . sideEffectSimulator . controls . provideAnimationFrame ( ) ;
192203 }
193204
194205 /**
@@ -202,59 +213,17 @@ export class Simulator {
202213 }
203214
204215 /**
205- * The element that shows when Resolver is waiting for the graph data.
206- */
207- public graphLoadingElement ( ) : ReactWrapper {
208- return this . domNodes ( '[data-test-subj="resolver:graph:loading"]' ) ;
209- }
210-
211- /**
212- * The element that shows if Resolver couldn't draw the graph.
213- */
214- public graphErrorElement ( ) : ReactWrapper {
215- return this . domNodes ( '[data-test-subj="resolver:graph:error"]' ) ;
216- }
217-
218- /**
219- * The element where nodes get drawn.
220- */
221- public graphElement ( ) : ReactWrapper {
222- return this . domNodes ( '[data-test-subj="resolver:graph"]' ) ;
223- }
224-
225- /**
226- * The titles of the links that select a node in the node list view.
227- */
228- public nodeListNodeLinkText ( ) : ReactWrapper {
229- return this . domNodes ( '[data-test-subj="resolver:node-list:node-link:title"]' ) ;
230- }
231-
232- /**
233- * The icons in the links that select a node in the node list view.
234- */
235- public nodeListNodeLinkIcons ( ) : ReactWrapper {
236- return this . domNodes ( '[data-test-subj="resolver:node-list:node-link:icon"]' ) ;
237- }
238-
239- /**
240- * Link rendered in the breadcrumbs of the node detail view. Takes the user to the node list.
241- */
242- public nodeDetailBreadcrumbNodeListLink ( ) : ReactWrapper {
243- return this . domNodes ( '[data-test-subj="resolver:node-detail:breadcrumbs:node-list-link"]' ) ;
244- }
245-
246- /**
247- * The title element for the node detail view.
216+ * Given a 'data-test-subj' value, it will resolve the react wrapper or undefined if not found
248217 */
249- public nodeDetailViewTitle ( ) : ReactWrapper {
250- return this . domNodes ( ' [data-test-subj="resolver:node-detail:title"]' ) ;
218+ public async resolve ( selector : string ) : Promise < ReactWrapper | undefined > {
219+ return this . resolveWrapper ( ( ) => this . domNodes ( ` [data-test-subj="${ selector } "]` ) ) ;
251220 }
252221
253222 /**
254- * The icon element for the node detail title.
223+ * Given a 'data-test-subj' selector, it will return the domNode
255224 */
256- public nodeDetailViewTitleIcon ( ) : ReactWrapper {
257- return this . domNodes ( ' [data-test-subj="resolver:node-detail:title-icon"]' ) ;
225+ public testSubject ( selector : string ) : ReactWrapper {
226+ return this . domNodes ( ` [data-test-subj="${ selector } "]` ) ;
258227 }
259228
260229 /**
@@ -297,7 +266,7 @@ export class Simulator {
297266 public async resolveWrapper (
298267 wrapperFactory : ( ) => ReactWrapper ,
299268 predicate : ( wrapper : ReactWrapper ) => boolean = ( wrapper ) => wrapper . length > 0
300- ) : Promise < ReactWrapper | void > {
269+ ) : Promise < ReactWrapper | undefined > {
301270 for await ( const wrapper of this . map ( wrapperFactory ) ) {
302271 if ( predicate ( wrapper ) ) {
303272 return wrapper ;
0 commit comments