Skip to content

Commit

Permalink
[ML] functional tests for sub-aggregations
Browse files Browse the repository at this point in the history
  • Loading branch information
darnautov committed Jun 9, 2020
1 parent 5bf217c commit 3005944
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 18 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const AggListForm: React.FC<AggListProps> = ({ deleteHandler, list, onCha
const otherAggNames = listKeys.filter((k) => k !== aggName);
return (
<Fragment key={aggName}>
<EuiPanel paddingSize="s" data-test-subj={`transformAggregationEntry ${i}`}>
<EuiPanel paddingSize="s" data-test-subj={`transformAggregationEntry_${i}`}>
<AggLabelForm
deleteHandler={deleteHandler}
item={list[aggName]}
Expand Down
32 changes: 27 additions & 5 deletions x-pack/test/functional/apps/transform/creation_index_pattern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ export default function ({ getService }: FtrProviderContext) {
transformFilterAggTypeSelector: 'term',
transformFilterTermValueSelector: 'New York',
},
subAggs: [
{
identifier: 'max(products.base_price)',
label: 'products.base_price.max',
},
],
},
],
transformId: `ec_1_${Date.now()}`,
Expand Down Expand Up @@ -93,6 +99,13 @@ export default function ({ getService }: FtrProviderContext) {
'geoip.city_name': 'New York',
},
},
aggs: {
'products.base_price.max': {
max: {
field: 'products.base_price',
},
},
},
},
},
},
Expand Down Expand Up @@ -131,6 +144,12 @@ export default function ({ getService }: FtrProviderContext) {
form: {
transformFilterAggTypeSelector: 'exists',
},
subAggs: [
{
identifier: 'max(products.discount_amount)',
label: 'products.discount_amount.max',
},
],
},
],
transformId: `ec_2_${Date.now()}`,
Expand Down Expand Up @@ -162,6 +181,13 @@ export default function ({ getService }: FtrProviderContext) {
field: 'customer_phone',
},
},
aggs: {
'products.discount_amount.max': {
max: {
feild: 'products.discount_amount',
},
},
},
},
},
},
Expand Down Expand Up @@ -249,11 +275,7 @@ export default function ({ getService }: FtrProviderContext) {
});

it('adds the aggregation entries', async () => {
for (const [index, agg] of testData.aggregationEntries.entries()) {
await transform.wizard.assertAggregationInputExists();
await transform.wizard.assertAggregationInputValue([]);
await transform.wizard.addAggregationEntry(index, agg.identifier, agg.label, agg.form);
}
await transform.wizard.addAggregationEntries(testData.aggregationEntries);
});

it('displays the advanced pivot editor switch', async () => {
Expand Down
44 changes: 33 additions & 11 deletions x-pack/test/functional/services/transform/wizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,20 @@ export function TransformWizardProvider({ getService }: FtrProviderContext) {
await this.assertGroupByEntryExists(index, expectedLabel, expectedIntervalLabel);
},

async assertAggregationInputExists() {
await testSubjects.existOrFail('transformAggregationSelection > comboBoxInput');
getComboBoxInputSelector(parentSelector = ''): string {
return `${parentSelector && `${parentSelector} > `}${
parentSelector ? 'transformSubAggregationSelection' : 'transformAggregationSelection'
} > comboBoxInput`;
},

async assertAggregationInputValue(expectedIdentifier: string[]) {
async assertAggregationInputExists(parentSelector?: string) {
await testSubjects.existOrFail(this.getComboBoxInputSelector(parentSelector));
},

async assertAggregationInputValue(expectedIdentifier: string[], parentSelector?: string) {
await retry.tryForTime(2000, async () => {
const comboBoxSelectedOptions = await comboBox.getComboBoxSelectedOptions(
'transformAggregationSelection > comboBoxInput'
this.getComboBoxInputSelector(parentSelector)
);
expect(comboBoxSelectedOptions).to.eql(
expectedIdentifier,
Expand All @@ -258,27 +264,43 @@ export function TransformWizardProvider({ getService }: FtrProviderContext) {
});
},

async assertAggregationEntryExists(index: number, expectedLabel: string) {
await testSubjects.existOrFail(`transformAggregationEntry ${index}`);
async assertAggregationEntryExists(index: number, expectedLabel: string, parentSelector = '') {
const aggEntryPanelSelector = `${
parentSelector && `${parentSelector} > `
}transformAggregationEntry_${index}`;
await testSubjects.existOrFail(aggEntryPanelSelector);

const actualLabel = await testSubjects.getVisibleText(
`transformAggregationEntry ${index} > transformAggregationEntryLabel`
`${aggEntryPanelSelector} > transformAggregationEntryLabel`
);
expect(actualLabel).to.eql(
expectedLabel,
`Label for aggregation entry '${index}' should be '${expectedLabel}' (got '${actualLabel}')`
);
},

async addAggregationEntries(aggregationEntries: any[], parentSelector?: string) {
for (const [index, agg] of aggregationEntries.entries()) {
await this.assertAggregationInputExists(parentSelector);
await this.assertAggregationInputValue([], parentSelector);
await this.addAggregationEntry(index, agg.identifier, agg.label, agg.form, parentSelector);

if (agg.subAggs) {
await this.addAggregationEntries(agg.subAggs, `transformAggregationEntry_${index}`);
}
}
},

async addAggregationEntry(
index: number,
identifier: string,
expectedLabel: string,
formData?: Record<string, any>
formData?: Record<string, any>,
parentSelector = ''
) {
await comboBox.set('transformAggregationSelection > comboBoxInput', identifier);
await this.assertAggregationInputValue([]);
await this.assertAggregationEntryExists(index, expectedLabel);
await comboBox.set(this.getComboBoxInputSelector(parentSelector), identifier);
await this.assertAggregationInputValue([], parentSelector);
await this.assertAggregationEntryExists(index, expectedLabel, parentSelector);

if (formData !== undefined) {
await this.fillPopoverForm(identifier, expectedLabel, formData);
Expand Down

0 comments on commit 3005944

Please sign in to comment.