2022-04-22 08:33:13 -05:00
|
|
|
// This import has side effects, and must be at the top so jQuery is made global before
|
|
|
|
// angular is imported.
|
|
|
|
import './global-jquery-shim';
|
|
|
|
|
|
|
|
import angular from 'angular';
|
2023-07-31 11:04:48 -05:00
|
|
|
import { TextEncoder, TextDecoder } from 'util';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
2021-11-09 05:30:04 -06:00
|
|
|
import { EventBusSrv } from '@grafana/data';
|
2022-11-23 15:32:52 -06:00
|
|
|
import { GrafanaBootConfig } from '@grafana/runtime';
|
2023-10-13 07:11:41 -05:00
|
|
|
import { initIconCache } from 'app/core/icons/iconBundle';
|
2023-07-31 11:04:48 -05:00
|
|
|
|
2022-09-29 09:09:40 -05:00
|
|
|
import 'blob-polyfill';
|
2020-02-17 04:13:13 -06:00
|
|
|
import 'mutationobserver-shim';
|
2021-11-09 11:05:01 -06:00
|
|
|
import './mocks/workers';
|
2019-11-07 05:37:46 -06:00
|
|
|
|
2022-04-22 08:33:13 -05:00
|
|
|
import '../vendor/flot/jquery.flot';
|
|
|
|
import '../vendor/flot/jquery.flot.time';
|
|
|
|
|
2023-10-13 07:11:41 -05:00
|
|
|
// icon cache needs to be initialized for test to prevent
|
|
|
|
// libraries such as msw from throwing "unhandled resource"-errors
|
|
|
|
initIconCache();
|
|
|
|
|
2021-11-09 05:30:04 -06:00
|
|
|
const testAppEvents = new EventBusSrv();
|
2019-11-07 05:37:46 -06:00
|
|
|
const global = window as any;
|
|
|
|
global.$ = global.jQuery = $;
|
|
|
|
|
2022-11-23 15:32:52 -06:00
|
|
|
// mock the default window.grafanaBootData settings
|
|
|
|
const settings: Partial<GrafanaBootConfig> = {
|
|
|
|
angularSupportEnabled: true,
|
|
|
|
};
|
|
|
|
global.grafanaBootData = {
|
|
|
|
settings,
|
|
|
|
user: {},
|
|
|
|
navTree: [],
|
|
|
|
};
|
|
|
|
|
2021-06-17 13:20:27 -05:00
|
|
|
// https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom
|
|
|
|
Object.defineProperty(global, 'matchMedia', {
|
|
|
|
writable: true,
|
|
|
|
value: jest.fn().mockImplementation((query) => ({
|
|
|
|
matches: false,
|
|
|
|
media: query,
|
|
|
|
onchange: null,
|
|
|
|
addListener: jest.fn(), // deprecated
|
|
|
|
removeListener: jest.fn(), // deprecated
|
|
|
|
addEventListener: jest.fn(),
|
|
|
|
removeEventListener: jest.fn(),
|
|
|
|
dispatchEvent: jest.fn(),
|
|
|
|
})),
|
|
|
|
});
|
|
|
|
|
2018-06-12 09:14:22 -05:00
|
|
|
angular.module('grafana', ['ngRoute']);
|
|
|
|
angular.module('grafana.services', ['ngRoute', '$strap.directives']);
|
|
|
|
angular.module('grafana.panels', []);
|
|
|
|
angular.module('grafana.controllers', []);
|
|
|
|
angular.module('grafana.directives', []);
|
|
|
|
angular.module('grafana.filters', []);
|
|
|
|
angular.module('grafana.routes', ['ngRoute']);
|
|
|
|
|
2023-06-23 02:50:51 -05:00
|
|
|
// mock the intersection observer and just say everything is in view
|
|
|
|
const mockIntersectionObserver = jest
|
|
|
|
.fn()
|
|
|
|
.mockImplementation((callback: (arg: IntersectionObserverEntry[]) => void) => ({
|
|
|
|
observe: jest.fn().mockImplementation((elem: HTMLElement) => {
|
|
|
|
callback([{ target: elem, isIntersecting: true }] as unknown as IntersectionObserverEntry[]);
|
|
|
|
}),
|
|
|
|
unobserve: jest.fn(),
|
|
|
|
disconnect: jest.fn(),
|
|
|
|
}));
|
2022-08-24 05:19:36 -05:00
|
|
|
global.IntersectionObserver = mockIntersectionObserver;
|
|
|
|
|
2023-07-31 11:04:48 -05:00
|
|
|
global.TextEncoder = TextEncoder;
|
|
|
|
global.TextDecoder = TextDecoder;
|
|
|
|
|
2022-07-20 02:25:09 -05:00
|
|
|
jest.mock('../app/core/core', () => ({
|
|
|
|
...jest.requireActual('../app/core/core'),
|
|
|
|
appEvents: testAppEvents,
|
|
|
|
}));
|
2021-10-27 08:21:07 -05:00
|
|
|
jest.mock('../app/angular/partials', () => ({}));
|
|
|
|
jest.mock('../app/features/plugins/plugin_loader', () => ({}));
|
2017-10-22 00:03:26 -05:00
|
|
|
|
2019-09-25 07:10:11 -05:00
|
|
|
const throwUnhandledRejections = () => {
|
2021-01-20 00:59:48 -06:00
|
|
|
process.on('unhandledRejection', (err) => {
|
2019-09-25 07:10:11 -05:00
|
|
|
throw err;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
throwUnhandledRejections();
|
2023-07-12 06:37:26 -05:00
|
|
|
|
|
|
|
// Used by useMeasure
|
|
|
|
global.ResizeObserver = class ResizeObserver {
|
|
|
|
//callback: ResizeObserverCallback;
|
|
|
|
|
|
|
|
constructor(callback: ResizeObserverCallback) {
|
|
|
|
setTimeout(() => {
|
|
|
|
callback(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
contentRect: {
|
|
|
|
x: 1,
|
|
|
|
y: 2,
|
|
|
|
width: 500,
|
|
|
|
height: 500,
|
|
|
|
top: 100,
|
|
|
|
bottom: 0,
|
|
|
|
left: 100,
|
|
|
|
right: 0,
|
|
|
|
},
|
2023-07-31 11:04:48 -05:00
|
|
|
target: {},
|
2023-07-12 06:37:26 -05:00
|
|
|
} as ResizeObserverEntry,
|
|
|
|
],
|
|
|
|
this
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
observe() {}
|
|
|
|
disconnect() {}
|
|
|
|
unobserve() {}
|
|
|
|
};
|