Skip to content

Commit

Permalink
add vega_chart_page, refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
dmlemeshko committed Jan 3, 2020
1 parent 4ab65d7 commit bd0e10b
Show file tree
Hide file tree
Showing 23 changed files with 117 additions and 96 deletions.
1 change: 0 additions & 1 deletion test/functional/apps/visualize/_area_chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export default function({ getService, getPageObjects }) {
'visEditor',
'visChart',
'header',
'settings',
'timePicker',
]);

Expand Down
9 changes: 1 addition & 8 deletions test/functional/apps/visualize/_data_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,7 @@ export default function({ getService, getPageObjects }) {
const testSubjects = getService('testSubjects');
const retry = getService('retry');
const filterBar = getService('filterBar');
const PageObjects = getPageObjects([
'common',
'visualize',
'header',
'timePicker',
'visEditor',
'visChart',
]);
const PageObjects = getPageObjects(['visualize', 'timePicker', 'visEditor', 'visChart']);

describe('data table', function indexPatternCreation() {
const vizName1 = 'Visualization DataTable';
Expand Down
2 changes: 1 addition & 1 deletion test/functional/apps/visualize/_data_table_nontimeindex.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function({ getService, getPageObjects }) {
const retry = getService('retry');
const filterBar = getService('filterBar');
const renderable = getService('renderable');
const PageObjects = getPageObjects(['common', 'visualize', 'visEditor', 'header']);
const PageObjects = getPageObjects(['visualize', 'visEditor', 'header', 'visChart']);

describe.skip('data table with index without time filter', function indexPatternCreation() {
const vizName1 = 'Visualization DataTable without time filter';
Expand Down
1 change: 0 additions & 1 deletion test/functional/apps/visualize/_embedding_chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export default function({ getService, getPageObjects }) {
const renderable = getService('renderable');
const embedding = getService('embedding');
const PageObjects = getPageObjects([
'common',
'visualize',
'visEditor',
'visChart',
Expand Down
2 changes: 1 addition & 1 deletion test/functional/apps/visualize/_experimental_vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import expect from '@kbn/expect';

export default ({ getService, getPageObjects }) => {
const log = getService('log');
const PageObjects = getPageObjects(['common', 'visualize']);
const PageObjects = getPageObjects(['visualize']);

describe('visualize app', function() {
this.tags('smoke');
Expand Down
8 changes: 1 addition & 7 deletions test/functional/apps/visualize/_gauge_chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,7 @@ export default function({ getService, getPageObjects }) {
const retry = getService('retry');
const inspector = getService('inspector');
const testSubjects = getService('testSubjects');
const PageObjects = getPageObjects([
'common',
'visualize',
'visEditor',
'visChart',
'timePicker',
]);
const PageObjects = getPageObjects(['visualize', 'visEditor', 'visChart', 'timePicker']);

// FLAKY: https://github.com/elastic/kibana/issues/45089
describe('gauge chart', function indexPatternCreation() {
Expand Down
8 changes: 1 addition & 7 deletions test/functional/apps/visualize/_heatmap_chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,7 @@ import expect from '@kbn/expect';
export default function({ getService, getPageObjects }) {
const log = getService('log');
const inspector = getService('inspector');
const PageObjects = getPageObjects([
'common',
'visualize',
'visEditor',
'visChart',
'timePicker',
]);
const PageObjects = getPageObjects(['visualize', 'visEditor', 'visChart', 'timePicker']);

describe('heatmap chart', function indexPatternCreation() {
this.tags('smoke');
Expand Down
8 changes: 1 addition & 7 deletions test/functional/apps/visualize/_inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,7 @@ export default function({ getService, getPageObjects }) {
const log = getService('log');
const inspector = getService('inspector');
const filterBar = getService('filterBar');
const PageObjects = getPageObjects([
'common',
'visualize',
'visEditor',
'visChart',
'timePicker',
]);
const PageObjects = getPageObjects(['visualize', 'visEditor', 'visChart', 'timePicker']);

describe('inspector', function describeIndexTests() {
this.tags('smoke');
Expand Down
2 changes: 1 addition & 1 deletion test/functional/apps/visualize/_markdown_vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import expect from '@kbn/expect';

export default function({ getPageObjects, getService }) {
const PageObjects = getPageObjects(['common', 'visualize', 'visEditor', 'visChart', 'header']);
const PageObjects = getPageObjects(['visualize', 'visEditor', 'visChart', 'header']);
const find = getService('find');
const inspector = getService('inspector');
const markdown = `
Expand Down
8 changes: 1 addition & 7 deletions test/functional/apps/visualize/_metric_chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,7 @@ export default function({ getService, getPageObjects }) {
const retry = getService('retry');
const filterBar = getService('filterBar');
const inspector = getService('inspector');
const PageObjects = getPageObjects([
'common',
'visualize',
'visEditor',
'visChart',
'timePicker',
]);
const PageObjects = getPageObjects(['visualize', 'visEditor', 'visChart', 'timePicker']);

describe('metric chart', function() {
before(async function() {
Expand Down
1 change: 0 additions & 1 deletion test/functional/apps/visualize/_pie_chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export default function({ getService, getPageObjects }) {
'visEditor',
'visChart',
'header',
'settings',
'timePicker',
]);

Expand Down
1 change: 0 additions & 1 deletion test/functional/apps/visualize/_point_series_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export default function({ getService, getPageObjects }) {
const kibanaServer = getService('kibanaServer');
const browser = getService('browser');
const PageObjects = getPageObjects([
'common',
'visualize',
'header',
'pointSeries',
Expand Down
8 changes: 1 addition & 7 deletions test/functional/apps/visualize/_region_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,7 @@ export default function({ getService, getPageObjects }) {
const inspector = getService('inspector');
const log = getService('log');
const find = getService('find');
const PageObjects = getPageObjects([
'common',
'visualize',
'visEditor',
'timePicker',
'settings',
]);
const PageObjects = getPageObjects(['visualize', 'visEditor', 'timePicker']);

before(async function() {
log.debug('navigateToApp visualize');
Expand Down
1 change: 0 additions & 1 deletion test/functional/apps/visualize/_tile_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export default function({ getService, getPageObjects }) {
'visEditor',
'visChart',
'timePicker',
'settings',
'tileMap',
]);

Expand Down
12 changes: 6 additions & 6 deletions test/functional/apps/visualize/_vega_chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import expect from '@kbn/expect';

export default function({ getService, getPageObjects }) {
const PageObjects = getPageObjects(['common', 'header', 'timePicker', 'visualize', 'visChart']);
const PageObjects = getPageObjects(['timePicker', 'visualize', 'visChart', 'vegaChart']);
const filterBar = getService('filterBar');
const inspector = getService('inspector');
const log = getService('log');
Expand All @@ -40,15 +40,15 @@ export default function({ getService, getPageObjects }) {
});

it.skip('should have some initial vega spec text', async function() {
const vegaSpec = await PageObjects.visChart.getVegaSpec();
const vegaSpec = await PageObjects.vegaChart.getSpec();
expect(vegaSpec)
.to.contain('{')
.and.to.contain('data');
expect(vegaSpec.length).to.be.above(500);
});

it('should have view and control containers', async function() {
const view = await PageObjects.visChart.getVegaViewContainer();
const view = await PageObjects.vegaChart.getViewContainer();
expect(view).to.be.ok();
const size = await view.getSize();
expect(size)
Expand All @@ -57,7 +57,7 @@ export default function({ getService, getPageObjects }) {
expect(size.width).to.be.above(0);
expect(size.height).to.be.above(0);

const controls = await PageObjects.visChart.getVegaControlContainer();
const controls = await PageObjects.vegaChart.getControlContainer();
expect(controls).to.be.ok();
});
});
Expand All @@ -73,9 +73,9 @@ export default function({ getService, getPageObjects }) {
});

it.skip('should render different data in response to filter change', async function() {
await PageObjects.visualize.expectVisToMatchScreenshot('vega_chart');
await PageObjects.vegaChart.expectVisToMatchScreenshot('vega_chart');
await filterBar.addFilter('@tags.raw', 'is', 'error');
await PageObjects.visualize.expectVisToMatchScreenshot('vega_chart_filtered');
await PageObjects.vegaChart.expectVisToMatchScreenshot('vega_chart_filtered');
});
});
});
Expand Down
9 changes: 1 addition & 8 deletions test/functional/apps/visualize/_vertical_bar_chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,7 @@ export default function({ getService, getPageObjects }) {
const inspector = getService('inspector');
const testSubjects = getService('testSubjects');
const filterBar = getService('filterBar');
const PageObjects = getPageObjects([
'common',
'visualize',
'visEditor',
'visChart',
'header',
'timePicker',
]);
const PageObjects = getPageObjects(['visualize', 'visEditor', 'visChart', 'timePicker']);

// FLAKY: https://github.com/elastic/kibana/issues/22322
describe('vertical bar chart', function() {
Expand Down
2 changes: 1 addition & 1 deletion test/functional/apps/visualize/_visualize_listing.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import expect from '@kbn/expect';

export default function({ getService, getPageObjects }) {
const PageObjects = getPageObjects(['visualize', 'visEditor', 'header', 'common']);
const PageObjects = getPageObjects(['visualize', 'visEditor']);
const listingTable = getService('listingTable');

// FLAKY: https://github.com/elastic/kibana/issues/40912
Expand Down
3 changes: 2 additions & 1 deletion test/functional/page_objects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import { NewsfeedPageProvider } from './newsfeed_page';
import { PointSeriesPageProvider } from './point_series_page';
// @ts-ignore not TS yet
import { SettingsPageProvider } from './settings_page';
// @ts-ignore not TS yet
import { SharePageProvider } from './share_page';
// @ts-ignore not TS yet
import { ShieldPageProvider } from './shield_page';
Expand All @@ -53,6 +52,7 @@ import { VisualizeEditorPageProvider } from './visualize_editor_page';
import { VisualizeChartPageProvider } from './visualize_chart_page';
import { TileMapPageProvider } from './tile_map_page';
import { TagCloudPageProvider } from './tag_cloud_page';
import { VegaChartPageProvider } from './vega_chart_page';

export const pageObjects = {
common: CommonPageProvider,
Expand All @@ -77,4 +77,5 @@ export const pageObjects = {
visChart: VisualizeChartPageProvider,
tileMap: TileMapPageProvider,
tagCloud: TagCloudPageProvider,
vegaChart: VegaChartPageProvider,
};
2 changes: 1 addition & 1 deletion test/functional/page_objects/tile_map_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function TileMapPageProvider({ getService, getPageObjects }: FtrProviderC
const retry = getService('retry');
const log = getService('log');
const inspector = getService('inspector');
const { header } = getPageObjects(['common', 'header']);
const { header } = getPageObjects(['header']);

class TileMapPage {
public async getZoomSelectors(zoomSelector: string) {
Expand Down
91 changes: 91 additions & 0 deletions test/functional/page_objects/vega_chart_page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import expect from '@kbn/expect';
import { FtrProviderContext } from '../ftr_provider_context';

export function VegaChartPageProvider({
getService,
getPageObjects,
updateBaselines,
}: FtrProviderContext & { updateBaselines: boolean }) {
const find = getService('find');
const testSubjects = getService('testSubjects');
const browser = getService('browser');
const screenshot = getService('screenshots');
const log = getService('log');
const { visEditor, visChart } = getPageObjects(['visEditor', 'visChart']);

class VegaChartPage {
public async getSpec() {
// Adapted from console_page.js:getVisibleTextFromAceEditor(). Is there a common utilities file?
const editor = await testSubjects.find('vega-editor');
const lines = await editor.findAllByClassName('ace_line_group');
const linesText = await Promise.all(
lines.map(async line => {
return await line.getVisibleText();
})
);
return linesText.join('\n');
}

public async getViewContainer() {
return await find.byCssSelector('div.vgaVis__view');
}

public async getControlContainer() {
return await find.byCssSelector('div.vgaVis__controls');
}

/**
* Removes chrome and takes a small screenshot of a vis to compare against a baseline.
* @param {string} name The name of the baseline image.
* @param {object} opts Options object.
* @param {number} opts.threshold Threshold for allowed variance when comparing images.
*/
public async expectVisToMatchScreenshot(name: string, opts = { threshold: 0.05 }) {
log.debug(`expectVisToMatchScreenshot(${name})`);

// Collapse sidebar and inject some CSS to hide the nav so we have a focused screenshot
await visEditor.clickEditorSidebarCollapse();
await visChart.waitForVisualizationRenderingStabilized();
await browser.execute(`
var el = document.createElement('style');
el.id = '__data-test-style';
el.innerHTML = '[data-test-subj="headerGlobalNav"] { display: none; } ';
el.innerHTML += '[data-test-subj="top-nav"] { display: none; } ';
el.innerHTML += '[data-test-subj="experimentalVisInfo"] { display: none; } ';
document.body.appendChild(el);
`);

const percentDifference = await screenshot.compareAgainstBaseline(name, updateBaselines);

// Reset the chart to its original state
await browser.execute(`
var el = document.getElementById('__data-test-style');
document.body.removeChild(el);
`);
await visEditor.clickEditorSidebarCollapse();
await visChart.waitForVisualizationRenderingStabilized();
expect(percentDifference).to.be.lessThan(opts.threshold);
}
}

return new VegaChartPage();
}
20 changes: 0 additions & 20 deletions test/functional/page_objects/visualize_chart_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,26 +324,6 @@ export function VisualizeChartPageProvider({ getService, getPageObjects }: FtrPr
return element.getVisibleText();
}

public async getVegaSpec() {
// Adapted from console_page.js:getVisibleTextFromAceEditor(). Is there a common utilities file?
const editor = await testSubjects.find('vega-editor');
const lines = await editor.findAllByClassName('ace_line_group');
const linesText = await Promise.all(
lines.map(async line => {
return await line.getVisibleText();
})
);
return linesText.join('\n');
}

public async getVegaViewContainer() {
return await find.byCssSelector('div.vgaVis__view');
}

public async getVegaControlContainer() {
return await find.byCssSelector('div.vgaVis__controls');
}

/**
* If you are writing new tests, you should rather look into getTableVisContent method instead.
*/
Expand Down
Loading

0 comments on commit bd0e10b

Please sign in to comment.