diff --git a/public/app/features/alerting/unified/components/rules/state-history/LokiStateHistory.test.tsx b/public/app/features/alerting/unified/components/rules/state-history/LokiStateHistory.test.tsx index e9ba271cdec..3925cab0c31 100644 --- a/public/app/features/alerting/unified/components/rules/state-history/LokiStateHistory.test.tsx +++ b/public/app/features/alerting/unified/components/rules/state-history/LokiStateHistory.test.tsx @@ -3,7 +3,8 @@ import { render, waitFor } from '@testing-library/react'; import { http, HttpResponse } from 'msw'; import { setupServer } from 'msw/node'; import React from 'react'; -import { byRole, byText } from 'testing-library-selector'; +import { Props } from 'react-virtualized-auto-sizer'; +import { byRole, byTestId, byText } from 'testing-library-selector'; import { DataFrameJSON } from '@grafana/data'; import { setBackendSrv } from '@grafana/runtime'; @@ -15,6 +16,16 @@ import LokiStateHistory from './LokiStateHistory'; const server = setupServer(); +jest.mock('react-virtualized-auto-sizer', () => { + return ({ children }: Props) => + children({ + height: 600, + scaledHeight: 600, + scaledWidth: 1, + width: 1, + }); +}); + beforeAll(() => { setBackendSrv(backendSrv); server.listen({ onUnhandledRequest: 'error' }); @@ -80,6 +91,7 @@ const ui = { timestampViewer: byRole('list', { name: 'State history by timestamp' }), record: byRole('listitem'), noRecords: byText('No state transitions have occurred in the last 30 days'), + timelineChart: byTestId('uplot-main-div'), }; describe('LokiStateHistory', () => { @@ -96,6 +108,14 @@ describe('LokiStateHistory', () => { expect(timestampViewerElement).toHaveTextContent('/api/folders/:uid/'); }); + it('should render timeline chart', async () => { + render(, { wrapper: TestProvider }); + + await waitFor(() => expect(ui.loadingIndicator.query()).not.toBeInTheDocument()); + + expect(ui.timelineChart.get()).toBeInTheDocument(); + }); + it('should render no entries message when no records are returned', async () => { server.use( http.get('/api/v1/rules/history', () =>