Files
grafana/public/app/plugins/panel/bargauge/BarGaugePanel.test.tsx
Torkel Ödegaard 044ec40112 Graphite: Rollup Indicator (#22738)
* WIP: Rollup indiator progress

* Progress

* Progress, can now open inspector with right tab

* changed type and made inspect

* Showing stats

* Progress

* Progress

* Getting ready for v1

* Added option and fixed some strict nulls

* Updated

* Fixed test
2020-03-18 13:00:14 +01:00

94 lines
2.2 KiB
TypeScript

import React from 'react';
import { mount, ReactWrapper } from 'enzyme';
import {
PanelData,
dateMath,
TimeRange,
VizOrientation,
PanelProps,
LoadingState,
dateTime,
toDataFrame,
} from '@grafana/data';
import { BarGaugeDisplayMode } from '@grafana/ui';
import { BarGaugePanel } from './BarGaugePanel';
import { BarGaugeOptions } from './types';
describe('BarGaugePanel', () => {
describe('when empty result is rendered', () => {
const wrapper = createBarGaugePanelWithData({
series: [],
timeRange: createTimeRange(),
state: LoadingState.Done,
});
it('should render with title "No data"', () => {
const displayValue = wrapper.find('div.bar-gauge__value').text();
expect(displayValue).toBe('No data');
});
});
describe('when there is data', () => {
const wrapper = createBarGaugePanelWithData({
series: [
toDataFrame({
target: 'test',
datapoints: [
[100, 1000],
[100, 200],
],
}),
],
timeRange: createTimeRange(),
state: LoadingState.Done,
});
it('should render with title "No data"', () => {
const displayValue = wrapper.find('div.bar-gauge__value').text();
expect(displayValue).toBe('100');
});
});
});
function createTimeRange(): TimeRange {
return {
from: dateMath.parse('now-6h') || dateTime(),
to: dateMath.parse('now') || dateTime(),
raw: { from: 'now-6h', to: 'now' },
};
}
function createBarGaugePanelWithData(data: PanelData): ReactWrapper<PanelProps<BarGaugeOptions>> {
const timeRange = createTimeRange();
const options: BarGaugeOptions = {
displayMode: BarGaugeDisplayMode.Lcd,
fieldOptions: {
calcs: ['mean'],
defaults: {},
values: false,
overrides: [],
},
orientation: VizOrientation.Horizontal,
showUnfilled: true,
};
return mount<BarGaugePanel>(
<BarGaugePanel
id={1}
data={data}
timeRange={timeRange}
timeZone={'utc'}
options={options}
onOptionsChange={() => {}}
onChangeTimeRange={() => {}}
replaceVariables={s => s}
renderCounter={0}
width={532}
transparent={false}
height={250}
/>
);
}