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/explore/LogsVolumePanel.test.tsx

53 lines
1.7 KiB

import React from 'react';
import { render, screen } from '@testing-library/react';
import { LogsVolumePanel } from './LogsVolumePanel';
import { DataQueryResponse, LoadingState } from '@grafana/data';
jest.mock('./ExploreGraph', () => {
const ExploreGraph = () => <span>ExploreGraph</span>;
return {
ExploreGraph,
};
});
function renderPanel(logsVolumeData?: DataQueryResponse) {
render(
<LogsVolumePanel
absoluteRange={{ from: 0, to: 1 }}
timeZone="timeZone"
splitOpen={() => {}}
width={100}
onUpdateTimeRange={() => {}}
logsVolumeData={logsVolumeData}
onLoadLogsVolume={() => {}}
/>
);
}
describe('LogsVolumePanel', () => {
it('shows loading message', () => {
renderPanel({ state: LoadingState.Loading, error: undefined, data: [] });
expect(screen.getByText('Logs volume is loading...')).toBeInTheDocument();
});
it('shows no volume data', () => {
renderPanel({ state: LoadingState.Done, error: undefined, data: [] });
expect(screen.getByText('No volume data.')).toBeInTheDocument();
});
it('renders logs volume histogram graph', () => {
renderPanel({ state: LoadingState.Done, error: undefined, data: [{}] });
expect(screen.getByText('ExploreGraph')).toBeInTheDocument();
});
it('shows error message', () => {
renderPanel({ state: LoadingState.Error, error: { data: { message: 'Test error message' } }, data: [] });
expect(screen.getByText('Failed to load volume logs for this query')).toBeInTheDocument();
expect(screen.getByText('Test error message')).toBeInTheDocument();
});
it('does not show the panel when there is no volume data', () => {
renderPanel(undefined);
expect(screen.queryByText('Logs volume')).not.toBeInTheDocument();
});
});