|
|
@@ -1,8 +1,6 @@
|
|
|
jest.mock('app/core/core', () => ({}));
|
|
|
jest.mock('app/core/config', () => {
|
|
|
return {
|
|
|
- exploreEnabled: true,
|
|
|
- viewersCanEdit: false,
|
|
|
panels: {
|
|
|
test: {
|
|
|
id: 'test',
|
|
|
@@ -15,62 +13,47 @@ jest.mock('app/core/config', () => {
|
|
|
import q from 'q';
|
|
|
import { PanelModel } from 'app/features/dashboard/panel_model';
|
|
|
import { MetricsPanelCtrl } from '../metrics_panel_ctrl';
|
|
|
-import config from 'app/core/config';
|
|
|
|
|
|
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();
|
|
|
- });
|
|
|
-
|
|
|
+ describe('and has no datasource set but user has access to explore', () => {
|
|
|
it('should not return any items', () => {
|
|
|
- expect(additionalItems.length).toBe(0);
|
|
|
+ const ctrl = setupController({ hasAccessToExplore: true });
|
|
|
+
|
|
|
+ expect(ctrl.getAdditionalMenuItems().length).toBe(0);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- describe('and has datasource set that supports explore and user has powers', () => {
|
|
|
- beforeEach(() => {
|
|
|
- ctrl.contextSrv = { isEditor: true };
|
|
|
+ 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 });
|
|
|
ctrl.datasource = { meta: { explore: true } };
|
|
|
- additionalItems = ctrl.getAdditionalMenuItems();
|
|
|
- });
|
|
|
|
|
|
- it('should not return any items', () => {
|
|
|
- expect(additionalItems.length).toBe(1);
|
|
|
+ expect(ctrl.getAdditionalMenuItems().length).toBe(0);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- describe('and has datasource set that supports explore and viewersCanEdit is true', () => {
|
|
|
- beforeEach(() => {
|
|
|
- config.viewersCanEdit = true;
|
|
|
- ctrl.contextSrv = { isEditor: false };
|
|
|
+ describe('and has datasource set that supports explore and user has access to explore', () => {
|
|
|
+ it('should return one item', () => {
|
|
|
+ const ctrl = setupController({ hasAccessToExplore: true });
|
|
|
ctrl.datasource = { meta: { explore: true } };
|
|
|
- additionalItems = ctrl.getAdditionalMenuItems();
|
|
|
- });
|
|
|
|
|
|
- it('should not return any items', () => {
|
|
|
- expect(additionalItems.length).toBe(1);
|
|
|
+ expect(ctrl.getAdditionalMenuItems().length).toBe(1);
|
|
|
});
|
|
|
});
|
|
|
});
|
|
|
});
|
|
|
|
|
|
-function setupController() {
|
|
|
+function setupController({ hasAccessToExplore } = { hasAccessToExplore: false }) {
|
|
|
const injectorStub = {
|
|
|
get: type => {
|
|
|
switch (type) {
|
|
|
case '$q': {
|
|
|
return q;
|
|
|
}
|
|
|
+ case 'contextSrv': {
|
|
|
+ return { hasAccessToExplore: () => hasAccessToExplore };
|
|
|
+ }
|
|
|
default: {
|
|
|
return jest.fn();
|
|
|
}
|