Skip to content

Commit 3005944

Browse files
committed
[ML] functional tests for sub-aggregations
1 parent 5bf217c commit 3005944

File tree

4 files changed

+62
-18
lines changed

4 files changed

+62
-18
lines changed

x-pack/plugins/transform/public/app/sections/create_transform/components/aggregation_list/__snapshots__/list_form.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugins/transform/public/app/sections/create_transform/components/aggregation_list/list_form.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const AggListForm: React.FC<AggListProps> = ({ deleteHandler, list, onCha
3232
const otherAggNames = listKeys.filter((k) => k !== aggName);
3333
return (
3434
<Fragment key={aggName}>
35-
<EuiPanel paddingSize="s" data-test-subj={`transformAggregationEntry ${i}`}>
35+
<EuiPanel paddingSize="s" data-test-subj={`transformAggregationEntry_${i}`}>
3636
<AggLabelForm
3737
deleteHandler={deleteHandler}
3838
item={list[aggName]}

x-pack/test/functional/apps/transform/creation_index_pattern.ts

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ export default function ({ getService }: FtrProviderContext) {
5757
transformFilterAggTypeSelector: 'term',
5858
transformFilterTermValueSelector: 'New York',
5959
},
60+
subAggs: [
61+
{
62+
identifier: 'max(products.base_price)',
63+
label: 'products.base_price.max',
64+
},
65+
],
6066
},
6167
],
6268
transformId: `ec_1_${Date.now()}`,
@@ -93,6 +99,13 @@ export default function ({ getService }: FtrProviderContext) {
9399
'geoip.city_name': 'New York',
94100
},
95101
},
102+
aggs: {
103+
'products.base_price.max': {
104+
max: {
105+
field: 'products.base_price',
106+
},
107+
},
108+
},
96109
},
97110
},
98111
},
@@ -131,6 +144,12 @@ export default function ({ getService }: FtrProviderContext) {
131144
form: {
132145
transformFilterAggTypeSelector: 'exists',
133146
},
147+
subAggs: [
148+
{
149+
identifier: 'max(products.discount_amount)',
150+
label: 'products.discount_amount.max',
151+
},
152+
],
134153
},
135154
],
136155
transformId: `ec_2_${Date.now()}`,
@@ -162,6 +181,13 @@ export default function ({ getService }: FtrProviderContext) {
162181
field: 'customer_phone',
163182
},
164183
},
184+
aggs: {
185+
'products.discount_amount.max': {
186+
max: {
187+
feild: 'products.discount_amount',
188+
},
189+
},
190+
},
165191
},
166192
},
167193
},
@@ -249,11 +275,7 @@ export default function ({ getService }: FtrProviderContext) {
249275
});
250276

251277
it('adds the aggregation entries', async () => {
252-
for (const [index, agg] of testData.aggregationEntries.entries()) {
253-
await transform.wizard.assertAggregationInputExists();
254-
await transform.wizard.assertAggregationInputValue([]);
255-
await transform.wizard.addAggregationEntry(index, agg.identifier, agg.label, agg.form);
256-
}
278+
await transform.wizard.addAggregationEntries(testData.aggregationEntries);
257279
});
258280

259281
it('displays the advanced pivot editor switch', async () => {

x-pack/test/functional/services/transform/wizard.ts

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,20 @@ export function TransformWizardProvider({ getService }: FtrProviderContext) {
242242
await this.assertGroupByEntryExists(index, expectedLabel, expectedIntervalLabel);
243243
},
244244

245-
async assertAggregationInputExists() {
246-
await testSubjects.existOrFail('transformAggregationSelection > comboBoxInput');
245+
getComboBoxInputSelector(parentSelector = ''): string {
246+
return `${parentSelector && `${parentSelector} > `}${
247+
parentSelector ? 'transformSubAggregationSelection' : 'transformAggregationSelection'
248+
} > comboBoxInput`;
247249
},
248250

249-
async assertAggregationInputValue(expectedIdentifier: string[]) {
251+
async assertAggregationInputExists(parentSelector?: string) {
252+
await testSubjects.existOrFail(this.getComboBoxInputSelector(parentSelector));
253+
},
254+
255+
async assertAggregationInputValue(expectedIdentifier: string[], parentSelector?: string) {
250256
await retry.tryForTime(2000, async () => {
251257
const comboBoxSelectedOptions = await comboBox.getComboBoxSelectedOptions(
252-
'transformAggregationSelection > comboBoxInput'
258+
this.getComboBoxInputSelector(parentSelector)
253259
);
254260
expect(comboBoxSelectedOptions).to.eql(
255261
expectedIdentifier,
@@ -258,27 +264,43 @@ export function TransformWizardProvider({ getService }: FtrProviderContext) {
258264
});
259265
},
260266

261-
async assertAggregationEntryExists(index: number, expectedLabel: string) {
262-
await testSubjects.existOrFail(`transformAggregationEntry ${index}`);
267+
async assertAggregationEntryExists(index: number, expectedLabel: string, parentSelector = '') {
268+
const aggEntryPanelSelector = `${
269+
parentSelector && `${parentSelector} > `
270+
}transformAggregationEntry_${index}`;
271+
await testSubjects.existOrFail(aggEntryPanelSelector);
263272

264273
const actualLabel = await testSubjects.getVisibleText(
265-
`transformAggregationEntry ${index} > transformAggregationEntryLabel`
274+
`${aggEntryPanelSelector} > transformAggregationEntryLabel`
266275
);
267276
expect(actualLabel).to.eql(
268277
expectedLabel,
269278
`Label for aggregation entry '${index}' should be '${expectedLabel}' (got '${actualLabel}')`
270279
);
271280
},
272281

282+
async addAggregationEntries(aggregationEntries: any[], parentSelector?: string) {
283+
for (const [index, agg] of aggregationEntries.entries()) {
284+
await this.assertAggregationInputExists(parentSelector);
285+
await this.assertAggregationInputValue([], parentSelector);
286+
await this.addAggregationEntry(index, agg.identifier, agg.label, agg.form, parentSelector);
287+
288+
if (agg.subAggs) {
289+
await this.addAggregationEntries(agg.subAggs, `transformAggregationEntry_${index}`);
290+
}
291+
}
292+
},
293+
273294
async addAggregationEntry(
274295
index: number,
275296
identifier: string,
276297
expectedLabel: string,
277-
formData?: Record<string, any>
298+
formData?: Record<string, any>,
299+
parentSelector = ''
278300
) {
279-
await comboBox.set('transformAggregationSelection > comboBoxInput', identifier);
280-
await this.assertAggregationInputValue([]);
281-
await this.assertAggregationEntryExists(index, expectedLabel);
301+
await comboBox.set(this.getComboBoxInputSelector(parentSelector), identifier);
302+
await this.assertAggregationInputValue([], parentSelector);
303+
await this.assertAggregationEntryExists(index, expectedLabel, parentSelector);
282304

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

0 commit comments

Comments
 (0)