Skip to content

Commit 7d5b3c1

Browse files
committed
Add timeout
Signed-off-by: Lin Wang <[email protected]>
1 parent 7ebbee1 commit 7d5b3c1

File tree

1 file changed

+52
-14
lines changed

1 file changed

+52
-14
lines changed

cypress/integration/plugins/dashboards-assistant/mds_query_enhancements_suggest_anomaly_detector_spec.js

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -121,29 +121,67 @@ const testSuggestAD = (url) => {
121121
cy.wait('@suggestParameters');
122122

123123
// Check main UI elements are present
124-
cy.get('[data-test-subj="detectorNameTextInputFlyout"]').should('exist');
125-
cy.get('#add-anomaly-detector__title').should(
126-
'contain',
127-
'Suggested anomaly detector'
124+
cy.get('[data-test-subj="detectorNameTextInputFlyout"]').should('exist'); // Check for initial elements with adequate timeouts
125+
cy.get('#add-anomaly-detector__title', { timeout: 10000 })
126+
.should('be.visible')
127+
.should('contain', 'Suggested anomaly detector');
128+
129+
cy.get('[data-test-subj="detectionInterval"]', { timeout: 5000 }).should(
130+
'exist'
131+
);
132+
cy.get('[data-test-subj="windowDelay"]', { timeout: 5000 }).should(
133+
'exist'
128134
);
129-
cy.get('[data-test-subj="detectionInterval"]').should('exist');
130-
cy.get('[data-test-subj="windowDelay"]').should('exist');
131135

136+
// Expand the accordion with proper waiting
132137
cy.get('[id="detectorDetailsAccordion"]')
138+
.should('exist')
133139
.parent()
134140
.find('[data-test-subj="accordionTitleButton"]')
141+
.should('be.visible')
135142
.click();
136143

137-
// Test empty name validation
138-
cy.get('[data-test-subj="detectorNameTextInputFlyout"]').clear();
139-
cy.get('[data-test-subj="detectorNameTextInputFlyout"]').blur();
140-
cy.contains('Detector name cannot be empty').should('be.visible');
144+
// Wait for animation to complete
145+
cy.wait(1000);
141146

142-
// Test valid name
143-
cy.get('[data-test-subj="detectorNameTextInputFlyout"]').type(
144-
'test-detector-name' + Math.floor(Math.random() * 100) + 1
147+
// Test empty name validation with safer interactions
148+
cy.get('[data-test-subj="detectorNameTextInputFlyout"]')
149+
.should('be.visible')
150+
.clear();
151+
152+
// Use separate commands instead of chaining for more stability
153+
cy.get('[data-test-subj="detectorNameTextInputFlyout"]')
154+
.should('be.visible')
155+
.blur({ force: true });
156+
157+
// Wait and check for error message with retry
158+
cy.wait(500);
159+
cy.get('body', { timeout: 10000 }).should(
160+
'contain.text',
161+
'Detector name cannot be empty'
145162
);
146-
cy.contains('Detector name cannot be empty').should('not.exist');
163+
164+
// Generate random detector name
165+
const detectorName =
166+
'test-detector-name' + Math.floor(Math.random() * 100 + 1);
167+
168+
// Test valid name with separate commands
169+
cy.get('[data-test-subj="detectorNameTextInputFlyout"]')
170+
.should('be.visible')
171+
.clear()
172+
.type(detectorName, { delay: 50 }); // Add typing delay for stability
173+
174+
// Wait for validation to process
175+
cy.wait(500);
176+
177+
// Check that error message is gone
178+
cy.get('body').then(($body) => {
179+
if ($body.text().includes('Detector name cannot be empty')) {
180+
throw new Error(
181+
'Error message still visible after entering valid name'
182+
);
183+
}
184+
});
147185
});
148186

149187
it('should create detector successfully', () => {

0 commit comments

Comments
 (0)