mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
tests(playlist): adds ctrl test for playlist edit
This commit is contained in:
parent
b79f04493d
commit
feca2871eb
@ -9,7 +9,6 @@ function (angular, config, _) {
|
|||||||
var module = angular.module('grafana.controllers');
|
var module = angular.module('grafana.controllers');
|
||||||
|
|
||||||
module.controller('PlaylistEditCtrl', function($scope, playlistSrv, backendSrv, $location, $route) {
|
module.controller('PlaylistEditCtrl', function($scope, playlistSrv, backendSrv, $location, $route) {
|
||||||
$scope.timespan = config.playlist_timespan;
|
|
||||||
$scope.filteredPlaylistItems = [];
|
$scope.filteredPlaylistItems = [];
|
||||||
$scope.foundPlaylistItems = [];
|
$scope.foundPlaylistItems = [];
|
||||||
$scope.searchQuery = '';
|
$scope.searchQuery = '';
|
||||||
@ -17,19 +16,23 @@ function (angular, config, _) {
|
|||||||
$scope.playlist = {};
|
$scope.playlist = {};
|
||||||
$scope.playlistItems = [];
|
$scope.playlistItems = [];
|
||||||
|
|
||||||
if ($route.current.params.id) {
|
$scope.init = function() {
|
||||||
var playlistId = $route.current.params.id;
|
if ($route.current.params.id) {
|
||||||
|
var playlistId = $route.current.params.id;
|
||||||
|
|
||||||
backendSrv.get('/api/playlists/' + playlistId)
|
backendSrv.get('/api/playlists/' + playlistId)
|
||||||
.then(function(result) {
|
.then(function(result) {
|
||||||
$scope.playlist = result;
|
$scope.playlist = result;
|
||||||
});
|
});
|
||||||
|
|
||||||
backendSrv.get('/api/playlists/' + playlistId + '/playlistitems')
|
backendSrv.get('/api/playlists/' + playlistId + '/playlistitems')
|
||||||
.then(function(result) {
|
.then(function(result) {
|
||||||
$scope.playlistItems = result;
|
$scope.playlistItems = result;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$scope.search();
|
||||||
|
};
|
||||||
|
|
||||||
$scope.search = function() {
|
$scope.search = function() {
|
||||||
var query = {starred: true, limit: 10};
|
var query = {starred: true, limit: 10};
|
||||||
@ -136,6 +139,6 @@ function (angular, config, _) {
|
|||||||
$scope.moveDashboard(playlistItem, 1);
|
$scope.moveDashboard(playlistItem, 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.search();
|
$scope.init();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -0,0 +1,86 @@
|
|||||||
|
import '../playlist_edit_ctrl';
|
||||||
|
import {describe, beforeEach, it, sinon, expect, angularMocks} from 'test/lib/common';
|
||||||
|
import helpers from 'test/specs/helpers';
|
||||||
|
|
||||||
|
describe('PlaylistEditCtrl', function() {
|
||||||
|
var ctx = new helpers.ControllerTestContext();
|
||||||
|
|
||||||
|
var dashboards = [
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
title: 'dashboard: 2'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 3,
|
||||||
|
title: 'dashboard: 3'
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
var playlistSrv = {};
|
||||||
|
var backendSrv = {
|
||||||
|
search: (query) => {
|
||||||
|
return ctx.$q.when(dashboards);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
beforeEach(angularMocks.module('grafana.core'));
|
||||||
|
beforeEach(angularMocks.module('grafana.controllers'));
|
||||||
|
beforeEach(angularMocks.module('grafana.services'));
|
||||||
|
beforeEach(ctx.providePhase({
|
||||||
|
playlistSrv: playlistSrv,
|
||||||
|
backendSrv: backendSrv,
|
||||||
|
$route: { current: { params: { } } },
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(ctx.createControllerPhase('PlaylistEditCtrl'));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
ctx.scope.$digest();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe.only('searchresult returns 2 dashboards', function() {
|
||||||
|
it('found dashboard should be 2', function() {
|
||||||
|
expect(ctx.scope.foundPlaylistItems.length).to.be(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('filtred dashboard should be 2', function() {
|
||||||
|
expect(ctx.scope.filteredPlaylistItems.length).to.be(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('adds one dashboard to playlist', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
ctx.scope.addPlaylistItem({ id: 2, title: 'dashboard: 2' });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('playlistitems should be increased by one', () => {
|
||||||
|
expect(ctx.scope.playlistItems.length).to.be(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('filtred playlistitems should be reduced by one', () => {
|
||||||
|
expect(ctx.scope.filteredPlaylistItems.length).to.be(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('found dashboard should be 2', function() {
|
||||||
|
expect(ctx.scope.foundPlaylistItems.length).to.be(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('removes one dashboard from playlist', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
ctx.scope.removePlaylistItem(ctx.scope.playlistItems[0]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('playlistitems should be increased by one', () => {
|
||||||
|
expect(ctx.scope.playlistItems.length).to.be(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('found dashboard should be 2', function() {
|
||||||
|
expect(ctx.scope.foundPlaylistItems.length).to.be(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('filtred playlist should be reduced by one', () => {
|
||||||
|
expect(ctx.scope.filteredPlaylistItems.length).to.be(2);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user