Add whatwg-fetch and fixes to dashboard tests that break when polyfill is added

pull/85578/head
Tom Ratcliffe 1 year ago committed by Tom Ratcliffe
parent 2674043cef
commit 2ab13071fb
  1. 6
      public/app/features/dashboard-scene/panel-edit/PanelDataPane/PanelDataAlertingTab.test.tsx
  2. 7
      public/app/features/dashboard/containers/PublicDashboardPageProxy.test.tsx
  3. 7
      public/app/features/explore/extensions/AddToDashboard/index.test.tsx

@ -1,3 +1,4 @@
import 'whatwg-fetch';
import { act, render } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import React from 'react';
@ -7,6 +8,7 @@ import { byTestId } from 'testing-library-selector';
import { DataSourceApi } from '@grafana/data';
import { PromOptions, PrometheusDatasource } from '@grafana/prometheus';
import { locationService, setDataSourceSrv } from '@grafana/runtime';
import { backendSrv } from 'app/core/services/backend_srv';
import { fetchRules } from 'app/features/alerting/unified/api/prometheus';
import { fetchRulerRules } from 'app/features/alerting/unified/api/ruler';
import * as ruleActionButtons from 'app/features/alerting/unified/components/rules/RuleActionsButtons';
@ -14,6 +16,7 @@ import {
MockDataSourceSrv,
grantUserPermissions,
mockDataSource,
mockFolder,
mockPromAlertingRule,
mockPromRuleGroup,
mockPromRuleNamespace,
@ -192,6 +195,9 @@ describe('PanelAlertTabContent', () => {
AccessControlAction.AlertingRuleExternalRead,
AccessControlAction.AlertingRuleExternalWrite,
]);
jest.spyOn(backendSrv, 'getFolderByUid').mockResolvedValue(mockFolder());
mocks.getAllDataSources.mockReturnValue(Object.values(dataSources));
const dsService = new MockDataSourceSrv(dataSources);
dsService.datasources[dataSources.prometheus.uid] = new PrometheusDatasource(

@ -1,3 +1,4 @@
import 'whatwg-fetch';
import { render, screen, waitFor } from '@testing-library/react';
import React from 'react';
import { Provider } from 'react-redux';
@ -7,6 +8,7 @@ import { getGrafanaContextMock } from 'test/mocks/getGrafanaContextMock';
import { selectors as e2eSelectors } from '@grafana/e2e-selectors';
import { config, locationService } from '@grafana/runtime';
import { GrafanaContext } from 'app/core/context/GrafanaContext';
import { backendSrv } from 'app/core/services/backend_srv';
import { configureStore } from 'app/store/configureStore';
import { DashboardRoutes } from '../../../types';
@ -50,6 +52,11 @@ function setup(props: Partial<PublicDashboardPageProxyProps>) {
describe('PublicDashboardPageProxy', () => {
beforeEach(() => {
config.featureToggles.publicDashboardsScene = false;
// Mock the dashboard UID response so we don't get any refused connection errors
// from this test (as the fetch polyfill means this logic would actually try and call the API)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
jest.spyOn(backendSrv, 'getPublicDashboardByUid').mockResolvedValue({ dashboard: {}, meta: {} } as any);
});
describe('when scene feature enabled', () => {

@ -1,3 +1,4 @@
import 'whatwg-fetch';
import { act, render, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import React, { ReactNode } from 'react';
@ -56,6 +57,12 @@ describe('AddToDashboardButton', () => {
setEchoSrv(new Echo());
});
beforeEach(() => {
// Mock the search response so we don't get any refused connection errors
// from this test (as the fetch polyfill means this logic would actually try and call the API)
jest.spyOn(backendSrv, 'search').mockResolvedValue([]);
});
it('Is disabled if explore pane has no queries', async () => {
setup(<AddToDashboard exploreId={'left'} />, []);

Loading…
Cancel
Save