NodeGraph: Don't check for preferredVisualisationType (#35116)

* Don't check for preferredVisualisationType inside the NodeGraph

* Fix layout worker mocking
This commit is contained in:
Andrej Ocenas 2021-06-03 12:48:26 +02:00 committed by GitHub
parent 433f11a78c
commit 0b94f33813
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 25 deletions

View File

@ -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(
<UnconnectedNodeGraphContainer
dataFrames={[nodes]}
@ -32,6 +33,7 @@ describe('NodeGraphContainer', () => {
expect(container.firstChild?.childNodes.length).toBe(2);
expect(container.querySelector('svg')).toBeInTheDocument();
await screen.findByLabelText(/Node: tempo-querier/);
});
});

View File

@ -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');
jest.mock('react-use/lib/useMeasure', () => {
return {

View File

@ -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);
}
}

View File

@ -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) {

View File

@ -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' },
});
}