2018-05-17 14:56:15 +02:00
|
|
|
jest.mock('app/core/core', () => ({}));
|
2018-06-06 11:15:24 +02:00
|
|
|
jest.mock('app/core/config', () => {
|
|
|
|
|
return {
|
|
|
|
|
panels: {
|
|
|
|
|
test: {
|
|
|
|
|
id: 'test',
|
|
|
|
|
name: 'test',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
});
|
2018-05-17 14:56:15 +02:00
|
|
|
|
|
|
|
|
import q from 'q';
|
|
|
|
|
import { PanelModel } from 'app/features/dashboard/panel_model';
|
2018-06-06 11:15:24 +02:00
|
|
|
import { MetricsPanelCtrl } from '../metrics_panel_ctrl';
|
2018-05-17 14:56:15 +02:00
|
|
|
|
|
|
|
|
describe('MetricsPanelCtrl', () => {
|
|
|
|
|
describe('when getting additional menu items', () => {
|
2019-01-21 10:50:34 +01:00
|
|
|
describe('and has no datasource set but user has access to explore', () => {
|
2018-05-17 14:56:15 +02:00
|
|
|
it('should not return any items', () => {
|
2019-01-21 10:50:34 +01:00
|
|
|
const ctrl = setupController({ hasAccessToExplore: true });
|
|
|
|
|
|
|
|
|
|
expect(ctrl.getAdditionalMenuItems().length).toBe(0);
|
2018-05-17 14:56:15 +02:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2019-01-21 10:50:34 +01:00
|
|
|
describe('and has datasource set that supports explore and user does not have access to explore', () => {
|
|
|
|
|
it('should not return any items', () => {
|
|
|
|
|
const ctrl = setupController({ hasAccessToExplore: false });
|
2018-09-24 17:47:43 +02:00
|
|
|
ctrl.datasource = { meta: { explore: true } };
|
2018-05-17 14:56:15 +02:00
|
|
|
|
2019-01-21 10:50:34 +01:00
|
|
|
expect(ctrl.getAdditionalMenuItems().length).toBe(0);
|
2018-05-17 14:56:15 +02:00
|
|
|
});
|
|
|
|
|
});
|
2019-01-21 08:47:41 +01:00
|
|
|
|
2019-01-21 10:50:34 +01:00
|
|
|
describe('and has datasource set that supports explore and user has access to explore', () => {
|
|
|
|
|
it('should return one item', () => {
|
|
|
|
|
const ctrl = setupController({ hasAccessToExplore: true });
|
2019-01-21 08:47:41 +01:00
|
|
|
ctrl.datasource = { meta: { explore: true } };
|
|
|
|
|
|
2019-01-21 10:50:34 +01:00
|
|
|
expect(ctrl.getAdditionalMenuItems().length).toBe(1);
|
2019-01-21 08:47:41 +01:00
|
|
|
});
|
|
|
|
|
});
|
2018-05-17 14:56:15 +02:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2019-01-21 10:50:34 +01:00
|
|
|
function setupController({ hasAccessToExplore } = { hasAccessToExplore: false }) {
|
2018-05-17 14:56:15 +02:00
|
|
|
const injectorStub = {
|
|
|
|
|
get: type => {
|
|
|
|
|
switch (type) {
|
|
|
|
|
case '$q': {
|
|
|
|
|
return q;
|
|
|
|
|
}
|
2019-01-21 10:50:34 +01:00
|
|
|
case 'contextSrv': {
|
|
|
|
|
return { hasAccessToExplore: () => hasAccessToExplore };
|
|
|
|
|
}
|
2018-05-17 14:56:15 +02:00
|
|
|
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);
|
|
|
|
|
}
|