From 627373978396b17ca2069faaaf0d15bfbaf24997 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 9 Oct 2025 11:31:26 +0200 Subject: [PATCH] Bug 40981: Prevent KohaTable/Holdings_spec.ts to fail randomly There is a JS warning raised by DT which makes the tests fail: ``` The following error originated from your application code, not from Cypress. > DataTables warning detected in log: "DataTables warning: table id=holdings_table - Ajax error. For more information about this error, please see https://datatables.net/tn/7" ``` It is caused by a 404 returned by the API, because DT receives the response during the afterEach (after the objects have been deleted) We must wait for the responses when needed. Test plan: cypress run --spec t/cypress/integration/KohaTable/Holdings_spec.ts should still pass Signed-off-by: Lucas Gass --- .../integration/KohaTable/Holdings_spec.ts | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/t/cypress/integration/KohaTable/Holdings_spec.ts b/t/cypress/integration/KohaTable/Holdings_spec.ts index 8c77f678308..0b912641fae 100644 --- a/t/cypress/integration/KohaTable/Holdings_spec.ts +++ b/t/cypress/integration/KohaTable/Holdings_spec.ts @@ -34,11 +34,18 @@ describe("catalogue/detail/holdings_table with items", () => { it("Correctly init the table", function () { // Do not use `() => {` or this.objects won't be retrieved const biblio_id = this.objects.biblio.biblio_id; + + cy.intercept("get", `/api/v1/biblios/${biblio_id}/items*`).as( + "searchItems" + ); + cy.set_syspref("AlwaysShowHoldingsTableFilters", 1).then(() => { cy.visit( "/cgi-bin/koha/catalogue/detail.pl?biblionumber=" + biblio_id ); + cy.wait("@searchItems"); + cy.get(`#${table_id}_wrapper tbody tr`).should( "have.length", RESTdefaultPageSize @@ -54,6 +61,10 @@ describe("catalogue/detail/holdings_table with items", () => { // Do not use `() => {` or this.objects won't be retrieved const biblio_id = this.objects.biblio.biblio_id; + cy.intercept("get", `/api/v1/biblios/${biblio_id}/items*`).as( + "searchItems" + ); + cy.set_syspref("AlwaysShowHoldingsTableFilters", 0).then(() => { cy.visit( "/cgi-bin/koha/catalogue/detail.pl?biblionumber=" + biblio_id @@ -67,6 +78,8 @@ describe("catalogue/detail/holdings_table with items", () => { "items_table_settings.holdings" ); + cy.wait("@searchItems"); + cy.get("@columns").then(columns => { cy.get(`#${table_id}_wrapper tbody tr`).should( "have.length", @@ -83,6 +96,7 @@ describe("catalogue/detail/holdings_table with items", () => { .should("not.exist"); cy.get(`.${table_id}_table_controls .show_filters`).click(); + cy.wait("@searchItems"); cy.get(`#${table_id}_wrapper .dt-info`).contains( `Showing 1 to ${RESTdefaultPageSize} of ${baseTotalCount} entries` ); @@ -110,6 +124,8 @@ describe("catalogue/detail/holdings_table with items", () => { "items_table_settings.holdings" ); + cy.wait("@searchItems"); + cy.get("@columns").then(columns => { cy.get(`#${table_id}_wrapper tbody tr`).should( "have.length", @@ -120,6 +136,7 @@ describe("catalogue/detail/holdings_table with items", () => { cy.get(`#${table_id} thead tr`).should("have.length", 2); cy.get(`.${table_id}_table_controls .hide_filters`).click(); + cy.wait("@searchItems"); // Filters are not displayed cy.get(`#${table_id} thead tr`).should("have.length", 1); @@ -290,8 +307,15 @@ describe("catalogue/detail/holdings_table without items", () => { // Do not use `() => {` or this.objects won't be retrieved const biblio_id = this.objects.biblio.biblio_id; + cy.intercept("get", `/api/v1/biblios/${biblio_id}/items*`).as( + "searchItems" + ); + cy.visit("/cgi-bin/koha/catalogue/detail.pl?biblionumber=" + biblio_id); + // No API request + cy.get("@searchItems.all").should("have.length", 0); + cy.get(`#${table_id}_wrapper`).should("not.exist"); }); }); -- 2.39.5