|
|
@@ -1,4 +1,6 @@
|
|
|
+import _ from 'lodash';
|
|
|
import {DashboardModel} from '../dashboard_model';
|
|
|
+import { expect } from 'test/lib/common';
|
|
|
|
|
|
jest.mock('app/core/services/context_srv', () => ({
|
|
|
|
|
|
@@ -146,19 +148,19 @@ describe('given dashboard with panel repeat in vertical direction', function() {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
-describe.skip('given dashboard with row repeat', function() {
|
|
|
- var dashboard;
|
|
|
+describe('given dashboard with row repeat', function() {
|
|
|
+ let dashboard, dashboardJSON;
|
|
|
|
|
|
beforeEach(function() {
|
|
|
- dashboard = new DashboardModel({
|
|
|
+ dashboardJSON = {
|
|
|
panels: [
|
|
|
- {id: 1, type: 'row', repeat: 'apps', gridPos: {x: 0, y: 0, h: 1 , w: 24}},
|
|
|
+ {id: 1, type: 'row', gridPos: {x: 0, y: 0, h: 1 , w: 24}, repeat: 'apps'},
|
|
|
{id: 2, type: 'graph', gridPos: {x: 0, y: 1, h: 1 , w: 6}},
|
|
|
{id: 3, type: 'graph', gridPos: {x: 6, y: 1, h: 1 , w: 6}},
|
|
|
{id: 4, type: 'row', gridPos: {x: 0, y: 2, h: 1 , w: 24}},
|
|
|
{id: 5, type: 'graph', gridPos: {x: 0, y: 3, h: 1 , w: 12}},
|
|
|
],
|
|
|
- templating: {
|
|
|
+ templating: {
|
|
|
list: [{
|
|
|
name: 'apps',
|
|
|
current: {
|
|
|
@@ -172,33 +174,137 @@ describe.skip('given dashboard with row repeat', function() {
|
|
|
]
|
|
|
}]
|
|
|
}
|
|
|
- });
|
|
|
+ };
|
|
|
+ dashboard = new DashboardModel(dashboardJSON);
|
|
|
dashboard.processRepeats();
|
|
|
});
|
|
|
|
|
|
it('should not repeat only row', function() {
|
|
|
- expect(dashboard.panels[1].type).toBe('graph');
|
|
|
- });
|
|
|
- //
|
|
|
- // it('should set scopedVars on panels', function() {
|
|
|
- // expect(dashboard.panels[1].scopedVars).toMatchObject({apps: {text: 'se1', value: 'se1'}})
|
|
|
- // });
|
|
|
- //
|
|
|
- // it.skip('should repeat row and panels below two times', function() {
|
|
|
- // expect(dashboard.panels).toMatchObject([
|
|
|
- // // first (original row)
|
|
|
- // {id: 1, type: 'row', repeat: 'apps', gridPos: {x: 0, y: 0, h: 1 , w: 24}},
|
|
|
- // {id: 2, type: 'graph', gridPos: {x: 0, y: 1, h: 1 , w: 6}},
|
|
|
- // {id: 3, type: 'graph', gridPos: {x: 6, y: 1, h: 1 , w: 6}},
|
|
|
- // // repeated row
|
|
|
- // {id: 1, type: 'row', repeatPanelId: 1, gridPos: {x: 0, y: 0, h: 1 , w: 24}},
|
|
|
- // {id: 2, type: 'graph', repeatPanelId: 1, gridPos: {x: 0, y: 1, h: 1 , w: 6}},
|
|
|
- // {id: 3, type: 'graph', repeatPanelId: 1, gridPos: {x: 6, y: 1, h: 1 , w: 6}},
|
|
|
- // // row below dont touch
|
|
|
- // {id: 4, type: 'row', gridPos: {x: 0, y: 2, h: 1 , w: 24}},
|
|
|
- // {id: 5, type: 'graph', gridPos: {x: 0, y: 3, h: 1 , w: 12}},
|
|
|
- // ]);
|
|
|
- // });
|
|
|
+ const panel_types = _.map(dashboard.panels, 'type');
|
|
|
+ expect(panel_types).toEqual([
|
|
|
+ 'row', 'graph', 'graph',
|
|
|
+ 'row', 'graph', 'graph',
|
|
|
+ 'row', 'graph'
|
|
|
+ ]);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should set scopedVars for each panel', function() {
|
|
|
+ dashboardJSON.templating.list[0].options[2].selected = true;
|
|
|
+ dashboard = new DashboardModel(dashboardJSON);
|
|
|
+ dashboard.processRepeats();
|
|
|
+
|
|
|
+ expect(dashboard.panels[1].scopedVars).toMatchObject({apps: {text: 'se1', value: 'se1'}});
|
|
|
+ expect(dashboard.panels[4].scopedVars).toMatchObject({apps: {text: 'se2', value: 'se2'}});
|
|
|
+
|
|
|
+ const scopedVars = _.compact(_.map(dashboard.panels, (panel) => {
|
|
|
+ return panel.scopedVars ? panel.scopedVars.apps.value : null;
|
|
|
+ }));
|
|
|
+
|
|
|
+ expect(scopedVars).toEqual([
|
|
|
+ 'se1', 'se1', 'se1',
|
|
|
+ 'se2', 'se2', 'se2',
|
|
|
+ 'se3', 'se3', 'se3',
|
|
|
+ ]);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should repeat only configured row', function() {
|
|
|
+ expect(dashboard.panels[6].id).toBe(4);
|
|
|
+ expect(dashboard.panels[7].id).toBe(5);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should repeat only row if it is collapsed', function() {
|
|
|
+ dashboardJSON.panels = [
|
|
|
+ {
|
|
|
+ id: 1, type: 'row', collapsed: true, repeat: 'apps', gridPos: {x: 0, y: 0, h: 1 , w: 24},
|
|
|
+ panels: [
|
|
|
+ {id: 2, type: 'graph', gridPos: {x: 0, y: 1, h: 1 , w: 6}},
|
|
|
+ {id: 3, type: 'graph', gridPos: {x: 6, y: 1, h: 1 , w: 6}},
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {id: 4, type: 'row', gridPos: {x: 0, y: 1, h: 1 , w: 24}},
|
|
|
+ {id: 5, type: 'graph', gridPos: {x: 0, y: 2, h: 1 , w: 12}},
|
|
|
+ ];
|
|
|
+ dashboard = new DashboardModel(dashboardJSON);
|
|
|
+ dashboard.processRepeats();
|
|
|
+
|
|
|
+ const panel_types = _.map(dashboard.panels, 'type');
|
|
|
+ expect(panel_types).toEqual([
|
|
|
+ 'row', 'row', 'row', 'graph'
|
|
|
+ ]);
|
|
|
+ expect(dashboard.panels[0].panels).toHaveLength(2);
|
|
|
+ expect(dashboard.panels[1].panels).toHaveLength(2);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should properly repeat multiple rows', function() {
|
|
|
+ dashboardJSON.panels = [
|
|
|
+ {id: 1, type: 'row', gridPos: {x: 0, y: 0, h: 1 , w: 24}, repeat: 'apps'}, // repeat
|
|
|
+ {id: 2, type: 'graph', gridPos: {x: 0, y: 1, h: 1 , w: 6}},
|
|
|
+ {id: 3, type: 'graph', gridPos: {x: 6, y: 1, h: 1 , w: 6}},
|
|
|
+ {id: 4, type: 'row', gridPos: {x: 0, y: 2, h: 1 , w: 24}}, // don't touch
|
|
|
+ {id: 5, type: 'graph', gridPos: {x: 0, y: 3, h: 1 , w: 12}},
|
|
|
+ {id: 6, type: 'row', gridPos: {x: 0, y: 4, h: 1 , w: 24}, repeat: 'hosts'}, // repeat
|
|
|
+ {id: 7, type: 'graph', gridPos: {x: 0, y: 5, h: 1 , w: 6}},
|
|
|
+ {id: 8, type: 'graph', gridPos: {x: 6, y: 5, h: 1 , w: 6}}
|
|
|
+ ];
|
|
|
+ dashboardJSON.templating.list.push({
|
|
|
+ name: 'hosts',
|
|
|
+ current: {
|
|
|
+ text: 'backend01, backend02',
|
|
|
+ value: ['backend01', 'backend02']
|
|
|
+ },
|
|
|
+ options: [
|
|
|
+ {text: 'backend01', value: 'backend01', selected: true},
|
|
|
+ {text: 'backend02', value: 'backend02', selected: true},
|
|
|
+ {text: 'backend03', value: 'backend03', selected: false}
|
|
|
+ ]
|
|
|
+ });
|
|
|
+ dashboard = new DashboardModel(dashboardJSON);
|
|
|
+ dashboard.processRepeats();
|
|
|
+
|
|
|
+ const panel_types = _.map(dashboard.panels, 'type');
|
|
|
+ expect(panel_types).toEqual([
|
|
|
+ 'row', 'graph', 'graph',
|
|
|
+ 'row', 'graph', 'graph',
|
|
|
+ 'row', 'graph',
|
|
|
+ 'row', 'graph', 'graph',
|
|
|
+ 'row', 'graph', 'graph',
|
|
|
+ ]);
|
|
|
+
|
|
|
+ expect(dashboard.panels[0].scopedVars['apps'].value).toBe('se1');
|
|
|
+ expect(dashboard.panels[1].scopedVars['apps'].value).toBe('se1');
|
|
|
+ expect(dashboard.panels[3].scopedVars['apps'].value).toBe('se2');
|
|
|
+ expect(dashboard.panels[4].scopedVars['apps'].value).toBe('se2');
|
|
|
+ expect(dashboard.panels[8].scopedVars['hosts'].value).toBe('backend01');
|
|
|
+ expect(dashboard.panels[9].scopedVars['hosts'].value).toBe('backend01');
|
|
|
+ expect(dashboard.panels[11].scopedVars['hosts'].value).toBe('backend02');
|
|
|
+ expect(dashboard.panels[12].scopedVars['hosts'].value).toBe('backend02');
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should assign unique ids for repeated panels', function() {
|
|
|
+ dashboardJSON.panels = [
|
|
|
+ {
|
|
|
+ id: 1, type: 'row', collapsed: true, repeat: 'apps', gridPos: {x: 0, y: 0, h: 1 , w: 24},
|
|
|
+ panels: [
|
|
|
+ {id: 2, type: 'graph', gridPos: {x: 0, y: 1, h: 1 , w: 6}},
|
|
|
+ {id: 3, type: 'graph', gridPos: {x: 6, y: 1, h: 1 , w: 6}},
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {id: 4, type: 'row', gridPos: {x: 0, y: 1, h: 1 , w: 24}},
|
|
|
+ {id: 5, type: 'graph', gridPos: {x: 0, y: 2, h: 1 , w: 12}},
|
|
|
+ ];
|
|
|
+ dashboard = new DashboardModel(dashboardJSON);
|
|
|
+ dashboard.processRepeats();
|
|
|
+
|
|
|
+ const panel_ids = _.flattenDeep(_.map(dashboard.panels, (panel) => {
|
|
|
+ let ids = [];
|
|
|
+ if (panel.panels && panel.panels.length) {
|
|
|
+ ids = _.map(panel.panels, 'id');
|
|
|
+ }
|
|
|
+ ids.push(panel.id);
|
|
|
+ return ids;
|
|
|
+ }));
|
|
|
+ expect(panel_ids.length).toEqual(_.uniq(panel_ids).length);
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
|