Skip to content

Commit ca156f1

Browse files
authored
test(ad): add Suggest parameters E2E and stabilize selections (#1847)
1 parent 0ed2714 commit ca156f1

File tree

3 files changed

+96
-9
lines changed

3 files changed

+96
-9
lines changed

cypress/integration/plugins/anomaly-detection-dashboards-plugin/create_detector_spec.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,17 @@ context('Create detector workflow', () => {
6262
// Configure model step
6363
cy.getElementByTestId('featureNameTextInput-0').type(TEST_FEATURE_NAME);
6464
selectTopItemFromFilter('featureFieldTextInput-0', false);
65+
66+
// Suggest parameters
67+
cy.getElementByTestId('suggestParametersButton').click();
68+
cy.getElementByTestId('suggestParametersDialogTitle').should('exist');
69+
cy.getElementByTestId('generateSuggestionsButton').click();
70+
cy.getElementByTestId('suggestedParametersResult').should('exist');
71+
cy.getElementByTestId('useSuggestedParametersButton').click();
72+
73+
// The dialog should close and we're back on the model configuration page
74+
cy.getElementByTestId('suggestParametersDialogTitle').should('not.exist');
75+
6576
cy.getElementByTestId('configureModelNextButton').click();
6677
cy.getElementByTestId('configureOrEditModelConfigurationTitle').should(
6778
'not.exist'

cypress/integration/plugins/anomaly-detection-dashboards-plugin/create_remote_detector_spec.js

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,8 @@ context('Create remote detector workflow', () => {
223223

224224
cy.getElementByTestId('indicesFilter').type(TEST_INDEX_NAME);
225225
cy.wait(500);
226-
cy.contains(
227-
'.euiComboBoxOption__content',
228-
`${remoteClusterName}:${TEST_INDEX_NAME}`
229-
).click();
226+
cy.get(`button[title="${remoteClusterName}:${TEST_INDEX_NAME}"]`).click();
227+
230228
cy.wait(1500);
231229

232230
selectTopItemFromFilter('timestampFilter', false);
@@ -256,6 +254,17 @@ context('Create remote detector workflow', () => {
256254
// Configure model step
257255
cy.getElementByTestId('featureNameTextInput-0').type(TEST_FEATURE_NAME);
258256
selectTopItemFromFilter('featureFieldTextInput-0', false);
257+
258+
// Suggest parameters
259+
cy.getElementByTestId('suggestParametersButton').click();
260+
cy.getElementByTestId('suggestParametersDialogTitle').should('exist');
261+
cy.getElementByTestId('generateSuggestionsButton').click();
262+
cy.getElementByTestId('suggestedParametersResult').should('exist');
263+
cy.getElementByTestId('useSuggestedParametersButton').click();
264+
265+
// The dialog should close and we're back on the model configuration page
266+
cy.getElementByTestId('suggestParametersDialogTitle').should('not.exist');
267+
259268
cy.getElementByTestId('configureModelNextButton').click();
260269
cy.getElementByTestId('configureOrEditModelConfigurationTitle').should(
261270
'not.exist'
@@ -324,10 +333,9 @@ context('Create remote detector workflow', () => {
324333
cy.getElementByTestId('indicesFilter').type('sample-ad-index-t');
325334
cy.wait(1000);
326335

327-
cy.get('.euiComboBoxOption__content')
328-
.contains(`${remoteClusterName}:${TEST_SECOND_INDEX_NAME}`)
329-
.should('exist')
330-
.click();
336+
cy.get(
337+
`button[title="${remoteClusterName}:${TEST_SECOND_INDEX_NAME}"]`
338+
).click();
331339

332340
selectTopItemFromFilter('timestampFilter', false);
333341

@@ -354,6 +362,20 @@ context('Create remote detector workflow', () => {
354362
.should('exist')
355363
.click({ force: true });
356364

365+
// wait for feature field to be populated
366+
// otherwise suggest API reports illegal arguments exception
367+
cy.wait(500);
368+
369+
// Suggest parameters
370+
cy.getElementByTestId('suggestParametersButton').click();
371+
cy.getElementByTestId('suggestParametersDialogTitle').should('exist');
372+
cy.getElementByTestId('generateSuggestionsButton').click();
373+
cy.getElementByTestId('suggestedParametersResult').should('exist');
374+
cy.getElementByTestId('useSuggestedParametersButton').click();
375+
376+
// The dialog should close and we're back on the model configuration page
377+
cy.getElementByTestId('suggestParametersDialogTitle').should('not.exist');
378+
357379
cy.getElementByTestId('configureModelNextButton').click();
358380
cy.getElementByTestId('configureOrEditModelConfigurationTitle').should(
359381
'not.exist'

cypress/integration/plugins/anomaly-detection-dashboards-plugin/forecaster_configuration_spec.js

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*/
55

66
import { AD_FIXTURE_BASE_PATH, FORECAST_URL } from '../../../utils/constants';
7-
import { selectTopItemFromFilter } from '../../../utils/helpers';
87

98
/*
109
* Scenarios covered in this Cypress test:
@@ -90,6 +89,61 @@ context('edit forecaster workflow', () => {
9089
cy.deleteForecastIndices();
9190
});
9291

92+
const selectTopItemFromFilter = (
93+
dataTestSubjectName,
94+
allowMultipleSelections = true
95+
) => {
96+
cy.getElementByTestId(dataTestSubjectName)
97+
.find('[data-test-subj=comboBoxToggleListButton]')
98+
.click({ force: true });
99+
100+
clickFirstFilterItem();
101+
102+
cy.wait(1000);
103+
104+
// If multiple options can be selected, the combo box doesn't close after selecting an option.
105+
// We manually close in this case, so the unselected items aren't visible on the page.
106+
// This way, we can test whether or not filtering has worked as expected.
107+
if (allowMultipleSelections) {
108+
cy.getElementByTestId(dataTestSubjectName)
109+
.find('[data-test-subj=comboBoxToggleListButton]')
110+
.click();
111+
}
112+
};
113+
114+
/**
115+
* Clicks the first option in the EUI filter popover and waits until the combo box pill reflects the selection.
116+
* EUI renders the popover asynchronously, so the first click sometimes lands before the list (or the combo box pill)
117+
* is ready. We retry up to six times with a short delay so the command behaves deterministically even on slower UI renders.
118+
*/
119+
const clickFirstFilterItem = (attempt = 0) => {
120+
const maxAttempts = 6;
121+
122+
return cy
123+
.get('.euiFilterSelectItem')
124+
.first()
125+
.then(($item) => {
126+
const chosen = $item.text().trim();
127+
cy.wrap($item).click();
128+
129+
return cy
130+
.get('[data-test-subj="categoryFieldComboBox"] .euiComboBoxPill')
131+
.then(($pill) => {
132+
if ($pill.length && $pill.text().includes(chosen)) {
133+
return; // success
134+
}
135+
136+
if (attempt >= maxAttempts - 1) {
137+
throw new Error(
138+
'Could not select a filter item after 6 attempts'
139+
);
140+
}
141+
142+
return cy.wait(500).then(() => clickFirstFilterItem(attempt + 1));
143+
});
144+
});
145+
};
146+
93147
it('Create, edit, and delete a forecaster', () => {
94148
// Define Forecaster step
95149
cy.visit(FORECAST_URL.CREATE_FORECASTER);

0 commit comments

Comments
 (0)