Skip to content

Commit

Permalink
✅ Add functional tests for layer actions and random sampling
Browse files Browse the repository at this point in the history
  • Loading branch information
dej611 committed Oct 19, 2022
1 parent 4f63f67 commit f9e1bb9
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,7 @@ export function getFormBasedDatasource({
execute: openLayerSettings,
icon: 'gear',
isCompatible: Boolean(state.layers[layerId]),
'data-test-subj': 'lnsLayerSettings',
},
];
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export function LayerSettingsPanel({
return (
<EuiFormRow
display="columnCompressed"
data-test-subj="lns-indexPattern-random-sampling-row"
fullWidth
helpText={i18n.translate('xpack.lens.xyChart.randomSampling.help', {
defaultMessage: 'Change the sampling probability to see how your chart is affected',
Expand Down Expand Up @@ -52,6 +53,7 @@ export function LayerSettingsPanel({
}
>
<EuiRange
data-test-subj="lns-indexPattern-random-sampling"
value={currentSamplingIndex}
onChange={(e) => {
setState({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ const InContextMenuActions = (props: LayerActionsProps) => {
closePopover={closePopover}
panelPaddingSize="none"
anchorPosition="downLeft"
panelProps={{
'data-test-subj': 'lnsLayerActionsMenu',
}}
>
<EuiContextMenuPanel
size="s"
Expand Down
1 change: 1 addition & 0 deletions x-pack/test/functional/apps/lens/group1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export default ({ getService, loadTestFile, getPageObjects }: FtrProviderContext
loadTestFile(require.resolve('./table_dashboard'));
loadTestFile(require.resolve('./table'));
loadTestFile(require.resolve('./text_based_languages'));
loadTestFile(require.resolve('./layer_actions'));
}
});
};
91 changes: 91 additions & 0 deletions x-pack/test/functional/apps/lens/group1/layer_actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

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

export default function ({ getService, getPageObjects }: FtrProviderContext) {
const PageObjects = getPageObjects(['visualize', 'lens', 'common', 'header']);
const find = getService('find');
const testSubjects = getService('testSubjects');

describe('lens layer actions tests', () => {
it('should allow creation of lens xy chart', async () => {
await PageObjects.visualize.navigateToNewVisualization();
await PageObjects.visualize.clickVisType('lens');
await PageObjects.lens.goToTimeRange();

await PageObjects.lens.openLayerContextMenu();

// should be 3 actions available
expect(
(await find.allByCssSelector('[data-test-subj=lnsLayerActionsMenu] button')).length
).to.eql(3);
});

it('should open layer settings for a data layer', async () => {
// click on open layer settings
await testSubjects.click('lnsLayerSettings');
// random sampling available
await testSubjects.existOrFail('lns-indexPattern-random-sampling-row');
// tweak the value
await PageObjects.lens.dragRangeInput('lns-indexPattern-random-sampling', 2, 'left');

expect(await PageObjects.lens.getRangeInputValue('lns-indexPattern-random-sampling')).to.eql(
2 // 0.01
);
await testSubjects.click('lns-indexPattern-dimensionContainerBack');
});

it('should add an annotation layer and settings shoud not be available', async () => {
// configure a date histogram
await PageObjects.lens.configureDimension({
dimension: 'lnsXY_xDimensionPanel > lns-empty-dimension',
operation: 'date_histogram',
field: '@timestamp',
});

await PageObjects.lens.configureDimension({
dimension: 'lnsXY_yDimensionPanel > lns-empty-dimension',
operation: 'average',
field: 'bytes',
});
// add annotation layer
await testSubjects.click('lnsLayerAddButton');
await testSubjects.click(`lnsLayerAddButton-annotations`);
await PageObjects.lens.openLayerContextMenu(1);
// layer settings not available
await testSubjects.missingOrFail('lnsLayerSettings');
});

it('should switch to pie chart and have layer settings available', async () => {
await PageObjects.lens.switchToVisualization('pie');
await PageObjects.lens.openLayerContextMenu();
// layer settings still available
// open the panel
await testSubjects.click('lnsLayerSettings');
// check the sampling value
expect(await PageObjects.lens.getRangeInputValue('lns-indexPattern-random-sampling')).to.eql(
2 // 0.01
);
await testSubjects.click('lns-indexPattern-dimensionContainerBack');
});

it('should switch to table and still have layer settings', async () => {
await PageObjects.lens.switchToVisualization('lnsDatatable');
await PageObjects.lens.openLayerContextMenu();
// layer settings still available
// open the panel
await testSubjects.click('lnsLayerSettings');
// check the sampling value
expect(await PageObjects.lens.getRangeInputValue('lns-indexPattern-random-sampling')).to.eql(
2 // 0.01
);
await testSubjects.click('lns-indexPattern-dimensionContainerBack');
});
});
}
17 changes: 17 additions & 0 deletions x-pack/test/functional/page_objects/lens_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,19 @@ export function LensPageProvider({ getService, getPageObjects }: FtrProviderCont
await this.waitForVisualization();
},

async dragRangeInput(testId: string, steps: number = 1, direction: 'left' | 'right' = 'right') {
const inputEl = await testSubjects.find(testId);
await inputEl.focus();
const browserKey = direction === 'left' ? browser.keys.LEFT : browser.keys.RIGHT;
while (steps--) {
await browser.pressKeys(browserKey);
}
},

async getRangeInputValue(testId: string) {
return (await testSubjects.find(testId)).getAttribute('value');
},

async isTopLevelAggregation() {
return await testSubjects.isEuiSwitchChecked('indexPattern-nesting-switch');
},
Expand Down Expand Up @@ -1104,6 +1117,10 @@ export function LensPageProvider({ getService, getPageObjects }: FtrProviderCont
);
},

async openLayerContextMenu(index: number = 0) {
await testSubjects.click(`lnsLayerSplitButton--${index}`);
},

async toggleColumnVisibility(dimension: string, no = 1) {
await this.openDimensionEditor(dimension);
const id = 'lns-table-column-hidden';
Expand Down

0 comments on commit f9e1bb9

Please sign in to comment.