Files
grafana/public/app/plugins/panel/flamegraph/components/FlameGraph/FlameGraph.test.tsx
Joey Tawadrous 74c809f544 Plugins: Introduce new Flame graph panel (#56376)
* Flamegraph

* Updated flame graph width/height values

* Fix top table rendering issue

* Add feature toggle for flamegraph in explore

* Update tests

* Hide flamegraph from dash panel viz list if feature toggle not enabled

* Show table if no flameGraphFrames

* Add flame graph to testdata ds

* Minor improvement
2022-10-07 11:39:14 +01:00

62 lines
1.8 KiB
TypeScript

import { screen } from '@testing-library/dom';
import { render } from '@testing-library/react';
import React, { useState } from 'react';
import { DataFrameView, MutableDataFrame } from '@grafana/data';
import { SelectedView } from '../types';
import FlameGraph from './FlameGraph';
import { Item, nestedSetToLevels } from './dataTransform';
import { data } from './testData/dataNestedSet';
import 'jest-canvas-mock';
jest.mock('react-use', () => ({
useMeasure: () => {
const ref = React.useRef();
return [ref, { width: 1600 }];
},
}));
describe('FlameGraph', () => {
const FlameGraphWithProps = () => {
const [topLevelIndex, setTopLevelIndex] = useState(0);
const [rangeMin, setRangeMin] = useState(0);
const [rangeMax, setRangeMax] = useState(1);
const [search] = useState('');
const [selectedView, _] = useState(SelectedView.Both);
const flameGraphData = new MutableDataFrame(data);
const dataView = new DataFrameView<Item>(flameGraphData);
const levels = nestedSetToLevels(dataView);
return (
<FlameGraph
data={flameGraphData}
levels={levels}
topLevelIndex={topLevelIndex}
rangeMin={rangeMin}
rangeMax={rangeMax}
search={search}
setTopLevelIndex={setTopLevelIndex}
setRangeMin={setRangeMin}
setRangeMax={setRangeMax}
selectedView={selectedView}
/>
);
};
it('should render without error', async () => {
expect(() => render(<FlameGraphWithProps />)).not.toThrow();
});
it('should render correctly', async () => {
render(<FlameGraphWithProps />);
const canvas = screen.getByTestId('flameGraph') as HTMLCanvasElement;
const ctx = canvas!.getContext('2d');
const calls = ctx!.__getDrawCalls();
expect(calls).toMatchSnapshot();
});
});