The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/features/panel/components/PanelDataErrorView.test.tsx

95 lines
2.3 KiB

import { render, screen } from '@testing-library/react';
import { defaultsDeep } from 'lodash';
import React from 'react';
import { Provider } from 'react-redux';
import { FieldType, getDefaultTimeRange, LoadingState } from '@grafana/data';
import { PanelDataErrorViewProps } from '@grafana/runtime';
import { configureStore } from 'app/store/configureStore';
import { PanelDataErrorView } from './PanelDataErrorView';
jest.mock('app/features/dashboard/services/DashboardSrv', () => ({
getDashboardSrv: () => {
return {
getCurrent: () => undefined,
};
},
}));
describe('PanelDataErrorView', () => {
it('show No data when there is no data', () => {
renderWithProps();
expect(screen.getByText('No data')).toBeInTheDocument();
});
it('show No data when there is no data', () => {
renderWithProps({
data: {
state: LoadingState.Done,
timeRange: getDefaultTimeRange(),
series: [
{
fields: [
{
name: 'time',
type: FieldType.time,
config: {},
values: [],
},
],
length: 0,
},
{
fields: [
{
name: 'value',
type: FieldType.number,
config: {},
values: [],
},
],
length: 0,
},
],
},
});
expect(screen.getByText('No data')).toBeInTheDocument();
});
it('show no value field config when there is no data', () => {
renderWithProps({
fieldConfig: {
overrides: [],
defaults: {
noValue: 'Query returned nothing',
},
},
});
expect(screen.getByText('Query returned nothing')).toBeInTheDocument();
});
});
function renderWithProps(overrides?: Partial<PanelDataErrorViewProps>) {
const defaults: PanelDataErrorViewProps = {
panelId: 1,
data: {
state: LoadingState.Done,
series: [],
timeRange: getDefaultTimeRange(),
},
};
const props = defaultsDeep(overrides ?? {}, defaults);
const store = configureStore();
const stuff = render(
<Provider store={store}>
<PanelDataErrorView {...props} />
</Provider>
);
return { ...stuff };
}