Skip to content

Commit

Permalink
# This is a combination of 3 commits.
Browse files Browse the repository at this point in the history
# This is the 1st commit message:
Add margin of error to test determining panel widths

# This is the commit message #2:

use real kibana version when creating panel data. Will make future conversions easier.

# This is the commit message #3:

Fix lint errors
  • Loading branch information
stacey-gammon committed Sep 20, 2017
1 parent aafbe72 commit bee007f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { PanelUtils } from '../panel/panel_utils';
import { DashboardGrid } from './dashboard_grid';
import { DashboardPanel } from '../panel/dashboard_panel';

jest.mock('ui/chrome', () => ({ getKibanaVersion: () => '6.0.0' }), { virtual: true });

const getContainerApi = () => {
return {
addFilter: () => {},
Expand Down
2 changes: 2 additions & 0 deletions src/core_plugins/kibana/public/dashboard/panel/panel_state.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export const DEFAULT_PANEL_WIDTH = 6;
export const DEFAULT_PANEL_HEIGHT = 3;

import { DASHBOARD_GRID_COLUMN_COUNT } from '../dashboard_constants';
import chrome from 'ui/chrome';

/**
* Represents a panel on a grid. Keeps track of position in the grid and what visualization it
Expand Down Expand Up @@ -96,6 +97,7 @@ export function createPanelState(id, type, panelIndex, currentPanels) {
y,
i: panelIndex.toString()
},
version: chrome.getKibanaVersion(),
panelIndex: panelIndex,
type: type,
id: id
Expand Down
29 changes: 2 additions & 27 deletions src/core_plugins/kibana/public/dashboard/panel/panel_utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DEFAULT_PANEL_WIDTH, DEFAULT_PANEL_HEIGHT } from 'plugins/kibana/dashboard/panel/panel_state';
import chrome from 'ui/chrome';

import _ from 'lodash';

Expand Down Expand Up @@ -31,40 +32,14 @@ export class PanelUtils {
w: panel.size_x || DEFAULT_PANEL_WIDTH,
h: panel.size_y || DEFAULT_PANEL_HEIGHT,
i: panel.panelIndex.toString(),
version: 6,
version: chrome.getKibanaVersion(),
};
delete panel.size_x;
delete panel.size_y;
delete panel.row;
delete panel.col;
}

/**
* Ensures that the panel object has the latest size/pos info.
* @param {PanelState} panel
* @param {Element} panelElement - jQuery element representing the element in the UI
*/
static refreshSizeAndPosition(panel, panelElement) {
const data = panelElement.coords().grid;
panel.size_x = data.size_x;
panel.size_y = data.size_y;
panel.col = data.col;
panel.row = data.row;
}

/**
* Ensures that the grid element matches the latest size/pos info in the panel element.
* @param {PanelState} panel
* @param {Element} panelElement - jQuery element representing the element in the UI
*/
static refreshElementSizeAndPosition(panel, panelElement) {
const data = panelElement.coords().grid;
data.size_x = panel.size_x;
data.size_y = panel.size_y;
data.col = panel.col;
data.row = panel.row;
}

/**
* Returns the panel with the given panelIndex from the panels array (*NOT* the panel at the given index).
* @param panelIndex {number} - Note this is *NOT* the index of the panel in the panels array.
Expand Down
5 changes: 5 additions & 0 deletions src/ui/public/chrome/api/apps.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ export default function (chrome, internals) {
return internals.showAppsLink == null ? internals.nav.length > 1 : internals.showAppsLink;
};


chrome.getKibanaVersion = function () {
return internals.version;
};

chrome.getApp = function () {
return clone(internals.app);
};
Expand Down
6 changes: 5 additions & 1 deletion test/functional/apps/dashboard/_dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,11 @@ export default function ({ getService, getPageObjects }) {
if (newPanelDimensions.length < 0) {
throw new Error('No panel dimensions...');
}
expect(newPanelDimensions[0].width).to.equal(currentPanelDimensions[0].width * 2);
// Some margin of error is allowed, I've noticed it being off by one pixel. Probably something to do with
// an odd width and dividing by two. Note that if we add margins, we'll have to adjust this as well.
const marginOfError = 5;
expect(newPanelDimensions[0].width).to.be.lessThan(currentPanelDimensions[0].width * 2 + marginOfError);
expect(newPanelDimensions[0].width).to.be.greaterThan(currentPanelDimensions[0].width * 2 - marginOfError);
});
});
});
Expand Down

0 comments on commit bee007f

Please sign in to comment.