Skip to content

Commit

Permalink
Found another bug with initial state not being set correctly on a har…
Browse files Browse the repository at this point in the history
…d refresh
  • Loading branch information
stacey-gammon committed Oct 14, 2017
1 parent e7bf212 commit 3c20f1d
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ export class DashboardStateManager {
// Always start out with all panels minimized when a dashboard is first loaded.
store.dispatch(minimizePanel());
store.dispatch(updatePanels(this.getPanels()));
store.dispatch(updateViewMode(this.getViewMode()));
store.dispatch(updateIsFullScreenMode(this.getFullScreenMode()));

this.changeListeners = [];

Expand Down
36 changes: 0 additions & 36 deletions test/functional/apps/dashboard/_dashboard.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import expect from 'expect.js';

import {
DEFAULT_PANEL_WIDTH,
} from '../../../../src/core_plugins/kibana/public/dashboard/dashboard_constants';

import {
VisualizeConstants
} from '../../../../src/core_plugins/kibana/public/visualize/visualize_constants';
Expand Down Expand Up @@ -111,38 +107,6 @@ export default function ({ getService, getPageObjects }) {
});
});

describe('Directly modifying url updates dashboard state', () => {
it('for query parameter', async function () {
const currentQuery = await PageObjects.dashboard.getQuery();
expect(currentQuery).to.equal('');
const currentUrl = await remote.getCurrentUrl();
const newUrl = currentUrl.replace('query:%27%27', 'query:%27hi%27');
// Don't add the timestamp to the url or it will cause a hard refresh and we want to test a
// soft refresh.
await remote.get(newUrl.toString(), false);
const newQuery = await PageObjects.dashboard.getQuery();
expect(newQuery).to.equal('hi');
});

it('for panel size parameters', async function () {
const currentUrl = await remote.getCurrentUrl();
const currentPanelDimensions = await PageObjects.dashboard.getPanelDimensions();
const newUrl = currentUrl.replace(`w:${DEFAULT_PANEL_WIDTH}`, `w:${DEFAULT_PANEL_WIDTH * 2}`);
await remote.get(newUrl.toString(), false);
await retry.try(async () => {
const newPanelDimensions = await PageObjects.dashboard.getPanelDimensions();
if (newPanelDimensions.length < 0) {
throw new Error('No panel dimensions...');
}
// 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);
});
});
});

describe('expanding a panel', () => {
it('hides other panels', async () => {
await PageObjects.dashboard.toggleExpandPanel();
Expand Down
45 changes: 45 additions & 0 deletions test/functional/apps/dashboard/_dashboard_state.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import expect from 'expect.js';

import { PIE_CHART_VIS_NAME } from '../../page_objects/dashboard_page';
import {
DEFAULT_PANEL_WIDTH,
} from '../../../../src/core_plugins/kibana/public/dashboard/dashboard_constants';

export default function ({ getService, getPageObjects }) {
const PageObjects = getPageObjects(['dashboard', 'visualize', 'header']);
const testSubjects = getService('testSubjects');
const remote = getService('remote');
const retry = getService('retry');

describe('dashboard state', function describeIndexTests() {
before(async function () {
Expand All @@ -15,7 +22,45 @@ export default function ({ getService, getPageObjects }) {
await PageObjects.header.clickDashboard();
});

describe('Directly modifying url updates dashboard state', () => {
it('for query parameter', async function () {
await PageObjects.dashboard.gotoDashboardLandingPage();
await PageObjects.dashboard.clickNewDashboard();

const currentQuery = await PageObjects.dashboard.getQuery();
expect(currentQuery).to.equal('');
const currentUrl = await remote.getCurrentUrl();
const newUrl = currentUrl.replace('query:%27%27', 'query:%27hi%27');
// Don't add the timestamp to the url or it will cause a hard refresh and we want to test a
// soft refresh.
await remote.get(newUrl.toString(), false);
const newQuery = await PageObjects.dashboard.getQuery();
expect(newQuery).to.equal('hi');
});

it('for panel size parameters', async function () {
await PageObjects.dashboard.addVisualization(PIE_CHART_VIS_NAME);
const currentUrl = await remote.getCurrentUrl();
const currentPanelDimensions = await PageObjects.dashboard.getPanelDimensions();
const newUrl = currentUrl.replace(`w:${DEFAULT_PANEL_WIDTH}`, `w:${DEFAULT_PANEL_WIDTH * 2}`);
await remote.get(newUrl.toString(), false);
await retry.try(async () => {
const newPanelDimensions = await PageObjects.dashboard.getPanelDimensions();
if (newPanelDimensions.length < 0) {
throw new Error('No panel dimensions...');
}
// 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);
});
});
});

it('Tile map with no changes will update with visualization changes', async () => {
await PageObjects.dashboard.gotoDashboardLandingPage();

await PageObjects.dashboard.clickNewDashboard();
await PageObjects.dashboard.setTimepickerInDataRange();
await PageObjects.dashboard.addVisualizations(['Visualization TileMap']);
Expand Down
19 changes: 19 additions & 0 deletions test/functional/apps/dashboard/_panel_controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,25 @@ export default function ({ getService, getPageObjects }) {
expect(removeExists).to.equal(true);
});

// Based off an actual bug encountered in a PR where a hard refresh in edit mode did not show the edit mode
// controls.
it ('are shown in edit mode after a hard refresh', async () => {
const currentUrl = await remote.getCurrentUrl();
// the second parameter of true will include the timestamp in the url and trigger a hard refresh.
await remote.get(currentUrl.toString(), true);

await PageObjects.dashboard.showPanelEditControlsDropdownMenu();
const editLinkExists = await testSubjects.exists('dashboardPanelEditLink');
const removeExists = await testSubjects.exists('dashboardPanelRemoveIcon');

expect(editLinkExists).to.equal(true);
expect(removeExists).to.equal(true);

// Get rid of the timestamp in the url.
await remote.get(currentUrl.toString(), false);
});


describe('on an expanded panel', function () {
it('are hidden in view mode', async function () {
await PageObjects.dashboard.saveDashboard(dashboardName);
Expand Down

0 comments on commit 3c20f1d

Please sign in to comment.