Skip to content

Commit

Permalink
[TSVB] Table tests (#36762) (#37071)
Browse files Browse the repository at this point in the history
* implement table tests
  • Loading branch information
vitalics authored May 24, 2019
1 parent 382970b commit 04c6505
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 22 deletions.
19 changes: 0 additions & 19 deletions test/functional/apps/visualize/_tsvb_chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,25 +122,6 @@ export default function({ getService, getPageObjects }: FtrProviderContext) {
});
});

describe('table', () => {
beforeEach(async () => {
await PageObjects.visualBuilder.resetPage(
'2015-09-22 06:00:00.000',
'2015-09-22 11:00:00.000'
);
await PageObjects.visualBuilder.clickTable();
});

it('should display correct values on changing group by field and column name', async () => {
await PageObjects.visualBuilder.selectGroupByField('machine.os.raw');
await PageObjects.visualBuilder.setLabelValue('OS');
await PageObjects.visualize.waitForVisualizationRenderingStabilized();
const tableData = await PageObjects.visualBuilder.getViewTable();
const expectedData = 'OS Count\nwin 8 13\nwin xp 10\nwin 7 12\nios 5\nosx 3';
expect(tableData).to.be(expectedData);
});
});

describe.skip('switch index patterns', () => {
before(async () => {
log.debug('Load kibana_sample_data_flights data');
Expand Down
57 changes: 57 additions & 0 deletions test/functional/apps/visualize/_tsvb_table.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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';

// eslint-disable-next-line import/no-default-export
export default function({ getPageObjects }: FtrProviderContext) {
const { visualBuilder, visualize } = getPageObjects(['visualBuilder', 'visualize']);

describe('visual builder', function describeIndexTests() {
describe('table', () => {
beforeEach(async () => {
await visualBuilder.resetPage('2015-09-22 06:00:00.000', '2015-09-22 11:00:00.000');
await visualBuilder.clickTable();

await visualBuilder.checkTableTabIsPresent();
await visualBuilder.selectGroupByField('machine.os.raw');
await visualBuilder.setColumnLabelValue('OS');
await visualize.waitForVisualizationRenderingStabilized();
});

it('should display correct values on changing group by field and column name', async () => {
const EXPECTED = 'OS Count\nwin 8 13\nwin xp 10\nwin 7 12\nios 5\nosx 3';

const tableData = await visualBuilder.getViewTable();
expect(tableData).to.be(EXPECTED);
});

it('should display correct values on changing metrics aggregation', async () => {
const EXPECTED = 'OS Cardinality\nwin 8 12\nwin xp 9\nwin 7 8\nios 5\nosx 3';

await visualBuilder.setLabel('Cardinality');
await visualBuilder.selectAggType('Cardinality');
await visualBuilder.setFieldForAggregation('machine.ram');
const tableData = await visualBuilder.getViewTable();
expect(tableData).to.be(EXPECTED);
});
});
});
}
1 change: 1 addition & 0 deletions test/functional/apps/visualize/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export default function({ getService, loadTestFile }: FtrProviderContext) {
loadTestFile(require.resolve('./_vertical_bar_chart_nontimeindex'));
loadTestFile(require.resolve('./_tsvb_chart'));
loadTestFile(require.resolve('./_tsvb_markdown'));
loadTestFile(require.resolve('./_tsvb_table'));
loadTestFile(require.resolve('./_vega_chart'));
});
});
Expand Down
56 changes: 53 additions & 3 deletions test/functional/page_objects/visual_builder_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ export function VisualBuilderPageProvider({ getService, getPageObjects }: FtrPro
});
}

public async selectAggType(value: string, nth = 0) {
public async selectAggType(value: string, nth: number = 0): Promise<void> {
const elements = await testSubjects.findAll('aggSelector');
await comboBox.setElement(elements[nth], value);
return await PageObjects.header.waitUntilLoadingHasFinished();
Expand All @@ -262,14 +262,22 @@ export function VisualBuilderPageProvider({ getService, getPageObjects }: FtrPro
await comboBox.set('groupByField', fieldName);
}

public async setLabelValue(value: string) {
public async setColumnLabelValue(value: string) {
const el = await testSubjects.find('columnLabelName');
await el.clearValue();
await el.type(value);
await PageObjects.header.waitUntilLoadingHasFinished();
}

public async getViewTable() {
/**
* get values for rendered table
*
* **Note:** this work only for table visualization
*
* @returns {Promise<string>}
* @memberof VisualBuilderPage
*/
public async getViewTable(): Promise<string> {
const tableView = await testSubjects.find('tableView');
return await tableView.getVisibleText();
}
Expand All @@ -294,6 +302,48 @@ export function VisualBuilderPageProvider({ getService, getPageObjects }: FtrPro
await el.pressKeys(browser.keys.RETURN);
await PageObjects.header.waitUntilLoadingHasFinished();
}

/**
* check that table visualization is visible and ready for interact
*
* @returns {Promise<void>}
* @memberof VisualBuilderPage
*/
public async checkTableTabIsPresent(): Promise<void> {
await testSubjects.existOrFail('visualizationLoader');
const isDataExists = await testSubjects.exists('tableView');
log.debug(`data is already rendered: ${isDataExists}`);
if (!isDataExists) {
await testSubjects.existOrFail('noTSVBDataMessage');
}
}

/**
* set label name for aggregation
*
* @param {string} labelName
* @param {number} [nth=0]
* @memberof VisualBuilderPage
*/
public async setLabel(labelName: string, nth: number = 0): Promise<void> {
const input = (await find.allByCssSelector('[placeholder="Label"]'))[nth];
await input.type(labelName);
}

/**
* set field for type of aggregation
*
* @param {string} field name of field
* @param {number} [aggNth=0] number of aggregation. Start by zero
* @default 0
* @memberof VisualBuilderPage
*/
public async setFieldForAggregation(field: string, aggNth: number = 0): Promise<void> {
const labels = await testSubjects.findAll('aggRow');
const label = labels[aggNth];
const fieldEl = (await label.findAllByCssSelector('[data-test-subj = "comboBoxInput"]'))[1];
await comboBox.setElement(fieldEl, field);
}
}

return new VisualBuilderPage();
Expand Down

0 comments on commit 04c6505

Please sign in to comment.