* Don't check for preferredVisualisationType inside the NodeGraph
* Fix layout worker mocking
(cherry picked from commit 0b94f33813)
Co-authored-by: Andrej Ocenas <mr.ocenas@gmail.com>
This commit is contained in:
co-authored by
Andrej Ocenas
parent
1e533f37ed
commit
aa6355b6ea
@@ -1,8 +1,9 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { render } from '@testing-library/react';
|
import { render, screen } from '@testing-library/react';
|
||||||
import { UnconnectedNodeGraphContainer } from './NodeGraphContainer';
|
import { UnconnectedNodeGraphContainer } from './NodeGraphContainer';
|
||||||
import { getDefaultTimeRange, MutableDataFrame } from '@grafana/data';
|
import { getDefaultTimeRange, MutableDataFrame } from '@grafana/data';
|
||||||
import { ExploreId } from '../../types';
|
import { ExploreId } from '../../types';
|
||||||
|
jest.mock('../../plugins/panel/nodeGraph/layout.worker.js');
|
||||||
|
|
||||||
describe('NodeGraphContainer', () => {
|
describe('NodeGraphContainer', () => {
|
||||||
it('is collapsed if shown with traces', () => {
|
it('is collapsed if shown with traces', () => {
|
||||||
@@ -20,7 +21,7 @@ describe('NodeGraphContainer', () => {
|
|||||||
expect(container.firstChild?.childNodes.length).toBe(1);
|
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(
|
const { container } = render(
|
||||||
<UnconnectedNodeGraphContainer
|
<UnconnectedNodeGraphContainer
|
||||||
dataFrames={[nodes]}
|
dataFrames={[nodes]}
|
||||||
@@ -32,6 +33,7 @@ describe('NodeGraphContainer', () => {
|
|||||||
|
|
||||||
expect(container.firstChild?.childNodes.length).toBe(2);
|
expect(container.firstChild?.childNodes.length).toBe(2);
|
||||||
expect(container.querySelector('svg')).toBeInTheDocument();
|
expect(container.querySelector('svg')).toBeInTheDocument();
|
||||||
|
await screen.findByLabelText(/Node: tempo-querier/);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -3,25 +3,7 @@ import { render, screen, fireEvent, waitFor, getByText } from '@testing-library/
|
|||||||
import userEvent from '@testing-library/user-event';
|
import userEvent from '@testing-library/user-event';
|
||||||
import { NodeGraph } from './NodeGraph';
|
import { NodeGraph } from './NodeGraph';
|
||||||
import { makeEdgesDataFrame, makeNodesDataFrame } from './utils';
|
import { makeEdgesDataFrame, makeNodesDataFrame } from './utils';
|
||||||
|
jest.mock('./layout.worker.js');
|
||||||
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,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('NodeGraph', () => {
|
describe('NodeGraph', () => {
|
||||||
it('doesnt fail without any data', async () => {
|
it('doesnt fail without any data', async () => {
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,8 +8,7 @@ import { DataFrame } from '@grafana/data';
|
|||||||
*/
|
*/
|
||||||
export function useCategorizeFrames(series: DataFrame[]) {
|
export function useCategorizeFrames(series: DataFrame[]) {
|
||||||
return useMemo(() => {
|
return useMemo(() => {
|
||||||
const serviceMapFrames = series.filter((frame) => frame.meta?.preferredVisualisationType === 'nodeGraph');
|
return series.reduce(
|
||||||
return serviceMapFrames.reduce(
|
|
||||||
(acc, frame) => {
|
(acc, frame) => {
|
||||||
const sourceField = frame.fields.filter((f) => f.name === 'source');
|
const sourceField = frame.fields.filter((f) => f.name === 'source');
|
||||||
if (sourceField.length) {
|
if (sourceField.length) {
|
||||||
|
|||||||
@@ -227,7 +227,6 @@ function nodesFrame() {
|
|||||||
...fields[key],
|
...fields[key],
|
||||||
name: key,
|
name: key,
|
||||||
})),
|
})),
|
||||||
meta: { preferredVisualisationType: 'nodeGraph' },
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -266,7 +265,6 @@ function edgesFrame() {
|
|||||||
...fields[key],
|
...fields[key],
|
||||||
name: key,
|
name: key,
|
||||||
})),
|
})),
|
||||||
meta: { preferredVisualisationType: 'nodeGraph' },
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user