mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: fix act warnings in alerting tests (#45113)
* fix act warnings in alerting tests * remove unnecessary angular dep
This commit is contained in:
@@ -3,7 +3,7 @@ import { locationService, setDataSourceSrv } from '@grafana/runtime';
|
||||
import { configureStore } from 'app/store/configureStore';
|
||||
import { Provider } from 'react-redux';
|
||||
import { Router } from 'react-router-dom';
|
||||
import { render } from '@testing-library/react';
|
||||
import { render, act } from '@testing-library/react';
|
||||
import { PanelAlertTabContent } from './PanelAlertTabContent';
|
||||
import { DashboardModel, PanelModel } from 'app/features/dashboard/state';
|
||||
import {
|
||||
@@ -57,13 +57,15 @@ const mocks = {
|
||||
const renderAlertTabContent = (dashboard: DashboardModel, panel: PanelModel) => {
|
||||
const store = configureStore();
|
||||
|
||||
return render(
|
||||
<Provider store={store}>
|
||||
<Router history={locationService.getHistory()}>
|
||||
<PanelAlertTabContent dashboard={dashboard} panel={panel} />
|
||||
</Router>
|
||||
</Provider>
|
||||
);
|
||||
return act(async () => {
|
||||
render(
|
||||
<Provider store={store}>
|
||||
<Router history={locationService.getHistory()}>
|
||||
<PanelAlertTabContent dashboard={dashboard} panel={panel} />
|
||||
</Router>
|
||||
</Provider>
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
const rules = [
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import React from 'react';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { act, render, screen } from '@testing-library/react';
|
||||
import { Provider } from 'react-redux';
|
||||
import { Router } from 'react-router-dom';
|
||||
import { DataSourceJsonData, PluginMeta } from '@grafana/data';
|
||||
@@ -29,20 +29,22 @@ jest.mock('@grafana/runtime', () => ({
|
||||
|
||||
const store = configureStore();
|
||||
const renderRuleViewer = () => {
|
||||
return render(
|
||||
<Provider store={store}>
|
||||
<Router history={locationService.getHistory()}>
|
||||
<RuleViewer {...mockRoute} />
|
||||
</Router>
|
||||
</Provider>
|
||||
);
|
||||
return act(async () => {
|
||||
render(
|
||||
<Provider store={store}>
|
||||
<Router history={locationService.getHistory()}>
|
||||
<RuleViewer {...mockRoute} />
|
||||
</Router>
|
||||
</Provider>
|
||||
);
|
||||
});
|
||||
};
|
||||
describe('RuleViewer', () => {
|
||||
afterEach(() => {
|
||||
jest.resetAllMocks();
|
||||
});
|
||||
|
||||
it('should render page with grafana alert', () => {
|
||||
it('should render page with grafana alert', async () => {
|
||||
typeAsJestMock(useCombinedRule).mockReturnValue({
|
||||
result: mockGrafanaRule as CombinedRule,
|
||||
loading: false,
|
||||
@@ -50,13 +52,13 @@ describe('RuleViewer', () => {
|
||||
requestId: 'A',
|
||||
error: undefined,
|
||||
});
|
||||
await renderRuleViewer();
|
||||
|
||||
renderRuleViewer();
|
||||
expect(screen.getByText('Alerting / View rule')).toBeInTheDocument();
|
||||
expect(screen.getByText('Test alert')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should render page with cloud alert', () => {
|
||||
it('should render page with cloud alert', async () => {
|
||||
typeAsJestMock(useCombinedRule).mockReturnValue({
|
||||
result: mockCloudRule as CombinedRule,
|
||||
loading: false,
|
||||
@@ -64,7 +66,7 @@ describe('RuleViewer', () => {
|
||||
requestId: 'A',
|
||||
error: undefined,
|
||||
});
|
||||
renderRuleViewer();
|
||||
await renderRuleViewer();
|
||||
expect(screen.getByText('Alerting / View rule')).toBeInTheDocument();
|
||||
expect(screen.getByText('Cloud test alert')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { isArray } from 'angular';
|
||||
import { AsyncThunk, createSlice, Draft, isAsyncThunkAction, PayloadAction, SerializedError } from '@reduxjs/toolkit';
|
||||
import { FetchError } from '@grafana/runtime';
|
||||
import { AppEvents } from '@grafana/data';
|
||||
@@ -147,7 +146,7 @@ export function messageFromError(e: Error | FetchError | SerializedError): strin
|
||||
msg += `; ${e.data.error}`;
|
||||
}
|
||||
return msg;
|
||||
} else if (isArray(e.data) && e.data.length && e.data[0]?.message) {
|
||||
} else if (Array.isArray(e.data) && e.data.length && e.data[0]?.message) {
|
||||
return e.data
|
||||
.map((d) => d?.message)
|
||||
.filter((m) => !!m)
|
||||
|
||||
Reference in New Issue
Block a user