grafana/public/app/features/explore/LogsVolumePanel.test.tsx
Piotr Jamróz 0bf2b89eb9
Explore: Align multiple log volumes (#64356)
* Align log volumes on x an y axes

* Move helper functions to logs/utils

* Add tests

* Simplify supplementaryQueries.ts

* Fix tests

* Revert code simplifications

To simplify the PR, this can be added in a separate PR

* Fix reusing logs volume when limited/non-limited are used

* Use more specific property name

* Add missing property

* Stretch graph to selected range but only if there's data available

* Fix unit tests

* Fix calculating maximum when bars are stacked

* Sort log volumes by data source name

* Simplify logic to determine if log volumes can be zoomed in
2023-04-11 10:05:04 +02:00

58 lines
1.8 KiB
TypeScript

import { render, screen } from '@testing-library/react';
import React from 'react';
import { DataQueryResponse, LoadingState, EventBusSrv } from '@grafana/data';
import { LogsVolumePanel } from './LogsVolumePanel';
jest.mock('./Graph/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={() => {}}
onHiddenSeriesChanged={() => null}
eventBus={new EventBusSrv()}
allLogsVolumeMaximum={20}
/>
);
}
describe('LogsVolumePanel', () => {
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('does not show the panel when there is no volume data', () => {
renderPanel(undefined);
expect(screen.queryByText('Log volume')).not.toBeInTheDocument();
});
it('renders a loading indicator when data is streaming', () => {
renderPanel({ state: LoadingState.Streaming, error: undefined, data: [{}] });
expect(screen.getByTestId('logs-volume-streaming')).toBeInTheDocument();
});
it('does not render loading indicator when data is not streaming', () => {
renderPanel({ state: LoadingState.Done, error: undefined, data: [{}] });
expect(screen.queryByText('logs-volume-streaming')).not.toBeInTheDocument();
});
});