Files
grafana/public/app/plugins/panel/flamegraph/components/FlameGraph/FlameGraphTooltip.test.ts
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

87 lines
2.1 KiB
TypeScript

import { ArrayVector, Field, FieldType } from '@grafana/data';
import { getTooltipData } from './FlameGraphTooltip';
describe('should get tooltip data correctly', () => {
it('for bytes', () => {
const tooltipData = getTooltipData(makeField('bytes'), 'total', 8_624_078_250, 8_624_078_250);
expect(tooltipData).toEqual({
name: 'total',
percentTitle: '% of total',
percentValue: 100,
unitTitle: 'RAM',
unitValue: '8.03 GiB',
samples: '8,624,078,250',
});
});
it('with none unit', () => {
const tooltipData = getTooltipData(makeField('none'), 'total', 8_624_078_250, 8_624_078_250);
expect(tooltipData).toEqual({
name: 'total',
percentTitle: '% of total',
percentValue: 100,
unitTitle: 'Count',
unitValue: '8624078250',
samples: '8,624,078,250',
});
});
it('without unit', () => {
const tooltipData = getTooltipData(
{
name: 'test',
type: FieldType.number,
values: new ArrayVector(),
config: {},
},
'total',
8_624_078_250,
8_624_078_250
);
expect(tooltipData).toEqual({
name: 'total',
percentTitle: '% of total',
percentValue: 100,
unitTitle: 'Count',
unitValue: '8624078250',
samples: '8,624,078,250',
});
});
it('for objects', () => {
const tooltipData = getTooltipData(makeField('short'), 'total', 8_624_078_250, 8_624_078_250);
expect(tooltipData).toEqual({
name: 'total',
percentTitle: '% of total',
percentValue: 100,
unitTitle: 'Count',
unitValue: '8.62 Bil',
samples: '8,624,078,250',
});
});
it('for nanoseconds', () => {
const tooltipData = getTooltipData(makeField('ns'), 'total', 8_624_078_250, 8_624_078_250);
expect(tooltipData).toEqual({
name: 'total',
percentTitle: '% of total time',
percentValue: 100,
unitTitle: 'Time',
unitValue: '8.62 s',
samples: '8,624,078,250',
});
});
});
function makeField(unit: string): Field {
return {
name: 'test',
type: FieldType.number,
config: {
unit,
},
values: new ArrayVector(),
};
}