Files
grafana/public/app/features/panel/components/PanelDataErrorView.test.tsx
Ashley Harrison 47f8717149 React: Use new JSX transform (#88802)
* update eslint, tsconfig + esbuild to handle new jsx transform

* remove thing that breaks the new jsx transform

* remove react imports

* adjust grafana-icons build

* is this the correct syntax?

* try this

* well this was much easier than expected...

* change grafana-plugin-configs webpack config

* fixes

* fix lockfile

* fix 2 more violations

* use path.resolve instead of require.resolve

* remove react import

* fix react imports

* more fixes

* remove React import

* remove import React from docs

* remove another react import
2024-06-25 12:43:47 +01:00

95 lines
2.2 KiB
TypeScript

import { render, screen } from '@testing-library/react';
import { defaultsDeep } from 'lodash';
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 };
}