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-02-08 08:39:09 -06:00
|
|
|
it('shows short warning message', () => {
|
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-02-08 08:39:09 -06:00
|
|
|
expect(screen.getByText('Test error message')).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows long warning message', () => {
|
|
|
|
// we make a long message
|
|
|
|
const messagePart = 'One two three four five six seven eight nine ten.';
|
|
|
|
const message = messagePart + ' ' + messagePart + ' ' + messagePart;
|
|
|
|
|
|
|
|
renderPanel({ state: LoadingState.Error, error: { data: { message } }, data: [] });
|
|
|
|
expect(screen.getByText('Failed to load log volume for this query')).toBeInTheDocument();
|
|
|
|
expect(screen.queryByText(message)).not.toBeInTheDocument();
|
|
|
|
const button = screen.getByText('Show details');
|
|
|
|
button.click();
|
|
|
|
expect(screen.getByText(message)).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
|
|
|
});
|
|
|
|
});
|