2017-12-20 12:33:33 +01:00
|
|
|
import { ManageDashboardsCtrl } from 'app/core/components/manage_dashboards/manage_dashboards';
|
|
|
|
|
import { SearchSrv } from 'app/core/services/search_srv';
|
|
|
|
|
import q from 'q';
|
2017-10-24 19:24:13 +02:00
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
describe('ManageDashboards', () => {
|
2017-10-29 22:08:26 +01:00
|
|
|
let ctrl;
|
2017-10-24 19:24:13 +02:00
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
describe('when browsing dashboards', () => {
|
2017-10-24 19:24:13 +02:00
|
|
|
beforeEach(() => {
|
|
|
|
|
const response = [
|
|
|
|
|
{
|
|
|
|
|
id: 410,
|
2017-12-20 12:33:33 +01:00
|
|
|
title: 'afolder',
|
|
|
|
|
type: 'dash-folder',
|
2017-11-20 18:15:59 +01:00
|
|
|
items: [
|
|
|
|
|
{
|
|
|
|
|
id: 399,
|
2017-12-20 12:33:33 +01:00
|
|
|
title: 'Dashboard Test',
|
|
|
|
|
url: 'dashboard/db/dashboard-test',
|
|
|
|
|
icon: 'fa fa-folder',
|
2017-11-20 18:15:59 +01:00
|
|
|
tags: [],
|
|
|
|
|
isStarred: false,
|
2017-12-20 12:33:33 +01:00
|
|
|
},
|
2017-11-20 18:15:59 +01:00
|
|
|
],
|
2017-10-24 19:24:13 +02:00
|
|
|
tags: [],
|
2017-12-20 12:33:33 +01:00
|
|
|
isStarred: false,
|
2017-10-24 19:24:13 +02:00
|
|
|
},
|
|
|
|
|
{
|
2017-11-20 18:15:59 +01:00
|
|
|
id: 0,
|
2018-02-02 10:33:31 +01:00
|
|
|
title: 'General',
|
2017-12-20 12:33:33 +01:00
|
|
|
icon: 'fa fa-folder-open',
|
|
|
|
|
uri: 'db/something-else',
|
|
|
|
|
type: 'dash-db',
|
2017-11-20 18:15:59 +01:00
|
|
|
items: [
|
|
|
|
|
{
|
|
|
|
|
id: 500,
|
2017-12-20 12:33:33 +01:00
|
|
|
title: 'Dashboard Test',
|
|
|
|
|
url: 'dashboard/db/dashboard-test',
|
|
|
|
|
icon: 'fa fa-folder',
|
2017-11-20 18:15:59 +01:00
|
|
|
tags: [],
|
2017-12-20 12:33:33 +01:00
|
|
|
isStarred: false,
|
|
|
|
|
},
|
2017-11-20 18:15:59 +01:00
|
|
|
],
|
2017-10-24 19:24:13 +02:00
|
|
|
tags: [],
|
2017-12-20 12:33:33 +01:00
|
|
|
isStarred: false,
|
|
|
|
|
},
|
2017-10-24 19:24:13 +02:00
|
|
|
];
|
2017-11-20 18:15:59 +01:00
|
|
|
ctrl = createCtrlWithStubs(response);
|
2018-01-09 14:29:30 +01:00
|
|
|
return ctrl.refreshList();
|
2017-10-24 19:24:13 +02:00
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should set checked to false on all sections and children', () => {
|
2017-11-20 18:15:59 +01:00
|
|
|
expect(ctrl.sections.length).toEqual(2);
|
|
|
|
|
expect(ctrl.sections[0].checked).toEqual(false);
|
2017-11-21 14:47:19 +01:00
|
|
|
expect(ctrl.sections[0].items[0].checked).toEqual(false);
|
|
|
|
|
expect(ctrl.sections[1].checked).toEqual(false);
|
|
|
|
|
expect(ctrl.sections[1].items[0].checked).toEqual(false);
|
2017-12-14 11:25:16 +01:00
|
|
|
expect(ctrl.sections[0].hideHeader).toBeFalsy();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
describe('when browsing dashboards for a folder', () => {
|
2017-12-14 11:25:16 +01:00
|
|
|
beforeEach(() => {
|
|
|
|
|
const response = [
|
|
|
|
|
{
|
|
|
|
|
id: 410,
|
2017-12-20 12:33:33 +01:00
|
|
|
title: 'afolder',
|
|
|
|
|
type: 'dash-folder',
|
2017-12-14 11:25:16 +01:00
|
|
|
items: [
|
|
|
|
|
{
|
|
|
|
|
id: 399,
|
2017-12-20 12:33:33 +01:00
|
|
|
title: 'Dashboard Test',
|
|
|
|
|
url: 'dashboard/db/dashboard-test',
|
|
|
|
|
icon: 'fa fa-folder',
|
2017-12-14 11:25:16 +01:00
|
|
|
tags: [],
|
|
|
|
|
isStarred: false,
|
2017-12-20 12:33:33 +01:00
|
|
|
},
|
2017-12-14 11:25:16 +01:00
|
|
|
],
|
|
|
|
|
tags: [],
|
2017-12-20 12:33:33 +01:00
|
|
|
isStarred: false,
|
|
|
|
|
},
|
2017-12-14 11:25:16 +01:00
|
|
|
];
|
|
|
|
|
ctrl = createCtrlWithStubs(response);
|
|
|
|
|
ctrl.folderId = 410;
|
2018-01-09 14:29:30 +01:00
|
|
|
return ctrl.refreshList();
|
2017-12-14 11:25:16 +01:00
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should set hide header to true on section', () => {
|
2017-12-14 11:25:16 +01:00
|
|
|
expect(ctrl.sections[0].hideHeader).toBeTruthy();
|
2017-11-21 14:47:19 +01:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
describe('when searching dashboards', () => {
|
2017-11-21 14:47:19 +01:00
|
|
|
beforeEach(() => {
|
|
|
|
|
const response = [
|
|
|
|
|
{
|
2017-11-23 18:31:02 +01:00
|
|
|
checked: false,
|
|
|
|
|
expanded: true,
|
|
|
|
|
hideHeader: true,
|
2017-11-21 14:47:19 +01:00
|
|
|
items: [
|
|
|
|
|
{
|
|
|
|
|
id: 399,
|
2017-12-20 12:33:33 +01:00
|
|
|
title: 'Dashboard Test',
|
|
|
|
|
url: 'dashboard/db/dashboard-test',
|
|
|
|
|
icon: 'fa fa-folder',
|
2017-11-21 14:47:19 +01:00
|
|
|
tags: [],
|
|
|
|
|
isStarred: false,
|
|
|
|
|
folderId: 410,
|
2018-02-05 13:23:24 +01:00
|
|
|
folderUid: 'uid',
|
|
|
|
|
folderTitle: 'Folder',
|
|
|
|
|
folderUrl: '/dashboards/f/uid/folder',
|
2017-11-23 18:31:02 +01:00
|
|
|
},
|
2017-11-21 14:47:19 +01:00
|
|
|
{
|
|
|
|
|
id: 500,
|
2017-12-20 12:33:33 +01:00
|
|
|
title: 'Dashboard Test',
|
|
|
|
|
url: 'dashboard/db/dashboard-test',
|
|
|
|
|
icon: 'fa fa-folder',
|
2017-11-21 14:47:19 +01:00
|
|
|
tags: [],
|
2017-11-23 18:31:02 +01:00
|
|
|
folderId: 499,
|
2017-12-20 12:33:33 +01:00
|
|
|
isStarred: false,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
2017-11-21 14:47:19 +01:00
|
|
|
];
|
2017-11-23 18:31:02 +01:00
|
|
|
|
2017-11-24 16:18:56 +01:00
|
|
|
ctrl = createCtrlWithStubs(response);
|
2017-11-21 14:47:19 +01:00
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
describe('with query filter', () => {
|
2017-11-22 18:44:18 +01:00
|
|
|
beforeEach(() => {
|
2017-12-20 12:33:33 +01:00
|
|
|
ctrl.query.query = 'd';
|
2017-11-23 14:59:52 +01:00
|
|
|
ctrl.canMove = true;
|
|
|
|
|
ctrl.canDelete = true;
|
2017-11-23 18:31:02 +01:00
|
|
|
ctrl.selectAllChecked = true;
|
2018-01-09 14:29:30 +01:00
|
|
|
return ctrl.refreshList();
|
2017-11-22 18:44:18 +01:00
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should set checked to false on all sections and children', () => {
|
2017-11-23 18:31:02 +01:00
|
|
|
expect(ctrl.sections.length).toEqual(1);
|
2017-11-22 18:44:18 +01:00
|
|
|
expect(ctrl.sections[0].checked).toEqual(false);
|
|
|
|
|
expect(ctrl.sections[0].items[0].checked).toEqual(false);
|
2017-11-23 18:31:02 +01:00
|
|
|
expect(ctrl.sections[0].items[1].checked).toEqual(false);
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should uncheck select all', () => {
|
2017-11-23 18:31:02 +01:00
|
|
|
expect(ctrl.selectAllChecked).toBeFalsy();
|
2017-11-22 18:44:18 +01:00
|
|
|
});
|
2017-11-23 14:59:52 +01:00
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should disable Move To button', () => {
|
2017-11-23 14:59:52 +01:00
|
|
|
expect(ctrl.canMove).toBeFalsy();
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should disable delete button', () => {
|
2017-11-23 14:59:52 +01:00
|
|
|
expect(ctrl.canDelete).toBeFalsy();
|
|
|
|
|
});
|
2017-11-23 18:31:02 +01:00
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should have active filters', () => {
|
2017-11-27 11:32:03 +01:00
|
|
|
expect(ctrl.hasFilters).toBeTruthy();
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
describe('when select all is checked', () => {
|
2017-11-23 18:31:02 +01:00
|
|
|
beforeEach(() => {
|
|
|
|
|
ctrl.selectAllChecked = true;
|
|
|
|
|
ctrl.onSelectAllChanged();
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should select all dashboards', () => {
|
2017-11-23 18:31:02 +01:00
|
|
|
expect(ctrl.sections[0].checked).toBeFalsy();
|
|
|
|
|
expect(ctrl.sections[0].items[0].checked).toBeTruthy();
|
|
|
|
|
expect(ctrl.sections[0].items[1].checked).toBeTruthy();
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should enable Move To button', () => {
|
2017-11-23 18:31:02 +01:00
|
|
|
expect(ctrl.canMove).toBeTruthy();
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should enable delete button', () => {
|
2017-11-23 18:31:02 +01:00
|
|
|
expect(ctrl.canDelete).toBeTruthy();
|
|
|
|
|
});
|
2017-11-27 11:32:03 +01:00
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
describe('when clearing filters', () => {
|
2017-11-27 11:32:03 +01:00
|
|
|
beforeEach(() => {
|
|
|
|
|
return ctrl.clearFilters();
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should reset query filter', () => {
|
|
|
|
|
expect(ctrl.query.query).toEqual('');
|
2017-11-27 11:32:03 +01:00
|
|
|
});
|
|
|
|
|
});
|
2017-11-23 18:31:02 +01:00
|
|
|
});
|
2017-11-22 18:44:18 +01:00
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
describe('with tag filter', () => {
|
2017-11-22 18:44:18 +01:00
|
|
|
beforeEach(() => {
|
2017-12-20 12:33:33 +01:00
|
|
|
return ctrl.filterByTag('test');
|
2017-11-22 18:44:18 +01:00
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should set tag filter', () => {
|
2017-11-23 18:31:02 +01:00
|
|
|
expect(ctrl.sections.length).toEqual(1);
|
2017-12-20 12:33:33 +01:00
|
|
|
expect(ctrl.query.tag[0]).toEqual('test');
|
2017-11-22 18:44:18 +01:00
|
|
|
});
|
2017-11-27 11:32:03 +01:00
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should have active filters', () => {
|
2017-11-27 11:32:03 +01:00
|
|
|
expect(ctrl.hasFilters).toBeTruthy();
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
describe('when clearing filters', () => {
|
2017-11-27 11:32:03 +01:00
|
|
|
beforeEach(() => {
|
|
|
|
|
return ctrl.clearFilters();
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should reset tag filter', () => {
|
2017-11-27 11:32:03 +01:00
|
|
|
expect(ctrl.query.tag.length).toEqual(0);
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-11-22 18:44:18 +01:00
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
describe('with starred filter', () => {
|
2017-11-22 18:44:18 +01:00
|
|
|
beforeEach(() => {
|
|
|
|
|
const yesOption: any = ctrl.starredFilterOptions[1];
|
|
|
|
|
|
|
|
|
|
ctrl.selectedStarredFilter = yesOption;
|
|
|
|
|
return ctrl.onStarredFilterChange();
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should set starred filter', () => {
|
2017-11-23 18:31:02 +01:00
|
|
|
expect(ctrl.sections.length).toEqual(1);
|
2017-11-22 18:44:18 +01:00
|
|
|
expect(ctrl.query.starred).toEqual(true);
|
|
|
|
|
});
|
2017-11-27 11:32:03 +01:00
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should have active filters', () => {
|
2017-11-27 11:32:03 +01:00
|
|
|
expect(ctrl.hasFilters).toBeTruthy();
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
describe('when clearing filters', () => {
|
2017-11-27 11:32:03 +01:00
|
|
|
beforeEach(() => {
|
|
|
|
|
return ctrl.clearFilters();
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should reset starred filter', () => {
|
2017-11-27 11:32:03 +01:00
|
|
|
expect(ctrl.query.starred).toEqual(false);
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-10-24 19:24:13 +02:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
describe('when selecting dashboards', () => {
|
2017-10-24 19:24:13 +02:00
|
|
|
let ctrl;
|
|
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2017-11-20 18:15:59 +01:00
|
|
|
ctrl = createCtrlWithStubs([]);
|
2017-10-24 19:24:13 +02:00
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
describe('and no dashboards are selected', () => {
|
2017-10-24 19:24:13 +02:00
|
|
|
beforeEach(() => {
|
2017-11-20 18:15:59 +01:00
|
|
|
ctrl.sections = [
|
|
|
|
|
{
|
|
|
|
|
id: 1,
|
2017-12-19 16:06:54 +01:00
|
|
|
items: [{ id: 2, checked: false }],
|
2017-12-20 12:33:33 +01:00
|
|
|
checked: false,
|
2017-11-20 18:15:59 +01:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 0,
|
2017-12-19 16:06:54 +01:00
|
|
|
items: [{ id: 3, checked: false }],
|
2017-12-20 12:33:33 +01:00
|
|
|
checked: false,
|
|
|
|
|
},
|
2017-10-24 19:24:13 +02:00
|
|
|
];
|
|
|
|
|
ctrl.selectionChanged();
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should disable Move To button', () => {
|
2017-10-24 19:24:13 +02:00
|
|
|
expect(ctrl.canMove).toBeFalsy();
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should disable delete button', () => {
|
2017-10-24 19:24:13 +02:00
|
|
|
expect(ctrl.canDelete).toBeFalsy();
|
|
|
|
|
});
|
2017-11-23 18:31:02 +01:00
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
describe('when select all is checked', () => {
|
2017-11-23 18:31:02 +01:00
|
|
|
beforeEach(() => {
|
|
|
|
|
ctrl.selectAllChecked = true;
|
|
|
|
|
ctrl.onSelectAllChanged();
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should select all folders and dashboards', () => {
|
2017-11-23 18:31:02 +01:00
|
|
|
expect(ctrl.sections[0].checked).toBeTruthy();
|
|
|
|
|
expect(ctrl.sections[0].items[0].checked).toBeTruthy();
|
|
|
|
|
expect(ctrl.sections[1].checked).toBeTruthy();
|
|
|
|
|
expect(ctrl.sections[1].items[0].checked).toBeTruthy();
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should enable Move To button', () => {
|
2017-12-14 11:25:16 +01:00
|
|
|
expect(ctrl.canMove).toBeTruthy();
|
2017-11-23 18:31:02 +01:00
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should enable delete button', () => {
|
2017-11-23 18:31:02 +01:00
|
|
|
expect(ctrl.canDelete).toBeTruthy();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
describe('and all folders and dashboards are selected', () => {
|
2017-11-23 18:31:02 +01:00
|
|
|
beforeEach(() => {
|
|
|
|
|
ctrl.sections = [
|
|
|
|
|
{
|
|
|
|
|
id: 1,
|
2017-12-19 16:06:54 +01:00
|
|
|
items: [{ id: 2, checked: true }],
|
2017-12-20 12:33:33 +01:00
|
|
|
checked: true,
|
2017-11-23 18:31:02 +01:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 0,
|
2017-12-19 16:06:54 +01:00
|
|
|
items: [{ id: 3, checked: true }],
|
2017-12-20 12:33:33 +01:00
|
|
|
checked: true,
|
|
|
|
|
},
|
2017-11-23 18:31:02 +01:00
|
|
|
];
|
|
|
|
|
ctrl.selectionChanged();
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should enable Move To button', () => {
|
2017-12-14 11:25:16 +01:00
|
|
|
expect(ctrl.canMove).toBeTruthy();
|
2017-11-23 18:31:02 +01:00
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should enable delete button', () => {
|
2017-11-23 18:31:02 +01:00
|
|
|
expect(ctrl.canDelete).toBeTruthy();
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
describe('when select all is unchecked', () => {
|
2017-11-23 18:31:02 +01:00
|
|
|
beforeEach(() => {
|
|
|
|
|
ctrl.selectAllChecked = false;
|
|
|
|
|
ctrl.onSelectAllChanged();
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should uncheck all checked folders and dashboards', () => {
|
2017-11-23 18:31:02 +01:00
|
|
|
expect(ctrl.sections[0].checked).toBeFalsy();
|
|
|
|
|
expect(ctrl.sections[0].items[0].checked).toBeFalsy();
|
|
|
|
|
expect(ctrl.sections[1].checked).toBeFalsy();
|
|
|
|
|
expect(ctrl.sections[1].items[0].checked).toBeFalsy();
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should disable Move To button', () => {
|
2017-11-23 18:31:02 +01:00
|
|
|
expect(ctrl.canMove).toBeFalsy();
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should disable delete button', () => {
|
2017-11-23 18:31:02 +01:00
|
|
|
expect(ctrl.canDelete).toBeFalsy();
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-10-24 19:24:13 +02:00
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
describe('and one dashboard in root is selected', () => {
|
2017-10-24 19:24:13 +02:00
|
|
|
beforeEach(() => {
|
2017-11-20 18:15:59 +01:00
|
|
|
ctrl.sections = [
|
|
|
|
|
{
|
|
|
|
|
id: 1,
|
2017-12-20 12:33:33 +01:00
|
|
|
title: 'folder',
|
2017-12-19 16:06:54 +01:00
|
|
|
items: [{ id: 2, checked: false }],
|
2017-12-20 12:33:33 +01:00
|
|
|
checked: false,
|
2017-11-20 18:15:59 +01:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 0,
|
2018-02-02 10:33:31 +01:00
|
|
|
title: 'General',
|
2017-12-19 16:06:54 +01:00
|
|
|
items: [{ id: 3, checked: true }],
|
2017-12-20 12:33:33 +01:00
|
|
|
checked: false,
|
|
|
|
|
},
|
2017-10-24 19:24:13 +02:00
|
|
|
];
|
|
|
|
|
ctrl.selectionChanged();
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should enable Move To button', () => {
|
2017-10-24 19:24:13 +02:00
|
|
|
expect(ctrl.canMove).toBeTruthy();
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should enable delete button', () => {
|
2017-10-24 19:24:13 +02:00
|
|
|
expect(ctrl.canDelete).toBeTruthy();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
describe('and one child dashboard is selected', () => {
|
2017-10-24 19:24:13 +02:00
|
|
|
beforeEach(() => {
|
2017-11-20 18:15:59 +01:00
|
|
|
ctrl.sections = [
|
|
|
|
|
{
|
|
|
|
|
id: 1,
|
2017-12-20 12:33:33 +01:00
|
|
|
title: 'folder',
|
2017-12-19 16:06:54 +01:00
|
|
|
items: [{ id: 2, checked: true }],
|
2017-12-20 12:33:33 +01:00
|
|
|
checked: false,
|
2017-11-20 18:15:59 +01:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 0,
|
2018-02-02 10:33:31 +01:00
|
|
|
title: 'General',
|
2017-12-19 16:06:54 +01:00
|
|
|
items: [{ id: 3, checked: false }],
|
2017-12-20 12:33:33 +01:00
|
|
|
checked: false,
|
|
|
|
|
},
|
2017-10-24 19:24:13 +02:00
|
|
|
];
|
2017-11-20 18:15:59 +01:00
|
|
|
|
2017-10-24 19:24:13 +02:00
|
|
|
ctrl.selectionChanged();
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should enable Move To button', () => {
|
2017-10-24 19:24:13 +02:00
|
|
|
expect(ctrl.canMove).toBeTruthy();
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should enable delete button', () => {
|
2017-10-24 19:24:13 +02:00
|
|
|
expect(ctrl.canDelete).toBeTruthy();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
describe('and one child dashboard and one dashboard is selected', () => {
|
2017-10-24 19:24:13 +02:00
|
|
|
beforeEach(() => {
|
2017-11-20 18:15:59 +01:00
|
|
|
ctrl.sections = [
|
|
|
|
|
{
|
|
|
|
|
id: 1,
|
2017-12-20 12:33:33 +01:00
|
|
|
title: 'folder',
|
2017-12-19 16:06:54 +01:00
|
|
|
items: [{ id: 2, checked: true }],
|
2017-12-20 12:33:33 +01:00
|
|
|
checked: false,
|
2017-11-20 18:15:59 +01:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 0,
|
2018-02-02 10:33:31 +01:00
|
|
|
title: 'General',
|
2017-12-19 16:06:54 +01:00
|
|
|
items: [{ id: 3, checked: true }],
|
2017-12-20 12:33:33 +01:00
|
|
|
checked: false,
|
|
|
|
|
},
|
2017-10-24 19:24:13 +02:00
|
|
|
];
|
2017-11-20 18:15:59 +01:00
|
|
|
|
2017-10-24 19:24:13 +02:00
|
|
|
ctrl.selectionChanged();
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should enable Move To button', () => {
|
2017-10-24 19:24:13 +02:00
|
|
|
expect(ctrl.canMove).toBeTruthy();
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should enable delete button', () => {
|
2017-10-24 19:24:13 +02:00
|
|
|
expect(ctrl.canDelete).toBeTruthy();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
describe('and one child dashboard and one folder is selected', () => {
|
2017-10-24 19:24:13 +02:00
|
|
|
beforeEach(() => {
|
2017-11-20 18:15:59 +01:00
|
|
|
ctrl.sections = [
|
|
|
|
|
{
|
|
|
|
|
id: 1,
|
2017-12-20 12:33:33 +01:00
|
|
|
title: 'folder',
|
2017-12-19 16:06:54 +01:00
|
|
|
items: [{ id: 2, checked: false }],
|
2017-12-20 12:33:33 +01:00
|
|
|
checked: true,
|
2017-11-20 18:15:59 +01:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 3,
|
2017-12-20 12:33:33 +01:00
|
|
|
title: 'folder',
|
2017-12-19 16:06:54 +01:00
|
|
|
items: [{ id: 4, checked: true }],
|
2017-12-20 12:33:33 +01:00
|
|
|
checked: false,
|
2017-11-20 18:15:59 +01:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 0,
|
2018-02-02 10:33:31 +01:00
|
|
|
title: 'General',
|
2017-12-19 16:06:54 +01:00
|
|
|
items: [{ id: 3, checked: false }],
|
2017-12-20 12:33:33 +01:00
|
|
|
checked: false,
|
|
|
|
|
},
|
2017-10-24 19:24:13 +02:00
|
|
|
];
|
2017-11-20 18:15:59 +01:00
|
|
|
|
2017-10-24 19:24:13 +02:00
|
|
|
ctrl.selectionChanged();
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should enable Move To button', () => {
|
2017-12-14 11:25:16 +01:00
|
|
|
expect(ctrl.canMove).toBeTruthy();
|
2017-10-24 19:24:13 +02:00
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should enable delete button', () => {
|
2017-10-24 19:24:13 +02:00
|
|
|
expect(ctrl.canDelete).toBeTruthy();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-10-29 22:08:26 +01:00
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
describe('when deleting dashboards', () => {
|
2017-12-14 15:07:31 +01:00
|
|
|
let toBeDeleted: any;
|
2017-12-14 11:25:16 +01:00
|
|
|
|
2017-10-29 22:08:26 +01:00
|
|
|
beforeEach(() => {
|
2017-11-20 18:15:59 +01:00
|
|
|
ctrl = createCtrlWithStubs([]);
|
|
|
|
|
|
|
|
|
|
ctrl.sections = [
|
|
|
|
|
{
|
|
|
|
|
id: 1,
|
2018-01-31 17:15:00 +01:00
|
|
|
uid: 'folder',
|
2017-12-20 12:33:33 +01:00
|
|
|
title: 'folder',
|
2018-01-31 17:15:00 +01:00
|
|
|
items: [{ id: 2, checked: true, uid: 'folder-dash' }],
|
2017-11-20 18:15:59 +01:00
|
|
|
checked: true,
|
2017-12-14 11:25:16 +01:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 3,
|
2017-12-20 12:33:33 +01:00
|
|
|
title: 'folder-2',
|
2018-01-31 17:15:00 +01:00
|
|
|
items: [{ id: 3, checked: true, uid: 'folder-2-dash' }],
|
2017-12-14 11:25:16 +01:00
|
|
|
checked: false,
|
2018-01-31 17:15:00 +01:00
|
|
|
uid: 'folder-2',
|
2017-11-20 18:15:59 +01:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 0,
|
2018-02-02 10:33:31 +01:00
|
|
|
title: 'General',
|
2018-01-31 17:15:00 +01:00
|
|
|
items: [{ id: 3, checked: true, uid: 'root-dash' }],
|
2017-12-20 12:33:33 +01:00
|
|
|
checked: true,
|
|
|
|
|
},
|
2017-10-29 22:08:26 +01:00
|
|
|
];
|
2017-12-14 11:25:16 +01:00
|
|
|
|
2017-12-14 15:07:31 +01:00
|
|
|
toBeDeleted = ctrl.getFoldersAndDashboardsToDelete();
|
2017-12-14 11:25:16 +01:00
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should return 1 folder', () => {
|
2017-12-14 15:07:31 +01:00
|
|
|
expect(toBeDeleted.folders.length).toEqual(1);
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should return 2 dashboards', () => {
|
2017-12-14 15:07:31 +01:00
|
|
|
expect(toBeDeleted.dashboards.length).toEqual(2);
|
2017-10-29 22:08:26 +01:00
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should filter out children if parent is checked', () => {
|
|
|
|
|
expect(toBeDeleted.folders[0]).toEqual('folder');
|
2017-12-14 11:25:16 +01:00
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should not filter out children if parent not is checked', () => {
|
|
|
|
|
expect(toBeDeleted.dashboards[0]).toEqual('folder-2-dash');
|
2017-12-14 11:25:16 +01:00
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should not filter out children if parent is checked and root', () => {
|
|
|
|
|
expect(toBeDeleted.dashboards[1]).toEqual('root-dash');
|
2017-11-20 18:15:59 +01:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
describe('when moving dashboards', () => {
|
2017-11-20 18:15:59 +01:00
|
|
|
beforeEach(() => {
|
|
|
|
|
ctrl = createCtrlWithStubs([]);
|
|
|
|
|
|
|
|
|
|
ctrl.sections = [
|
|
|
|
|
{
|
|
|
|
|
id: 1,
|
2017-12-20 12:33:33 +01:00
|
|
|
title: 'folder',
|
2018-01-31 17:15:00 +01:00
|
|
|
items: [{ id: 2, checked: true, uid: 'dash' }],
|
2017-11-20 18:15:59 +01:00
|
|
|
checked: false,
|
2018-01-31 17:15:00 +01:00
|
|
|
uid: 'folder',
|
2017-11-20 18:15:59 +01:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 0,
|
2018-02-02 10:33:31 +01:00
|
|
|
title: 'General',
|
2018-01-31 17:15:00 +01:00
|
|
|
items: [{ id: 3, checked: true, uid: 'dash-2' }],
|
2017-12-20 12:33:33 +01:00
|
|
|
checked: false,
|
|
|
|
|
},
|
2017-11-20 18:15:59 +01:00
|
|
|
];
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should get selected dashboards', () => {
|
2017-11-20 18:15:59 +01:00
|
|
|
const toBeMove = ctrl.getDashboardsToMove();
|
|
|
|
|
expect(toBeMove.length).toEqual(2);
|
2017-12-20 12:33:33 +01:00
|
|
|
expect(toBeMove[0]).toEqual('dash');
|
|
|
|
|
expect(toBeMove[1]).toEqual('dash-2');
|
2017-10-29 22:08:26 +01:00
|
|
|
});
|
|
|
|
|
});
|
2017-10-24 19:24:13 +02:00
|
|
|
});
|
2017-11-20 18:15:59 +01:00
|
|
|
|
2017-11-24 16:18:56 +01:00
|
|
|
function createCtrlWithStubs(searchResponse: any, tags?: any) {
|
2017-11-20 18:15:59 +01:00
|
|
|
const searchSrvStub = {
|
|
|
|
|
search: (options: any) => {
|
2017-11-22 18:44:18 +01:00
|
|
|
return q.resolve(searchResponse);
|
2017-11-20 18:15:59 +01:00
|
|
|
},
|
|
|
|
|
getDashboardTags: () => {
|
2017-11-22 18:44:18 +01:00
|
|
|
return q.resolve(tags || []);
|
2017-12-20 12:33:33 +01:00
|
|
|
},
|
2017-11-20 18:15:59 +01:00
|
|
|
};
|
|
|
|
|
|
2018-09-03 11:30:44 +02:00
|
|
|
return new ManageDashboardsCtrl({}, { getNav: () => {} }, searchSrvStub as SearchSrv, { isEditor: true });
|
2017-11-20 18:15:59 +01:00
|
|
|
}
|