mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
tests(playlist): refactor playlist edit ctrl
This commit is contained in:
@@ -1,84 +1,68 @@
|
|||||||
import '../playlist_edit_ctrl';
|
import '../playlist_edit_ctrl';
|
||||||
import {describe, beforeEach, it, expect, angularMocks} from 'test/lib/common';
|
import {describe, beforeEach, it, expect, angularMocks} from 'test/lib/common';
|
||||||
import helpers from 'test/specs/helpers';
|
import helpers from 'test/specs/helpers';
|
||||||
|
import {PlaylistEditCtrl} from '../playlist_edit_ctrl';
|
||||||
|
|
||||||
describe('PlaylistEditCtrl', function() {
|
describe.only('PlaylistEditCtrl', function() {
|
||||||
var ctx = new helpers.ControllerTestContext();
|
var ctx: any;
|
||||||
|
beforeEach(() => {
|
||||||
|
ctx = new PlaylistEditCtrl(null, null, null, null, { current: { params: {} } });
|
||||||
|
|
||||||
var searchResult = [
|
ctx.dashboardresult = [
|
||||||
{
|
{ id: 2, title: 'dashboard: 2' },
|
||||||
id: 2,
|
{ id: 3, title: 'dashboard: 3' }
|
||||||
title: 'dashboard: 2'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 3,
|
|
||||||
title: 'dashboard: 3'
|
|
||||||
}
|
|
||||||
];
|
];
|
||||||
|
|
||||||
var playlistSrv = {};
|
ctx.tagresult = [
|
||||||
var backendSrv = {
|
{ term: 'graphie', count: 1 },
|
||||||
search: (query) => {
|
{ term: 'nyc', count: 2 }
|
||||||
return ctx.$q.when(searchResult);
|
];
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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('searchresult returns 2 dashboards', function() {
|
describe('searchresult returns 2 dashboards', function() {
|
||||||
it('found dashboard should be 2', function() {
|
it('found dashboard should be 2', function() {
|
||||||
expect(ctx.scope.foundPlaylistItems.length).to.be(2);
|
expect(ctx.dashboardresult.length).to.be(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('filtred dashboard should be 2', function() {
|
it('filtred dashboard should be 2', function() {
|
||||||
expect(ctx.scope.filteredPlaylistItems.length).to.be(2);
|
ctx.filterFoundPlaylistItems();
|
||||||
|
expect(ctx.filteredDashboards.length).to.be(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('adds one dashboard to playlist', () => {
|
describe('adds one dashboard to playlist', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
ctx.scope.addPlaylistItem({ id: 2, title: 'dashboard: 2' });
|
ctx.addPlaylistItem({ id: 2, title: 'dashboard: 2' });
|
||||||
|
ctx.filterFoundPlaylistItems();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('playlistitems should be increased by one', () => {
|
it('playlistitems should be increased by one', () => {
|
||||||
expect(ctx.scope.playlistItems.length).to.be(1);
|
expect(ctx.playlistItems.length).to.be(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('filtred playlistitems should be reduced by one', () => {
|
it('filtred playlistitems should be reduced by one', () => {
|
||||||
expect(ctx.scope.filteredPlaylistItems.length).to.be(1);
|
expect(ctx.filteredDashboards.length).to.be(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('found dashboard should be 2', function() {
|
it('found dashboard should be 2', function() {
|
||||||
expect(ctx.scope.foundPlaylistItems.length).to.be(2);
|
expect(ctx.dashboardresult.length).to.be(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('removes one dashboard from playlist', () => {
|
describe('removes one dashboard from playlist', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
ctx.scope.removePlaylistItem(ctx.scope.playlistItems[0]);
|
ctx.removePlaylistItem(ctx.playlistItems[0]);
|
||||||
|
ctx.filterFoundPlaylistItems();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('playlistitems should be increased by one', () => {
|
it('playlistitems should be increased by one', () => {
|
||||||
expect(ctx.scope.playlistItems.length).to.be(0);
|
expect(ctx.playlistItems.length).to.be(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('found dashboard should be 2', function() {
|
it('found dashboard should be 2', function() {
|
||||||
expect(ctx.scope.foundPlaylistItems.length).to.be(2);
|
expect(ctx.dashboardresult.length).to.be(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('filtred playlist should be reduced by one', () => {
|
it('filtred playlist should be reduced by one', () => {
|
||||||
expect(ctx.scope.filteredPlaylistItems.length).to.be(2);
|
expect(ctx.filteredDashboards.length).to.be(2);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user