@@ -278,6 +278,97 @@ describe('<DependencyGraph>', () => {
278278 expect ( dagOptions3 . prop ( 'matchCount' ) ) . toBe ( 0 ) ;
279279 } ) ;
280280 } ) ;
281+
282+ describe ( '<DependencyGraph> filtering logic (findConnectedServices)' , ( ) => {
283+ let wrapper ;
284+ const baseProps = {
285+ fetchDependencies : jest . fn ( ) ,
286+ nodes : [ { key : 'dummyNode' } ] ,
287+ links : [ { from : 'dummyNode' , to : 'dummyNode' , label : '1' } ] ,
288+ loading : false ,
289+ error : null ,
290+ uiFind : undefined ,
291+ dependencies : [ ] ,
292+ } ;
293+
294+ const getGraphDataFromDAG = currentWrapper => {
295+ currentWrapper . update ( ) ;
296+ const dagComponent = currentWrapper . find ( DAG ) ;
297+ if ( dagComponent . exists ( ) ) {
298+ return dagComponent . prop ( 'data' ) ;
299+ }
300+ return { nodes : [ ] , edges : [ ] } ;
301+ } ;
302+
303+ it ( 'should include direct children when parent is selected' , ( ) => {
304+ const testDependencies = [ { parent : 'A' , child : 'B' , callCount : 1 } ] ;
305+
306+ wrapper = shallow ( < DependencyGraph { ...baseProps } dependencies = { testDependencies } /> ) ;
307+ wrapper . setState ( { selectedService : 'A' , selectedDepth : 1 , debouncedDepth : 1 } ) ;
308+
309+ const graphData = getGraphDataFromDAG ( wrapper ) ;
310+ expect ( graphData . nodes ) . toEqual ( expect . arrayContaining ( [ { key : 'A' } , { key : 'B' } ] ) ) ;
311+ expect ( graphData . edges ) . toEqual ( expect . arrayContaining ( [ { from : 'A' , to : 'B' , label : '1' } ] ) ) ;
312+ } ) ;
313+
314+ it ( 'should include direct parents when child is selected' , ( ) => {
315+ const testDependencies = [ { parent : 'A' , child : 'B' , callCount : 1 } ] ;
316+
317+ wrapper = shallow ( < DependencyGraph { ...baseProps } dependencies = { testDependencies } /> ) ;
318+ wrapper . setState ( { selectedService : 'B' , selectedDepth : 1 , debouncedDepth : 1 } ) ;
319+
320+ const graphData = getGraphDataFromDAG ( wrapper ) ;
321+ expect ( graphData . nodes ) . toEqual ( expect . arrayContaining ( [ { key : 'A' } , { key : 'B' } ] ) ) ;
322+ expect ( graphData . edges ) . toEqual ( expect . arrayContaining ( [ { from : 'A' , to : 'B' , label : '1' } ] ) ) ;
323+ } ) ;
324+
325+ it ( 'should not re-add already visited nodes (outgoing)' , ( ) => {
326+ const testDependencies = [
327+ { parent : 'A' , child : 'B' , callCount : 1 } ,
328+ { parent : 'B' , child : 'A' , callCount : 1 } ,
329+ ] ;
330+
331+ wrapper = shallow ( < DependencyGraph { ...baseProps } dependencies = { testDependencies } /> ) ;
332+ wrapper . setState ( { selectedService : 'A' , selectedDepth : 2 , debouncedDepth : 2 } ) ;
333+
334+ const graphData = getGraphDataFromDAG ( wrapper ) ;
335+ expect ( graphData . nodes ) . toHaveLength ( 2 ) ;
336+ expect ( graphData . nodes ) . toEqual ( expect . arrayContaining ( [ { key : 'A' } , { key : 'B' } ] ) ) ;
337+ expect ( graphData . edges ) . toHaveLength ( 1 ) ;
338+ expect ( graphData . edges ) . toEqual ( expect . arrayContaining ( [ { from : 'A' , to : 'B' , label : '1' } ] ) ) ;
339+ } ) ;
340+
341+ it ( 'should not re-add already visited nodes (incoming)' , ( ) => {
342+ const testDependencies = [
343+ { parent : 'A' , child : 'B' , callCount : 1 } ,
344+ { parent : 'B' , child : 'A' , callCount : 1 } ,
345+ ] ;
346+
347+ wrapper = shallow ( < DependencyGraph { ...baseProps } dependencies = { testDependencies } /> ) ;
348+ wrapper . setState ( { selectedService : 'B' , selectedDepth : 2 , debouncedDepth : 2 } ) ;
349+
350+ const graphData = getGraphDataFromDAG ( wrapper ) ;
351+ expect ( graphData . nodes ) . toHaveLength ( 2 ) ;
352+ expect ( graphData . nodes ) . toEqual ( expect . arrayContaining ( [ { key : 'A' } , { key : 'B' } ] ) ) ;
353+ expect ( graphData . edges ) . toHaveLength ( 1 ) ;
354+ expect ( graphData . edges ) . toEqual ( expect . arrayContaining ( [ { from : 'A' , to : 'B' , label : '1' } ] ) ) ;
355+ } ) ;
356+
357+ it ( 'should ignore calls not connected to the selected service' , ( ) => {
358+ const testDependencies = [
359+ { parent : 'A' , child : 'B' , callCount : 1 } ,
360+ { parent : 'C' , child : 'D' , callCount : 1 } ,
361+ ] ;
362+
363+ wrapper = shallow ( < DependencyGraph { ...baseProps } dependencies = { testDependencies } /> ) ;
364+ wrapper . setState ( { selectedService : 'A' , selectedDepth : 1 , debouncedDepth : 1 } ) ;
365+
366+ const graphData = getGraphDataFromDAG ( wrapper ) ;
367+ expect ( graphData . nodes ) . toHaveLength ( 2 ) ;
368+ expect ( graphData . nodes ) . toEqual ( expect . arrayContaining ( [ { key : 'A' } , { key : 'B' } ] ) ) ;
369+ expect ( graphData . edges ) . toHaveLength ( 1 ) ;
370+ } ) ;
371+ } ) ;
281372} ) ;
282373
283374describe ( 'mapStateToProps()' , ( ) => {
0 commit comments