|
@@ -1,76 +1,63 @@
|
|
|
import {DashboardListCtrl} from '../dashboard_list_ctrl';
|
|
import {DashboardListCtrl} from '../dashboard_list_ctrl';
|
|
|
|
|
+import { SearchSrv } from 'app/core/services/search_srv';
|
|
|
import q from 'q';
|
|
import q from 'q';
|
|
|
|
|
|
|
|
describe('DashboardListCtrl', () => {
|
|
describe('DashboardListCtrl', () => {
|
|
|
let ctrl;
|
|
let ctrl;
|
|
|
|
|
|
|
|
- describe('when fetching dashboards', () => {
|
|
|
|
|
- describe('and dashboard has parent that is not in search result', () => {
|
|
|
|
|
- beforeEach(() => {
|
|
|
|
|
- const response = [
|
|
|
|
|
- {
|
|
|
|
|
- id: 399,
|
|
|
|
|
- title: "Dashboard Test",
|
|
|
|
|
- uri: "db/dashboard-test",
|
|
|
|
|
- type: "dash-db",
|
|
|
|
|
- tags: [],
|
|
|
|
|
- isStarred: false,
|
|
|
|
|
- folderId: 410,
|
|
|
|
|
- folderTitle: "afolder",
|
|
|
|
|
- folderSlug: "afolder"
|
|
|
|
|
- }
|
|
|
|
|
- ];
|
|
|
|
|
-
|
|
|
|
|
- ctrl = new DashboardListCtrl({search: () => q.resolve(response)}, {getNav: () => {}}, q);
|
|
|
|
|
- return ctrl.getDashboards();
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- it('should add the missing parent folder to the result', () => {
|
|
|
|
|
- expect(ctrl.dashboards.length).toEqual(2);
|
|
|
|
|
- expect(ctrl.dashboards[0].id).toEqual(410);
|
|
|
|
|
- expect(ctrl.dashboards[1].id).toEqual(399);
|
|
|
|
|
- });
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
|
|
+ describe('when browsing dashboards', () => {
|
|
|
beforeEach(() => {
|
|
beforeEach(() => {
|
|
|
const response = [
|
|
const response = [
|
|
|
{
|
|
{
|
|
|
id: 410,
|
|
id: 410,
|
|
|
title: "afolder",
|
|
title: "afolder",
|
|
|
- uri: "db/afolder",
|
|
|
|
|
type: "dash-folder",
|
|
type: "dash-folder",
|
|
|
|
|
+ items: [
|
|
|
|
|
+ {
|
|
|
|
|
+ id: 399,
|
|
|
|
|
+ title: "Dashboard Test",
|
|
|
|
|
+ url: "dashboard/db/dashboard-test",
|
|
|
|
|
+ icon: 'fa fa-folder',
|
|
|
|
|
+ tags: [],
|
|
|
|
|
+ isStarred: false,
|
|
|
|
|
+ folderId: 410,
|
|
|
|
|
+ folderTitle: "afolder",
|
|
|
|
|
+ folderSlug: "afolder"
|
|
|
|
|
+ }
|
|
|
|
|
+ ],
|
|
|
tags: [],
|
|
tags: [],
|
|
|
isStarred: false
|
|
isStarred: false
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- id: 3,
|
|
|
|
|
- title: "something else",
|
|
|
|
|
|
|
+ id: 0,
|
|
|
|
|
+ title: "Root",
|
|
|
|
|
+ icon: 'fa fa-folder-open',
|
|
|
uri: "db/something-else",
|
|
uri: "db/something-else",
|
|
|
type: "dash-db",
|
|
type: "dash-db",
|
|
|
|
|
+ items: [
|
|
|
|
|
+ {
|
|
|
|
|
+ id: 500,
|
|
|
|
|
+ title: "Dashboard Test",
|
|
|
|
|
+ url: "dashboard/db/dashboard-test",
|
|
|
|
|
+ icon: 'fa fa-folder',
|
|
|
|
|
+ tags: [],
|
|
|
|
|
+ isStarred: false
|
|
|
|
|
+ }
|
|
|
|
|
+ ],
|
|
|
tags: [],
|
|
tags: [],
|
|
|
isStarred: false,
|
|
isStarred: false,
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- id: 399,
|
|
|
|
|
- title: "Dashboard Test",
|
|
|
|
|
- uri: "db/dashboard-test",
|
|
|
|
|
- type: "dash-db",
|
|
|
|
|
- tags: [],
|
|
|
|
|
- isStarred: false,
|
|
|
|
|
- folderId: 410,
|
|
|
|
|
- folderTitle: "afolder",
|
|
|
|
|
- folderSlug: "afolder"
|
|
|
|
|
}
|
|
}
|
|
|
];
|
|
];
|
|
|
- ctrl = new DashboardListCtrl({search: () => q.resolve(response)}, {getNav: () => {}}, null);
|
|
|
|
|
|
|
+ ctrl = createCtrlWithStubs(response);
|
|
|
return ctrl.getDashboards();
|
|
return ctrl.getDashboards();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- it('should group them in folders', () => {
|
|
|
|
|
- expect(ctrl.dashboards.length).toEqual(3);
|
|
|
|
|
- expect(ctrl.dashboards[0].id).toEqual(410);
|
|
|
|
|
- expect(ctrl.dashboards[1].id).toEqual(399);
|
|
|
|
|
- expect(ctrl.dashboards[2].id).toEqual(3);
|
|
|
|
|
|
|
+ it('should set checked to false on all sections and children', () => {
|
|
|
|
|
+ expect(ctrl.sections.length).toEqual(2);
|
|
|
|
|
+ expect(ctrl.sections[0].checked).toEqual(false);
|
|
|
|
|
+ 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);
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -78,14 +65,26 @@ describe('DashboardListCtrl', () => {
|
|
|
let ctrl;
|
|
let ctrl;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
beforeEach(() => {
|
|
|
- ctrl = new DashboardListCtrl({search: () => q.resolve([])}, {getNav: () => {}}, null);
|
|
|
|
|
|
|
+ ctrl = createCtrlWithStubs([]);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
describe('and no dashboards are selected', () => {
|
|
describe('and no dashboards are selected', () => {
|
|
|
beforeEach(() => {
|
|
beforeEach(() => {
|
|
|
- ctrl.dashboards = [
|
|
|
|
|
- {id: 1, type: 'dash-folder'},
|
|
|
|
|
- {id: 2, type: 'dash-db'}
|
|
|
|
|
|
|
+ ctrl.sections = [
|
|
|
|
|
+ {
|
|
|
|
|
+ id: 1,
|
|
|
|
|
+ items: [
|
|
|
|
|
+ { id: 2, checked: false }
|
|
|
|
|
+ ],
|
|
|
|
|
+ checked: false
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ id: 0,
|
|
|
|
|
+ items: [
|
|
|
|
|
+ { id: 3, checked: false }
|
|
|
|
|
+ ],
|
|
|
|
|
+ checked: false
|
|
|
|
|
+ }
|
|
|
];
|
|
];
|
|
|
ctrl.selectionChanged();
|
|
ctrl.selectionChanged();
|
|
|
});
|
|
});
|
|
@@ -101,9 +100,23 @@ describe('DashboardListCtrl', () => {
|
|
|
|
|
|
|
|
describe('and one dashboard in root is selected', () => {
|
|
describe('and one dashboard in root is selected', () => {
|
|
|
beforeEach(() => {
|
|
beforeEach(() => {
|
|
|
- ctrl.dashboards = [
|
|
|
|
|
- {id: 1, type: 'dash-folder'},
|
|
|
|
|
- {id: 2, type: 'dash-db', checked: true}
|
|
|
|
|
|
|
+ ctrl.sections = [
|
|
|
|
|
+ {
|
|
|
|
|
+ id: 1,
|
|
|
|
|
+ title: 'folder',
|
|
|
|
|
+ items: [
|
|
|
|
|
+ { id: 2, checked: false }
|
|
|
|
|
+ ],
|
|
|
|
|
+ checked: false
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ id: 0,
|
|
|
|
|
+ title: 'Root',
|
|
|
|
|
+ items: [
|
|
|
|
|
+ { id: 3, checked: true }
|
|
|
|
|
+ ],
|
|
|
|
|
+ checked: false
|
|
|
|
|
+ }
|
|
|
];
|
|
];
|
|
|
ctrl.selectionChanged();
|
|
ctrl.selectionChanged();
|
|
|
});
|
|
});
|
|
@@ -119,10 +132,25 @@ describe('DashboardListCtrl', () => {
|
|
|
|
|
|
|
|
describe('and one child dashboard is selected', () => {
|
|
describe('and one child dashboard is selected', () => {
|
|
|
beforeEach(() => {
|
|
beforeEach(() => {
|
|
|
- ctrl.dashboards = [
|
|
|
|
|
- {id: 1, type: 'dash-folder'},
|
|
|
|
|
- {id: 2, type: 'dash-child', checked: true}
|
|
|
|
|
|
|
+ ctrl.sections = [
|
|
|
|
|
+ {
|
|
|
|
|
+ id: 1,
|
|
|
|
|
+ title: 'folder',
|
|
|
|
|
+ items: [
|
|
|
|
|
+ { id: 2, checked: true }
|
|
|
|
|
+ ],
|
|
|
|
|
+ checked: false
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ id: 0,
|
|
|
|
|
+ title: 'Root',
|
|
|
|
|
+ items: [
|
|
|
|
|
+ { id: 3, checked: false }
|
|
|
|
|
+ ],
|
|
|
|
|
+ checked: false
|
|
|
|
|
+ }
|
|
|
];
|
|
];
|
|
|
|
|
+
|
|
|
ctrl.selectionChanged();
|
|
ctrl.selectionChanged();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -137,10 +165,25 @@ describe('DashboardListCtrl', () => {
|
|
|
|
|
|
|
|
describe('and one child dashboard and one dashboard is selected', () => {
|
|
describe('and one child dashboard and one dashboard is selected', () => {
|
|
|
beforeEach(() => {
|
|
beforeEach(() => {
|
|
|
- ctrl.dashboards = [
|
|
|
|
|
- {id: 1, type: 'dash-folder'},
|
|
|
|
|
- {id: 2, type: 'dash-child', checked: true}
|
|
|
|
|
|
|
+ ctrl.sections = [
|
|
|
|
|
+ {
|
|
|
|
|
+ id: 1,
|
|
|
|
|
+ title: 'folder',
|
|
|
|
|
+ items: [
|
|
|
|
|
+ { id: 2, checked: true }
|
|
|
|
|
+ ],
|
|
|
|
|
+ checked: false
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ id: 0,
|
|
|
|
|
+ title: 'Root',
|
|
|
|
|
+ items: [
|
|
|
|
|
+ { id: 3, checked: true }
|
|
|
|
|
+ ],
|
|
|
|
|
+ checked: false
|
|
|
|
|
+ }
|
|
|
];
|
|
];
|
|
|
|
|
+
|
|
|
ctrl.selectionChanged();
|
|
ctrl.selectionChanged();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -155,10 +198,33 @@ describe('DashboardListCtrl', () => {
|
|
|
|
|
|
|
|
describe('and one child dashboard and one folder is selected', () => {
|
|
describe('and one child dashboard and one folder is selected', () => {
|
|
|
beforeEach(() => {
|
|
beforeEach(() => {
|
|
|
- ctrl.dashboards = [
|
|
|
|
|
- {id: 1, type: 'dash-folder', checked: true},
|
|
|
|
|
- {id: 2, type: 'dash-child', checked: true}
|
|
|
|
|
|
|
+ ctrl.sections = [
|
|
|
|
|
+ {
|
|
|
|
|
+ id: 1,
|
|
|
|
|
+ title: 'folder',
|
|
|
|
|
+ items: [
|
|
|
|
|
+ { id: 2, checked: false }
|
|
|
|
|
+ ],
|
|
|
|
|
+ checked: true
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ id: 3,
|
|
|
|
|
+ title: 'folder',
|
|
|
|
|
+ items: [
|
|
|
|
|
+ { id: 4, checked: true }
|
|
|
|
|
+ ],
|
|
|
|
|
+ checked: false
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ id: 0,
|
|
|
|
|
+ title: 'Root',
|
|
|
|
|
+ items: [
|
|
|
|
|
+ { id: 3, checked: false }
|
|
|
|
|
+ ],
|
|
|
|
|
+ checked: false
|
|
|
|
|
+ }
|
|
|
];
|
|
];
|
|
|
|
|
+
|
|
|
ctrl.selectionChanged();
|
|
ctrl.selectionChanged();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -174,19 +240,86 @@ describe('DashboardListCtrl', () => {
|
|
|
|
|
|
|
|
describe('when deleting dashboards', () => {
|
|
describe('when deleting dashboards', () => {
|
|
|
beforeEach(() => {
|
|
beforeEach(() => {
|
|
|
- ctrl = new DashboardListCtrl({search: () => q.resolve([])}, {getNav: () => {}}, q);
|
|
|
|
|
- ctrl.dashboards = [
|
|
|
|
|
- {id: 1, type: 'dash-folder', checked: true},
|
|
|
|
|
- {id: 2, type: 'dash-child', checked: true, folderId: 1},
|
|
|
|
|
- {id: 3, type: 'dash-db', checked: true}
|
|
|
|
|
|
|
+ ctrl = createCtrlWithStubs([]);
|
|
|
|
|
+
|
|
|
|
|
+ ctrl.sections = [
|
|
|
|
|
+ {
|
|
|
|
|
+ id: 1,
|
|
|
|
|
+ title: 'folder',
|
|
|
|
|
+ items: [
|
|
|
|
|
+ { id: 2, checked: true, uri: 'dash' }
|
|
|
|
|
+ ],
|
|
|
|
|
+ checked: true,
|
|
|
|
|
+ uri: 'folder'
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ id: 0,
|
|
|
|
|
+ title: 'Root',
|
|
|
|
|
+ items: [
|
|
|
|
|
+ { id: 3, checked: true, uri: 'dash-2' }
|
|
|
|
|
+ ],
|
|
|
|
|
+ checked: false
|
|
|
|
|
+ }
|
|
|
];
|
|
];
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should filter out children if parent is selected', () => {
|
|
it('should filter out children if parent is selected', () => {
|
|
|
const toBeDeleted = ctrl.getDashboardsToDelete();
|
|
const toBeDeleted = ctrl.getDashboardsToDelete();
|
|
|
expect(toBeDeleted.length).toEqual(2);
|
|
expect(toBeDeleted.length).toEqual(2);
|
|
|
- expect(toBeDeleted[0].id).toEqual(1);
|
|
|
|
|
- expect(toBeDeleted[1].id).toEqual(3);
|
|
|
|
|
|
|
+ expect(toBeDeleted[0]).toEqual('folder');
|
|
|
|
|
+ expect(toBeDeleted[1]).toEqual('dash-2');
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ describe('when moving dashboards', () => {
|
|
|
|
|
+ beforeEach(() => {
|
|
|
|
|
+ ctrl = createCtrlWithStubs([]);
|
|
|
|
|
+
|
|
|
|
|
+ ctrl.sections = [
|
|
|
|
|
+ {
|
|
|
|
|
+ id: 1,
|
|
|
|
|
+ title: 'folder',
|
|
|
|
|
+ items: [
|
|
|
|
|
+ { id: 2, checked: true, uri: 'dash' }
|
|
|
|
|
+ ],
|
|
|
|
|
+ checked: false,
|
|
|
|
|
+ uri: 'folder'
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ id: 0,
|
|
|
|
|
+ title: 'Root',
|
|
|
|
|
+ items: [
|
|
|
|
|
+ { id: 3, checked: true, uri: 'dash-2' }
|
|
|
|
|
+ ],
|
|
|
|
|
+ checked: false
|
|
|
|
|
+ }
|
|
|
|
|
+ ];
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ it('should get selected dashboards', () => {
|
|
|
|
|
+ const toBeMove = ctrl.getDashboardsToMove();
|
|
|
|
|
+ expect(toBeMove.length).toEqual(2);
|
|
|
|
|
+ expect(toBeMove[0]).toEqual('dash');
|
|
|
|
|
+ expect(toBeMove[1]).toEqual('dash-2');
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
+
|
|
|
|
|
+function createCtrlWithStubs(response: any) {
|
|
|
|
|
+ const searchSrvStub = {
|
|
|
|
|
+ browse: () => {
|
|
|
|
|
+ return q.resolve(response);
|
|
|
|
|
+ },
|
|
|
|
|
+ search: (options: any) => {
|
|
|
|
|
+ return q.resolve(response);
|
|
|
|
|
+ },
|
|
|
|
|
+ toggleFolder: (section) => {
|
|
|
|
|
+ return q.resolve(response);
|
|
|
|
|
+ },
|
|
|
|
|
+ getDashboardTags: () => {
|
|
|
|
|
+ return q.resolve([]);
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ return new DashboardListCtrl({}, {getNav: () => {}}, q, <SearchSrv>searchSrvStub);
|
|
|
|
|
+}
|