mirror of
https://github.com/grafana/grafana.git
synced 2024-11-24 09:50:29 -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 { TestRuleResult, Props } from './TestRuleResult';
|
||||
import { DashboardModel } from '../dashboard/state';
|
||||
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: () => ({
|
||||
post: jest.fn(),
|
||||
}),
|
||||
|
@ -1,9 +1,10 @@
|
||||
import React, { PureComponent } from 'react';
|
||||
import { LoadingPlaceholder, JSONFormatter } from '@grafana/ui';
|
||||
|
||||
import appEvents from 'app/core/app_events';
|
||||
import { CopyToClipboard } from 'app/core/components/CopyToClipboard/CopyToClipboard';
|
||||
import { getBackendSrv } from '@grafana/runtime';
|
||||
import { DashboardModel } from '../dashboard/state/DashboardModel';
|
||||
import { LoadingPlaceholder, JSONFormatter } from '@grafana/ui';
|
||||
import { getBackendSrv, BackendSrv } from '@grafana/runtime';
|
||||
|
||||
export interface Props {
|
||||
panelId: number;
|
||||
@ -25,6 +26,12 @@ export class TestRuleResult extends PureComponent<Props, State> {
|
||||
|
||||
formattedJson: any;
|
||||
clipboard: any;
|
||||
backendSrv: BackendSrv = null;
|
||||
|
||||
constructor(props: Props) {
|
||||
super(props);
|
||||
this.backendSrv = getBackendSrv();
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.testRule();
|
||||
@ -35,7 +42,7 @@ export class TestRuleResult extends PureComponent<Props, State> {
|
||||
const payload = { dashboard: dashboard.getSaveModelClone(), panelId };
|
||||
|
||||
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 });
|
||||
}
|
||||
|
||||
|
@ -194,8 +194,8 @@ describe('AzureMonitorQueryCtrl', () => {
|
||||
describe('when onMetricNameChange is triggered for the Metric Names dropdown', () => {
|
||||
const response: any = {
|
||||
primaryAggType: 'Average',
|
||||
supportAggOptions: ['Average', 'Total'],
|
||||
supportedTimeGrains: ['PT1M', 'P1D'],
|
||||
supportedAggTypes: ['Average', 'Total'],
|
||||
supportedTimeGrains: [{ text: 'PT1M', value: 'PT1M' }, { text: 'P1D', value: 'P1D' }],
|
||||
dimensions: [],
|
||||
};
|
||||
|
||||
@ -227,8 +227,12 @@ describe('AzureMonitorQueryCtrl', () => {
|
||||
it('should set the options and default selected value for the Aggregations dropdown', () => {
|
||||
queryCtrl.onMetricNameChange().then(() => {
|
||||
expect(queryCtrl.target.azureMonitor.aggregation).toBe('Average');
|
||||
expect(queryCtrl.target.azureMonitor.aggOptions).toBe(['Average', 'Total']);
|
||||
expect(queryCtrl.target.azureMonitor.timeGrains).toBe(['PT1M', 'P1D']);
|
||||
expect(queryCtrl.target.azureMonitor.aggOptions).toEqual(['Average', 'Total']);
|
||||
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 { TemplateSrv } from 'app/features/templating/template_srv';
|
||||
import { auto } from 'angular';
|
||||
import { auto, IPromise } from 'angular';
|
||||
import { DataFrame } from '@grafana/data';
|
||||
|
||||
export interface ResultFormat {
|
||||
@ -396,9 +396,9 @@ export class AzureMonitorQueryCtrl extends QueryCtrl {
|
||||
this.target.azureMonitor.dimension = '';
|
||||
}
|
||||
|
||||
onMetricNameChange() {
|
||||
onMetricNameChange(): IPromise<void> {
|
||||
if (!this.target.azureMonitor.metricName || this.target.azureMonitor.metricName === this.defaultDropdownValue) {
|
||||
return;
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
return this.datasource
|
||||
|
@ -41,3 +41,11 @@ const localStorageMock = (() => {
|
||||
|
||||
global.localStorage = localStorageMock;
|
||||
// Object.defineProperty(window, 'localStorage', { value: localStorageMock });
|
||||
|
||||
const throwUnhandledRejections = () => {
|
||||
process.on('unhandledRejection', err => {
|
||||
throw err;
|
||||
});
|
||||
};
|
||||
|
||||
throwUnhandledRejections();
|
||||
|
Loading…
Reference in New Issue
Block a user