mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Remove global mock of plugin_loader
(#97351)
* Remove global mock of `plugin_loader` Removing this means we can get more accurate datasources behaviour in tests * Fix circular dependency/undefined method when plugin_loader is unmocked * Use optional chaining for trusted policies to stop tests failing when `bootData` is partially set * Add plugin_loader mock back into single test that is still broken * Revert trusted type policies changes * Fix tests that break with trusted type policies
This commit is contained in:
parent
1a22575613
commit
4e10507c84
@ -2,18 +2,12 @@ jest.mock('app/core/core', () => ({}));
|
||||
jest.mock('app/core/config', () => {
|
||||
return {
|
||||
...jest.requireActual('app/core/config'),
|
||||
bootData: {
|
||||
user: {},
|
||||
},
|
||||
panels: {
|
||||
test: {
|
||||
id: 'test',
|
||||
name: 'test',
|
||||
},
|
||||
},
|
||||
config: {
|
||||
appSubUrl: 'test',
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
|
@ -44,6 +44,9 @@ jest.mock('../services/PreferencesService', () => ({
|
||||
},
|
||||
}));
|
||||
|
||||
// FIXME: Tests break unless plugin loader is mocked. This is likely due to a circular dependency
|
||||
jest.mock('app/features/plugins/plugin_loader', () => ({}));
|
||||
|
||||
describe('RichHistoryRemoteStorage', () => {
|
||||
let storage: RichHistoryRemoteStorage;
|
||||
|
||||
|
@ -6,17 +6,6 @@ import { cleanUpAction } from '../actions/cleanUp';
|
||||
|
||||
import { createRootReducer } from './root';
|
||||
|
||||
jest.mock('@grafana/runtime', () => ({
|
||||
...jest.requireActual('@grafana/runtime'),
|
||||
config: {
|
||||
...jest.requireActual('@grafana/runtime').config,
|
||||
bootData: {
|
||||
navTree: [],
|
||||
user: {},
|
||||
},
|
||||
},
|
||||
}));
|
||||
|
||||
describe('rootReducer', () => {
|
||||
const rootReducer = createRootReducer();
|
||||
|
||||
|
@ -4,7 +4,7 @@ import { config } from '@grafana/runtime';
|
||||
import { DataQuery } from '@grafana/schema';
|
||||
import { RefreshPicker } from '@grafana/ui';
|
||||
import { getTimeSrv } from 'app/features/dashboard/services/TimeSrv';
|
||||
import { DEFAULT_RANGE } from 'app/features/explore/state/utils';
|
||||
import { DEFAULT_RANGE } from 'app/features/explore/state/constants';
|
||||
import { getVariablesUrlParams } from 'app/features/variables/getAllVariableValuesForUrl';
|
||||
|
||||
import { DatasourceSrvMock, MockDataSourceApi } from '../../../test/mocks/datasource_srv';
|
||||
|
@ -45,6 +45,7 @@ jest.mock('@grafana/runtime', () => ({
|
||||
newDashboardWithFiltersAndGroupBy: false,
|
||||
},
|
||||
bootData: {
|
||||
...jest.requireActual('@grafana/runtime').config.bootData,
|
||||
user: {
|
||||
timezone: 'Africa/Abidjan',
|
||||
},
|
||||
|
@ -3,10 +3,10 @@ import { isEqual } from 'lodash';
|
||||
import { CoreApp, DataSourceApi, ExploreUrlState, isTruthy } from '@grafana/data';
|
||||
import { DataQuery, DataSourceRef } from '@grafana/schema';
|
||||
import { getLastUsedDatasourceUID } from 'app/core/utils/explore';
|
||||
import { DEFAULT_RANGE } from 'app/features/explore/state/utils';
|
||||
import { getDatasourceSrv } from 'app/features/plugins/datasource_srv';
|
||||
import { MIXED_DATASOURCE_NAME } from 'app/plugins/datasource/mixed/MixedDataSource';
|
||||
|
||||
import { DEFAULT_RANGE } from '../../state/constants';
|
||||
import { isFulfilled } from '../utils';
|
||||
|
||||
export type InitState = 'pending' | 'done' | 'notstarted';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { DEFAULT_RANGE } from 'app/features/explore/state/utils';
|
||||
import { DEFAULT_RANGE } from 'app/features/explore/state/constants';
|
||||
|
||||
import { v0Migrator } from './v0';
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { ExploreUrlState } from '@grafana/data';
|
||||
import { DEFAULT_RANGE } from 'app/features/explore/state/utils';
|
||||
import { DEFAULT_RANGE } from 'app/features/explore/state/constants';
|
||||
|
||||
import { BaseExploreURL, MigrationHandler } from './types';
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { DEFAULT_RANGE } from 'app/features/explore/state/utils';
|
||||
import { DEFAULT_RANGE } from 'app/features/explore/state/constants';
|
||||
|
||||
import { v1Migrator } from './v1';
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { ExploreUrlState } from '@grafana/data';
|
||||
import { ID_ALPHABET, generateExploreId } from 'app/core/utils/explore';
|
||||
import { DEFAULT_RANGE } from 'app/features/explore/state/utils';
|
||||
import { DEFAULT_RANGE } from 'app/features/explore/state/constants';
|
||||
|
||||
import { hasKey } from '../../utils';
|
||||
|
||||
|
6
public/app/features/explore/state/constants.ts
Normal file
6
public/app/features/explore/state/constants.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import { config } from '@grafana/runtime';
|
||||
|
||||
export const DEFAULT_RANGE = {
|
||||
from: `now-${config.exploreDefaultTimeOffset}`,
|
||||
to: 'now',
|
||||
};
|
@ -14,8 +14,9 @@ import { RichHistorySearchFilters, RichHistorySettings } from '../../../core/uti
|
||||
import { createAsyncThunk, ThunkResult } from '../../../types';
|
||||
import { withUniqueRefIds } from '../utils/queries';
|
||||
|
||||
import { DEFAULT_RANGE } from './constants';
|
||||
import { initializeExplore, InitializeExploreOptions, paneReducer } from './explorePane';
|
||||
import { DEFAULT_RANGE, makeExplorePaneState } from './utils';
|
||||
import { makeExplorePaneState } from './utils';
|
||||
|
||||
//
|
||||
// Actions and Payloads
|
||||
@ -157,7 +158,7 @@ export const navigateToExplore = (
|
||||
/**
|
||||
* Global Explore state that handles multiple Explore areas and the split state
|
||||
*/
|
||||
const initialExploreItemState = makeExplorePaneState();
|
||||
const initialExploreItemState = () => makeExplorePaneState();
|
||||
export const initialExploreState: ExploreState = {
|
||||
syncedTimes: false,
|
||||
panes: {},
|
||||
@ -265,7 +266,7 @@ export const exploreReducer = (state = initialExploreState, action: AnyAction):
|
||||
...state,
|
||||
panes: {
|
||||
...state.panes,
|
||||
[action.meta.arg.exploreId]: initialExploreItemState,
|
||||
[action.meta.arg.exploreId]: initialExploreItemState(),
|
||||
},
|
||||
};
|
||||
}
|
||||
@ -274,7 +275,7 @@ export const exploreReducer = (state = initialExploreState, action: AnyAction):
|
||||
const initialPanes = Object.entries(state.panes);
|
||||
const before = initialPanes.slice(0, action.meta.arg.position);
|
||||
const after = initialPanes.slice(before.length);
|
||||
const panes = [...before, [action.meta.arg.exploreId, initialExploreItemState] as const, ...after].reduce(
|
||||
const panes = [...before, [action.meta.arg.exploreId, initialExploreItemState()] as const, ...after].reduce(
|
||||
(acc, [id, pane]) => ({ ...acc, [id]: pane }),
|
||||
{}
|
||||
);
|
||||
|
@ -20,7 +20,7 @@ import {
|
||||
URLRange,
|
||||
URLRangeValue,
|
||||
} from '@grafana/data';
|
||||
import { config, getDataSourceSrv } from '@grafana/runtime';
|
||||
import { getDataSourceSrv } from '@grafana/runtime';
|
||||
import { DataQuery, DataSourceJsonData, DataSourceRef, TimeZone } from '@grafana/schema';
|
||||
import { getLocalRichHistoryStorage } from 'app/core/history/richHistoryStorageProvider';
|
||||
import { SortOrder } from 'app/core/utils/richHistoryTypes';
|
||||
@ -33,12 +33,9 @@ import { setLastUsedDatasourceUID } from '../../../core/utils/explore';
|
||||
import { getDatasourceSrv } from '../../plugins/datasource_srv';
|
||||
import { loadSupplementaryQueries } from '../utils/supplementaryQueries';
|
||||
|
||||
export const MAX_HISTORY_AUTOCOMPLETE_ITEMS = 100;
|
||||
import { DEFAULT_RANGE } from './constants';
|
||||
|
||||
export const DEFAULT_RANGE = {
|
||||
from: `now-${config.exploreDefaultTimeOffset}`,
|
||||
to: 'now',
|
||||
};
|
||||
export const MAX_HISTORY_AUTOCOMPLETE_ITEMS = 100;
|
||||
|
||||
const GRAPH_STYLE_KEY = 'grafana.explore.style.graph';
|
||||
export const storeGraphStyle = (graphStyle: string): void => {
|
||||
|
@ -13,9 +13,6 @@ import { SuggestionName } from 'app/types/suggestions';
|
||||
|
||||
import { getAllSuggestions, panelsToCheckFirst } from './getAllSuggestions';
|
||||
|
||||
jest.unmock('app/core/core');
|
||||
jest.unmock('app/features/plugins/plugin_loader');
|
||||
|
||||
for (const pluginId of panelsToCheckFirst) {
|
||||
config.panels[pluginId] = {
|
||||
module: `core:plugin/${pluginId}`,
|
||||
|
@ -1,6 +1,3 @@
|
||||
// Use the real plugin_loader (stubbed by default)
|
||||
jest.unmock('app/features/plugins/plugin_loader');
|
||||
|
||||
jest.mock('app/core/core', () => {
|
||||
return {
|
||||
coreModule: {
|
||||
|
@ -30,7 +30,6 @@ jest.mock('@grafana/runtime', () => ({
|
||||
licenseUrl: '',
|
||||
},
|
||||
featureToggles: { accesscontrol: true },
|
||||
bootData: { navTree: [], user: {} },
|
||||
buildInfo: {
|
||||
edition: 'Open Source',
|
||||
version: '7.5.0',
|
||||
|
@ -78,7 +78,6 @@ jest.mock('../app/core/core', () => ({
|
||||
appEvents: testAppEvents,
|
||||
}));
|
||||
jest.mock('../app/angular/partials', () => ({}));
|
||||
jest.mock('../app/features/plugins/plugin_loader', () => ({}));
|
||||
|
||||
const throwUnhandledRejections = () => {
|
||||
process.on('unhandledRejection', (err) => {
|
||||
|
Loading…
Reference in New Issue
Block a user