mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Tests: Adds throwUnhandledRejections to jest setup (#19398)
* Chore: Adds throwUnhandledRejections to jest setup * Bring back @grafana/runtime import * Fix broken metric metadata aggregation test
This commit is contained in:
parent
97beb26f0c
commit
0598d60234
@ -1,9 +1,9 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import { TestRuleResult, Props } from './TestRuleResult';
|
||||||
|
import { DashboardModel } from '../dashboard/state';
|
||||||
import { shallow } from 'enzyme';
|
import { shallow } from 'enzyme';
|
||||||
import { DashboardModel } from '../dashboard/state/DashboardModel';
|
|
||||||
import { Props, TestRuleResult } from './TestRuleResult';
|
|
||||||
|
|
||||||
jest.mock('app/core/services/backend_srv', () => ({
|
jest.mock('@grafana/runtime/src/services/backendSrv', () => ({
|
||||||
getBackendSrv: () => ({
|
getBackendSrv: () => ({
|
||||||
post: jest.fn(),
|
post: jest.fn(),
|
||||||
}),
|
}),
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
import React, { PureComponent } from 'react';
|
import React, { PureComponent } from 'react';
|
||||||
|
import { LoadingPlaceholder, JSONFormatter } from '@grafana/ui';
|
||||||
|
|
||||||
import appEvents from 'app/core/app_events';
|
import appEvents from 'app/core/app_events';
|
||||||
import { CopyToClipboard } from 'app/core/components/CopyToClipboard/CopyToClipboard';
|
import { CopyToClipboard } from 'app/core/components/CopyToClipboard/CopyToClipboard';
|
||||||
import { getBackendSrv } from '@grafana/runtime';
|
|
||||||
import { DashboardModel } from '../dashboard/state/DashboardModel';
|
import { DashboardModel } from '../dashboard/state/DashboardModel';
|
||||||
import { LoadingPlaceholder, JSONFormatter } from '@grafana/ui';
|
import { getBackendSrv, BackendSrv } from '@grafana/runtime';
|
||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
panelId: number;
|
panelId: number;
|
||||||
@ -25,6 +26,12 @@ export class TestRuleResult extends PureComponent<Props, State> {
|
|||||||
|
|
||||||
formattedJson: any;
|
formattedJson: any;
|
||||||
clipboard: any;
|
clipboard: any;
|
||||||
|
backendSrv: BackendSrv = null;
|
||||||
|
|
||||||
|
constructor(props: Props) {
|
||||||
|
super(props);
|
||||||
|
this.backendSrv = getBackendSrv();
|
||||||
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.testRule();
|
this.testRule();
|
||||||
@ -35,7 +42,7 @@ export class TestRuleResult extends PureComponent<Props, State> {
|
|||||||
const payload = { dashboard: dashboard.getSaveModelClone(), panelId };
|
const payload = { dashboard: dashboard.getSaveModelClone(), panelId };
|
||||||
|
|
||||||
this.setState({ isLoading: true });
|
this.setState({ isLoading: true });
|
||||||
const testRuleResponse = await getBackendSrv().post(`/api/alerts/test`, payload);
|
const testRuleResponse = await this.backendSrv.post(`/api/alerts/test`, payload);
|
||||||
this.setState({ isLoading: false, testRuleResponse });
|
this.setState({ isLoading: false, testRuleResponse });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,8 +194,8 @@ describe('AzureMonitorQueryCtrl', () => {
|
|||||||
describe('when onMetricNameChange is triggered for the Metric Names dropdown', () => {
|
describe('when onMetricNameChange is triggered for the Metric Names dropdown', () => {
|
||||||
const response: any = {
|
const response: any = {
|
||||||
primaryAggType: 'Average',
|
primaryAggType: 'Average',
|
||||||
supportAggOptions: ['Average', 'Total'],
|
supportedAggTypes: ['Average', 'Total'],
|
||||||
supportedTimeGrains: ['PT1M', 'P1D'],
|
supportedTimeGrains: [{ text: 'PT1M', value: 'PT1M' }, { text: 'P1D', value: 'P1D' }],
|
||||||
dimensions: [],
|
dimensions: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -227,8 +227,12 @@ describe('AzureMonitorQueryCtrl', () => {
|
|||||||
it('should set the options and default selected value for the Aggregations dropdown', () => {
|
it('should set the options and default selected value for the Aggregations dropdown', () => {
|
||||||
queryCtrl.onMetricNameChange().then(() => {
|
queryCtrl.onMetricNameChange().then(() => {
|
||||||
expect(queryCtrl.target.azureMonitor.aggregation).toBe('Average');
|
expect(queryCtrl.target.azureMonitor.aggregation).toBe('Average');
|
||||||
expect(queryCtrl.target.azureMonitor.aggOptions).toBe(['Average', 'Total']);
|
expect(queryCtrl.target.azureMonitor.aggOptions).toEqual(['Average', 'Total']);
|
||||||
expect(queryCtrl.target.azureMonitor.timeGrains).toBe(['PT1M', 'P1D']);
|
expect(queryCtrl.target.azureMonitor.timeGrains).toEqual([
|
||||||
|
{ text: 'auto', value: 'auto' },
|
||||||
|
{ text: 'PT1M', value: 'PT1M' },
|
||||||
|
{ text: 'P1D', value: 'P1D' },
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -6,7 +6,7 @@ import './editor/editor_component';
|
|||||||
import kbn from 'app/core/utils/kbn';
|
import kbn from 'app/core/utils/kbn';
|
||||||
|
|
||||||
import { TemplateSrv } from 'app/features/templating/template_srv';
|
import { TemplateSrv } from 'app/features/templating/template_srv';
|
||||||
import { auto } from 'angular';
|
import { auto, IPromise } from 'angular';
|
||||||
import { DataFrame } from '@grafana/data';
|
import { DataFrame } from '@grafana/data';
|
||||||
|
|
||||||
export interface ResultFormat {
|
export interface ResultFormat {
|
||||||
@ -396,9 +396,9 @@ export class AzureMonitorQueryCtrl extends QueryCtrl {
|
|||||||
this.target.azureMonitor.dimension = '';
|
this.target.azureMonitor.dimension = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
onMetricNameChange() {
|
onMetricNameChange(): IPromise<void> {
|
||||||
if (!this.target.azureMonitor.metricName || this.target.azureMonitor.metricName === this.defaultDropdownValue) {
|
if (!this.target.azureMonitor.metricName || this.target.azureMonitor.metricName === this.defaultDropdownValue) {
|
||||||
return;
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.datasource
|
return this.datasource
|
||||||
|
@ -41,3 +41,11 @@ const localStorageMock = (() => {
|
|||||||
|
|
||||||
global.localStorage = localStorageMock;
|
global.localStorage = localStorageMock;
|
||||||
// Object.defineProperty(window, 'localStorage', { value: localStorageMock });
|
// Object.defineProperty(window, 'localStorage', { value: localStorageMock });
|
||||||
|
|
||||||
|
const throwUnhandledRejections = () => {
|
||||||
|
process.on('unhandledRejection', err => {
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
throwUnhandledRejections();
|
||||||
|
Loading…
Reference in New Issue
Block a user