2021-09-30 08:46:11 -05:00
|
|
|
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}
|
2021-10-18 05:22:41 -05:00
|
|
|
onLoadLogsVolume={() => {}}
|
2021-09-30 08:46:11 -05:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('LogsVolumePanel', () => {
|
|
|
|
it('shows loading message', () => {
|
|
|
|
renderPanel({ state: LoadingState.Loading, error: undefined, data: [] });
|
2021-11-10 04:20:30 -06:00
|
|
|
expect(screen.getByText('Log volume is loading...')).toBeInTheDocument();
|
2021-09-30 08:46:11 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
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();
|
|
|
|
});
|
|
|
|
|
2022-01-03 03:21:11 -06:00
|
|
|
it('shows warning message without details', () => {
|
2021-10-18 05:22:41 -05:00
|
|
|
renderPanel({ state: LoadingState.Error, error: { data: { message: 'Test error message' } }, data: [] });
|
2021-11-10 04:20:30 -06:00
|
|
|
expect(screen.getByText('Failed to load log volume for this query')).toBeInTheDocument();
|
2022-01-03 03:21:11 -06:00
|
|
|
expect(screen.getByText('Please check console logs for more details.')).toBeInTheDocument();
|
|
|
|
expect(screen.queryByText('Test error message')).not.toBeInTheDocument();
|
2021-09-30 08:46:11 -05:00
|
|
|
});
|
|
|
|
|
2021-10-18 05:22:41 -05:00
|
|
|
it('does not show the panel when there is no volume data', () => {
|
2021-09-30 08:46:11 -05:00
|
|
|
renderPanel(undefined);
|
2021-11-10 04:20:30 -06:00
|
|
|
expect(screen.queryByText('Log volume')).not.toBeInTheDocument();
|
2021-09-30 08:46:11 -05:00
|
|
|
});
|
|
|
|
});
|