Bug 40383: (follow-up) Fix flaky Cypress EDIFACT search tests in CI

Replace cy.wait(N) + bare assertion with assertion-based waits using
{ timeout: 10000 }, and replace .type(term, { delay: 50 }) with
.invoke('val', term).trigger('input') to avoid keyboard simulation
timing races against the 500ms debounce in the search component.

Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
This commit is contained in:
Martin Renvoize 2026-04-13 09:27:53 +01:00
parent 278aa32c03
commit bda5afd49c
No known key found for this signature in database
GPG Key ID: 2D86E0EAEC83711B
2 changed files with 23 additions and 22 deletions

View File

@ -404,11 +404,8 @@ describe("EDIFACT Modal Tests", () => {
// Type a search query that should have multiple results
cy.get("#EDI_modal .edi-search-input").type("UNH");
// Wait for search to complete
cy.wait(1000);
// Check that results are found and navigation buttons are enabled
cy.get("#EDI_modal .edi-search-count").should(
// Wait for debounce + search to complete
cy.get("#EDI_modal .edi-search-count", { timeout: 10000 }).should(
"not.contain",
"0 results"
);
@ -426,20 +423,21 @@ describe("EDIFACT Modal Tests", () => {
// Search for something likely to exist
cy.get("#EDI_modal .edi-search-input").type("UN");
cy.wait(1000);
// If results found, navigation should be enabled
cy.get("#EDI_modal .edi-search-count").then($count => {
const countText = $count.text();
if (!countText.includes("0 results")) {
cy.get("#EDI_modal .edi-search-prev").should(
"not.be.disabled"
);
cy.get("#EDI_modal .edi-search-next").should(
"not.be.disabled"
);
// Wait for debounce + search to complete
cy.get("#EDI_modal .edi-search-count", { timeout: 10000 }).then(
$count => {
const countText = $count.text();
if (!countText.includes("0 results")) {
cy.get("#EDI_modal .edi-search-prev").should(
"not.be.disabled"
);
cy.get("#EDI_modal .edi-search-next").should(
"not.be.disabled"
);
}
}
});
);
});
it("should clear search when input is cleared", () => {

View File

@ -9,15 +9,18 @@ describe("EDIFACT Search Functionality Tests", () => {
// Clear input first to ensure clean state
cy.get("#EDI_modal .edi-search-input").clear();
// Type with delay and verify the value was entered correctly
cy.get("#EDI_modal .edi-search-input").type(searchTerm, { delay: 50 });
// Set value directly and trigger input event to avoid keyboard simulation
// timing races with the 500ms debounce in the component
cy.get("#EDI_modal .edi-search-input")
.invoke("val", searchTerm)
.trigger("input");
// Verify the input contains what we typed - retry if needed
// Verify the input contains what we typed
cy.get("#EDI_modal .edi-search-input").should("have.value", searchTerm);
if (shouldFindResults) {
// Wait for debounce + search to complete (with longer timeout for reliability)
cy.get("#EDI_modal .edi-search-count", { timeout: 3000 }).should(
// Wait for debounce + search to complete
cy.get("#EDI_modal .edi-search-count", { timeout: 10000 }).should(
"not.contain",
"0 results"
);