Alerting: fix act warnings in alerting tests (#45113)

* fix act warnings in alerting tests

* remove unnecessary angular dep
This commit is contained in:
Nathan Rodman
2022-02-09 08:47:50 -08:00
committed by GitHub
parent 78fc0258b1
commit f019ee886a
3 changed files with 25 additions and 22 deletions

View File

@@ -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(
return act(async () => {
render(
<Provider store={store}>
<Router history={locationService.getHistory()}>
<PanelAlertTabContent dashboard={dashboard} panel={panel} />
</Router>
</Provider>
);
});
};
const rules = [

View File

@@ -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(
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();
});

View File

@@ -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)