diff --git a/public/app/features/explore/NodeGraphContainer.test.tsx b/public/app/features/explore/NodeGraphContainer.test.tsx index 01d5960af01..fa58763fc3e 100644 --- a/public/app/features/explore/NodeGraphContainer.test.tsx +++ b/public/app/features/explore/NodeGraphContainer.test.tsx @@ -1,8 +1,9 @@ import React from 'react'; -import { render } from '@testing-library/react'; +import { render, screen } from '@testing-library/react'; import { UnconnectedNodeGraphContainer } from './NodeGraphContainer'; import { getDefaultTimeRange, MutableDataFrame } from '@grafana/data'; import { ExploreId } from '../../types'; +jest.mock('../../plugins/panel/nodeGraph/layout.worker.js'); describe('NodeGraphContainer', () => { it('is collapsed if shown with traces', () => { @@ -20,7 +21,7 @@ describe('NodeGraphContainer', () => { expect(container.firstChild?.childNodes.length).toBe(1); }); - it('shows the graph if not with trace view', () => { + it('shows the graph if not with trace view', async () => { const { container } = render( { expect(container.firstChild?.childNodes.length).toBe(2); expect(container.querySelector('svg')).toBeInTheDocument(); + await screen.findByLabelText(/Node: tempo-querier/); }); }); diff --git a/public/app/plugins/panel/nodeGraph/NodeGraph.test.tsx b/public/app/plugins/panel/nodeGraph/NodeGraph.test.tsx index 9317dc065e6..530b86336dc 100644 --- a/public/app/plugins/panel/nodeGraph/NodeGraph.test.tsx +++ b/public/app/plugins/panel/nodeGraph/NodeGraph.test.tsx @@ -3,25 +3,7 @@ import { render, screen, fireEvent, waitFor, getByText } from '@testing-library/ import userEvent from '@testing-library/user-event'; import { NodeGraph } from './NodeGraph'; import { makeEdgesDataFrame, makeNodesDataFrame } from './utils'; - -jest.mock('./layout.worker.js', () => { - const { layout } = jest.requireActual('./layout.worker.js'); - class TestWorker { - constructor() {} - postMessage(data: any) { - const { nodes, edges, config } = data; - setTimeout(() => { - layout(nodes, edges, config); - // @ts-ignore - this.onmessage({ data: { nodes, edges } }); - }, 1); - } - } - return { - __esModule: true, - default: TestWorker, - }; -}); +jest.mock('./layout.worker.js'); describe('NodeGraph', () => { it('doesnt fail without any data', async () => { diff --git a/public/app/plugins/panel/nodeGraph/__mocks__/layout.worker.js b/public/app/plugins/panel/nodeGraph/__mocks__/layout.worker.js new file mode 100644 index 00000000000..39c401010e6 --- /dev/null +++ b/public/app/plugins/panel/nodeGraph/__mocks__/layout.worker.js @@ -0,0 +1,12 @@ +const { layout } = jest.requireActual('../layout.worker.js'); + +export default class TestWorker { + constructor() {} + postMessage(data) { + const { nodes, edges, config } = data; + setTimeout(() => { + layout(nodes, edges, config); + this.onmessage({ data: { nodes, edges } }); + }, 1); + } +} diff --git a/public/app/plugins/panel/nodeGraph/useCategorizeFrames.ts b/public/app/plugins/panel/nodeGraph/useCategorizeFrames.ts index b18ae1abc2a..3e37efd6661 100644 --- a/public/app/plugins/panel/nodeGraph/useCategorizeFrames.ts +++ b/public/app/plugins/panel/nodeGraph/useCategorizeFrames.ts @@ -8,8 +8,7 @@ import { DataFrame } from '@grafana/data'; */ export function useCategorizeFrames(series: DataFrame[]) { return useMemo(() => { - const serviceMapFrames = series.filter((frame) => frame.meta?.preferredVisualisationType === 'nodeGraph'); - return serviceMapFrames.reduce( + return series.reduce( (acc, frame) => { const sourceField = frame.fields.filter((f) => f.name === 'source'); if (sourceField.length) { diff --git a/public/app/plugins/panel/nodeGraph/utils.ts b/public/app/plugins/panel/nodeGraph/utils.ts index beb8e6dd857..a01fcd68744 100644 --- a/public/app/plugins/panel/nodeGraph/utils.ts +++ b/public/app/plugins/panel/nodeGraph/utils.ts @@ -227,7 +227,6 @@ function nodesFrame() { ...fields[key], name: key, })), - meta: { preferredVisualisationType: 'nodeGraph' }, }); } @@ -266,7 +265,6 @@ function edgesFrame() { ...fields[key], name: key, })), - meta: { preferredVisualisationType: 'nodeGraph' }, }); }