mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Karma to Jest: 3 test files (#12414)
* Karma to Jest: viewstate_srv * Karma to Jest: annotations_srv * Remove comments * Karma to Jest: series_override_ctrl * Remove unnecessary code * Class to function and fix lint error * Fix ngInject
This commit is contained in:
parent
443ff5deb4
commit
af0a4a6039
@ -1,17 +1,17 @@
|
||||
import { describe, beforeEach, it, expect, angularMocks } from 'test/lib/common';
|
||||
import '../annotations_srv';
|
||||
import helpers from 'test/specs/helpers';
|
||||
import 'app/features/dashboard/time_srv';
|
||||
import { AnnotationsSrv } from '../annotations_srv';
|
||||
|
||||
describe('AnnotationsSrv', function() {
|
||||
var ctx = new helpers.ServiceTestContext();
|
||||
let $rootScope = {
|
||||
onAppEvent: jest.fn(),
|
||||
};
|
||||
let $q;
|
||||
let datasourceSrv;
|
||||
let backendSrv;
|
||||
let timeSrv;
|
||||
|
||||
beforeEach(angularMocks.module('grafana.core'));
|
||||
beforeEach(angularMocks.module('grafana.services'));
|
||||
beforeEach(ctx.createService('timeSrv'));
|
||||
beforeEach(() => {
|
||||
ctx.createService('annotationsSrv');
|
||||
});
|
||||
let annotationsSrv = new AnnotationsSrv($rootScope, $q, datasourceSrv, backendSrv, timeSrv);
|
||||
|
||||
describe('When translating the query result', () => {
|
||||
const annotationSource = {
|
||||
@ -30,11 +30,11 @@ describe('AnnotationsSrv', function() {
|
||||
let translatedAnnotations;
|
||||
|
||||
beforeEach(() => {
|
||||
translatedAnnotations = ctx.service.translateQueryResult(annotationSource, annotations);
|
||||
translatedAnnotations = annotationsSrv.translateQueryResult(annotationSource, annotations);
|
||||
});
|
||||
|
||||
it('should set defaults', () => {
|
||||
expect(translatedAnnotations[0].source).to.eql(annotationSource);
|
||||
expect(translatedAnnotations[0].source).toEqual(annotationSource);
|
||||
});
|
||||
});
|
||||
});
|
67
public/app/features/dashboard/specs/viewstate_srv.jest.ts
Normal file
67
public/app/features/dashboard/specs/viewstate_srv.jest.ts
Normal file
@ -0,0 +1,67 @@
|
||||
//import { describe, beforeEach, it, expect, angularMocks } from 'test/lib/common';
|
||||
import 'app/features/dashboard/view_state_srv';
|
||||
import config from 'app/core/config';
|
||||
import { DashboardViewState } from '../view_state_srv';
|
||||
|
||||
describe('when updating view state', () => {
|
||||
let location = {
|
||||
replace: jest.fn(),
|
||||
search: jest.fn(),
|
||||
};
|
||||
|
||||
let $scope = {
|
||||
onAppEvent: jest.fn(() => {}),
|
||||
dashboard: {
|
||||
meta: {},
|
||||
panels: [],
|
||||
},
|
||||
};
|
||||
|
||||
let $rootScope = {};
|
||||
let viewState;
|
||||
|
||||
beforeEach(() => {
|
||||
config.bootData = {
|
||||
user: {
|
||||
orgId: 1,
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
describe('to fullscreen true and edit true', () => {
|
||||
beforeEach(() => {
|
||||
location.search = jest.fn(() => {
|
||||
return { fullscreen: true, edit: true, panelId: 1 };
|
||||
});
|
||||
viewState = new DashboardViewState($scope, location, {}, $rootScope);
|
||||
});
|
||||
|
||||
it('should update querystring and view state', () => {
|
||||
var updateState = { fullscreen: true, edit: true, panelId: 1 };
|
||||
|
||||
viewState.update(updateState);
|
||||
|
||||
expect(location.search).toHaveBeenCalledWith({
|
||||
edit: true,
|
||||
editview: null,
|
||||
fullscreen: true,
|
||||
orgId: 1,
|
||||
panelId: 1,
|
||||
});
|
||||
expect(viewState.dashboard.meta.fullscreen).toBe(true);
|
||||
expect(viewState.state.fullscreen).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('to fullscreen false', () => {
|
||||
beforeEach(() => {
|
||||
viewState = new DashboardViewState($scope, location, {}, $rootScope);
|
||||
});
|
||||
it('should remove params from query string', () => {
|
||||
viewState.update({ fullscreen: true, panelId: 1, edit: true });
|
||||
viewState.update({ fullscreen: false });
|
||||
expect(viewState.dashboard.meta.fullscreen).toBe(false);
|
||||
expect(viewState.state.fullscreen).toBe(null);
|
||||
});
|
||||
});
|
||||
});
|
@ -1,65 +0,0 @@
|
||||
import { describe, beforeEach, it, expect, angularMocks } from 'test/lib/common';
|
||||
import 'app/features/dashboard/view_state_srv';
|
||||
import config from 'app/core/config';
|
||||
|
||||
describe('when updating view state', function() {
|
||||
var viewState, location;
|
||||
var timeSrv = {};
|
||||
var templateSrv = {};
|
||||
var contextSrv = {
|
||||
user: {
|
||||
orgId: 19,
|
||||
},
|
||||
};
|
||||
beforeEach(function() {
|
||||
config.bootData = {
|
||||
user: {
|
||||
orgId: 1,
|
||||
},
|
||||
};
|
||||
});
|
||||
beforeEach(angularMocks.module('grafana.services'));
|
||||
beforeEach(
|
||||
angularMocks.module(function($provide) {
|
||||
$provide.value('timeSrv', timeSrv);
|
||||
$provide.value('templateSrv', templateSrv);
|
||||
$provide.value('contextSrv', contextSrv);
|
||||
})
|
||||
);
|
||||
|
||||
beforeEach(
|
||||
angularMocks.inject(function(dashboardViewStateSrv, $location, $rootScope) {
|
||||
$rootScope.onAppEvent = function() {};
|
||||
$rootScope.dashboard = {
|
||||
meta: {},
|
||||
panels: [],
|
||||
};
|
||||
viewState = dashboardViewStateSrv.create($rootScope);
|
||||
location = $location;
|
||||
})
|
||||
);
|
||||
|
||||
describe('to fullscreen true and edit true', function() {
|
||||
it('should update querystring and view state', function() {
|
||||
var updateState = { fullscreen: true, edit: true, panelId: 1 };
|
||||
viewState.update(updateState);
|
||||
expect(location.search()).to.eql({
|
||||
fullscreen: true,
|
||||
edit: true,
|
||||
panelId: 1,
|
||||
orgId: 1,
|
||||
});
|
||||
expect(viewState.dashboard.meta.fullscreen).to.be(true);
|
||||
expect(viewState.state.fullscreen).to.be(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('to fullscreen false', function() {
|
||||
it('should remove params from query string', function() {
|
||||
viewState.update({ fullscreen: true, panelId: 1, edit: true });
|
||||
viewState.update({ fullscreen: false });
|
||||
expect(viewState.dashboard.meta.fullscreen).to.be(false);
|
||||
expect(viewState.state.fullscreen).to.be(null);
|
||||
});
|
||||
});
|
||||
});
|
@ -1,9 +1,8 @@
|
||||
import _ from 'lodash';
|
||||
import angular from 'angular';
|
||||
|
||||
export class SeriesOverridesCtrl {
|
||||
/** @ngInject */
|
||||
constructor($scope, $element, popoverSrv) {
|
||||
export function SeriesOverridesCtrl($scope, $element, popoverSrv) {
|
||||
$scope.overrideMenu = [];
|
||||
$scope.currentOverrides = [];
|
||||
$scope.override = $scope.override || {};
|
||||
@ -155,6 +154,5 @@ export class SeriesOverridesCtrl {
|
||||
$scope.addOverrideOption('Legend', 'legend', [true, false]);
|
||||
$scope.updateCurrentOverrides();
|
||||
}
|
||||
}
|
||||
|
||||
angular.module('grafana.controllers').controller('SeriesOverridesCtrl', SeriesOverridesCtrl);
|
||||
|
@ -0,0 +1,42 @@
|
||||
import '../series_overrides_ctrl';
|
||||
import { SeriesOverridesCtrl } from '../series_overrides_ctrl';
|
||||
|
||||
describe('SeriesOverridesCtrl', () => {
|
||||
let popoverSrv = {};
|
||||
let $scope;
|
||||
|
||||
beforeEach(() => {
|
||||
$scope = {
|
||||
ctrl: {
|
||||
refresh: jest.fn(),
|
||||
render: jest.fn(),
|
||||
seriesList: [],
|
||||
},
|
||||
render: jest.fn(() => {}),
|
||||
};
|
||||
SeriesOverridesCtrl($scope, {}, popoverSrv);
|
||||
});
|
||||
|
||||
describe('When setting an override', () => {
|
||||
beforeEach(() => {
|
||||
$scope.setOverride({ propertyName: 'lines' }, { value: true });
|
||||
});
|
||||
|
||||
it('should set override property', () => {
|
||||
expect($scope.override.lines).toBe(true);
|
||||
});
|
||||
|
||||
it('should update view model', () => {
|
||||
expect($scope.currentOverrides[0].name).toBe('Lines');
|
||||
expect($scope.currentOverrides[0].value).toBe('true');
|
||||
});
|
||||
});
|
||||
|
||||
describe('When removing overide', () => {
|
||||
it('click should include option and value index', () => {
|
||||
$scope.setOverride(1, 0);
|
||||
$scope.removeOverride({ propertyName: 'lines' });
|
||||
expect($scope.currentOverrides.length).toBe(0);
|
||||
});
|
||||
});
|
||||
});
|
@ -1,55 +0,0 @@
|
||||
import { describe, beforeEach, it, expect, sinon, angularMocks } from 'test/lib/common';
|
||||
import '../series_overrides_ctrl';
|
||||
import helpers from 'test/specs/helpers';
|
||||
|
||||
describe('SeriesOverridesCtrl', function() {
|
||||
var ctx = new helpers.ControllerTestContext();
|
||||
var popoverSrv = {};
|
||||
|
||||
beforeEach(angularMocks.module('grafana.services'));
|
||||
beforeEach(angularMocks.module('grafana.controllers'));
|
||||
|
||||
beforeEach(
|
||||
ctx.providePhase({
|
||||
popoverSrv: popoverSrv,
|
||||
})
|
||||
);
|
||||
|
||||
beforeEach(
|
||||
angularMocks.inject(function($rootScope, $controller) {
|
||||
ctx.scope = $rootScope.$new();
|
||||
ctx.scope.ctrl = {
|
||||
refresh: sinon.spy(),
|
||||
render: sinon.spy(),
|
||||
seriesList: [],
|
||||
};
|
||||
ctx.scope.render = function() {};
|
||||
ctx.controller = $controller('SeriesOverridesCtrl', {
|
||||
$scope: ctx.scope,
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
describe('When setting an override', function() {
|
||||
beforeEach(function() {
|
||||
ctx.scope.setOverride({ propertyName: 'lines' }, { value: true });
|
||||
});
|
||||
|
||||
it('should set override property', function() {
|
||||
expect(ctx.scope.override.lines).to.be(true);
|
||||
});
|
||||
|
||||
it('should update view model', function() {
|
||||
expect(ctx.scope.currentOverrides[0].name).to.be('Lines');
|
||||
expect(ctx.scope.currentOverrides[0].value).to.be('true');
|
||||
});
|
||||
});
|
||||
|
||||
describe('When removing overide', function() {
|
||||
it('click should include option and value index', function() {
|
||||
ctx.scope.setOverride(1, 0);
|
||||
ctx.scope.removeOverride({ propertyName: 'lines' });
|
||||
expect(ctx.scope.currentOverrides.length).to.be(0);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user