mirror of
https://github.com/grafana/grafana.git
synced 2024-11-28 19:54:10 -06:00
Merge pull request #11973 from grafana/11953-explore-metricpanel
explore: fixes #11953
This commit is contained in:
commit
cebae40468
@ -312,7 +312,7 @@ class MetricsPanelCtrl extends PanelCtrl {
|
||||
|
||||
getAdditionalMenuItems() {
|
||||
const items = [];
|
||||
if (this.datasource.supportsExplore) {
|
||||
if (this.datasource && this.datasource.supportsExplore) {
|
||||
items.push({
|
||||
text: 'Explore',
|
||||
click: 'ctrl.explore();',
|
||||
|
65
public/app/features/panel/specs/metrics_panel_ctrl.jest.ts
Normal file
65
public/app/features/panel/specs/metrics_panel_ctrl.jest.ts
Normal file
@ -0,0 +1,65 @@
|
||||
jest.mock('app/core/core', () => ({}));
|
||||
|
||||
import { MetricsPanelCtrl } from '../metrics_panel_ctrl';
|
||||
import q from 'q';
|
||||
import { PanelModel } from 'app/features/dashboard/panel_model';
|
||||
|
||||
describe('MetricsPanelCtrl', () => {
|
||||
let ctrl;
|
||||
|
||||
beforeEach(() => {
|
||||
ctrl = setupController();
|
||||
});
|
||||
|
||||
describe('when getting additional menu items', () => {
|
||||
let additionalItems;
|
||||
|
||||
describe('and has no datasource set', () => {
|
||||
beforeEach(() => {
|
||||
additionalItems = ctrl.getAdditionalMenuItems();
|
||||
});
|
||||
|
||||
it('should not return any items', () => {
|
||||
expect(additionalItems.length).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('and has datasource set that supports explore', () => {
|
||||
beforeEach(() => {
|
||||
ctrl.datasource = { supportsExplore: true };
|
||||
additionalItems = ctrl.getAdditionalMenuItems();
|
||||
});
|
||||
|
||||
it('should not return any items', () => {
|
||||
expect(additionalItems.length).toBe(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function setupController() {
|
||||
const injectorStub = {
|
||||
get: type => {
|
||||
switch (type) {
|
||||
case '$q': {
|
||||
return q;
|
||||
}
|
||||
default: {
|
||||
return jest.fn();
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
const scope = {
|
||||
panel: { events: [] },
|
||||
appEvent: jest.fn(),
|
||||
onAppEvent: jest.fn(),
|
||||
$on: jest.fn(),
|
||||
colors: [],
|
||||
};
|
||||
|
||||
MetricsPanelCtrl.prototype.panel = new PanelModel({ type: 'test' });
|
||||
|
||||
return new MetricsPanelCtrl(scope, injectorStub);
|
||||
}
|
Loading…
Reference in New Issue
Block a user