From f4d85258069ea24744ae1f079bc8ec9b51cf0719 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 2 Dec 2025 11:19:20 +0100 Subject: [PATCH] Bug 38311: Fix Selenium and Cypress tests .dt-select-filter does no longer exist Here we rely on DT's API to retrieve the correct visible column index. However we cannot for Selenium tests, not ideal but it fixes the failure. Signed-off-by: Lucas Gass --- .../prog/en/includes/patron-search.inc | 14 ++-- .../KohaTable/PatronSearch_spec.ts | 68 +++++++++++++------ t/db_dependent/selenium/patrons_search.t | 3 +- 3 files changed, 60 insertions(+), 25 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc index 5e995e1f7d..d83f219dac 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc @@ -624,6 +624,7 @@ } [% CASE 'branch' %] { + name: "library", data: "library.name:me.library_id", dataFilter: "libraries", searchable: true, @@ -638,6 +639,7 @@ } [% CASE 'category' %] { + name: "category", data: "category_id", dataFilter: "categories", searchable: true, @@ -907,12 +909,16 @@ [% SWITCH c %] [% CASE 'branch' %] let library_id = patron_search_form.find(".branchcode_filter").val() || ""; - patrons_table.find('thead tr:eq(1) th[data-filter="libraries"] select').val('^' + library_id + '$'); - table_dt.column([% loop.count - 1 %]).search(library_id ? '^'+library_id+'$' : ''); + let library_column = table_dt.column('library:name'); + let library_visible_index = library_column.index("visible"); + patrons_table.find(`thead tr:eq(1) th:eq(${library_visible_index}) select`).val('^' + library_id + '$'); + library_column.search(library_id ? '^'+library_id+'$' : ''); [% CASE 'category' %] let category_id = patron_search_form.find(".categorycode_filter").val() || ""; - patrons_table.find('thead tr:eq(1) th[data-filter="categories"] select').val('^' + category_id.toLowerCase() + '$'); - table_dt.column([% loop.count - 1 %]).search(category_id ? '^'+category_id+'$' : ''); + let category_column = table_dt.column('category:name'); + let category_visible_index = category_column.index("visible"); + patrons_table.find(`thead tr:eq(1) th:eq(${category_visible_index}) select`).val('^' + category_id.toLowerCase() + '$'); + category_column.search(category_id ? '^'+category_id+'$' : ''); [% END %] [% END %] } diff --git a/t/cypress/integration/KohaTable/PatronSearch_spec.ts b/t/cypress/integration/KohaTable/PatronSearch_spec.ts index 92dd23c852..f1c9be33c2 100644 --- a/t/cypress/integration/KohaTable/PatronSearch_spec.ts +++ b/t/cypress/integration/KohaTable/PatronSearch_spec.ts @@ -159,25 +159,45 @@ describe("Filters", () => { `Showing 1 to ${RESTdefaultPageSize} of ${baseTotalCount} entries` ); - cy.get(`#${table_id} thead tr`).should("have.length", 2); + cy.get(`#${table_id}`).then($table => { + const dt = $table.DataTable(); + const libraryCol = dt.column("library:name"); + const libraryVisibleIndex = libraryCol.index("visible"); + const categoryCol = dt.column("category:name"); + const categoryVisibleIndex = categoryCol.index("visible"); - cy.get( - `#${table_id} thead tr th[data-filter='libraries'] select` - ).should("have.value", "^CPL$"); - // Lowercase see bug 32517 and related code in datatables.js - cy.get( - `#${table_id} thead tr th[data-filter='categories'] select` - ).should("have.value", "^s$"); + cy.get(`#${table_id} thead tr`).should("have.length", 2); + cy.get(`#${table_id} thead tr`) + .eq(1) + .find("th") + .eq(libraryVisibleIndex) + .find("select") + .should("have.value", "^CPL$"); - cy.get(`form.patron_search_form input.clear_search`).click(); - cy.get("form.patron_search_form input[type='submit']").click(); - cy.get( - `#${table_id} thead tr th[data-filter='libraries'] select` - ).should("have.value", null); - // Lowercase see bug 32517 and related code in datatables.js - cy.get( - `#${table_id} thead tr th[data-filter='categories'] select` - ).should("have.value", null); + // Lowercase see bug 32517 and related code in datatables.js + cy.get(`#${table_id} thead tr`) + .eq(1) + .find("th") + .eq(categoryVisibleIndex) + .find("select") + .should("have.value", "^s$"); + + cy.get(`form.patron_search_form input.clear_search`).click(); + cy.get("form.patron_search_form input[type='submit']").click(); + cy.get(`#${table_id} thead tr`) + .eq(1) + .find("th") + .eq(libraryVisibleIndex) + .find("select") + .should("have.value", null); + // Lowercase see bug 32517 and related code in datatables.js + cy.get(`#${table_id} thead tr`) + .eq(1) + .find("th") + .eq(categoryVisibleIndex) + .find("select") + .should("have.value", null); + }); }); }); @@ -257,9 +277,17 @@ describe("Filters", () => { cy.wait("@searchPatrons"); - cy.get( - `#${table_id} thead tr th[data-filter='libraries'] select` - ).select("^CPL$"); + cy.get(`#${table_id}`).then($table => { + const dt = $table.DataTable(); + const libraryCol = dt.column("library:name"); + const libraryVisibleIndex = libraryCol.index("visible"); + cy.get(`#${table_id} thead tr`) + .eq(1) + .find("th") + .eq(libraryVisibleIndex) + .find("select") + .select("^CPL$"); + }); cy.wait("@searchPatrons").then(interception => { const q = interception.request.query.q; diff --git a/t/db_dependent/selenium/patrons_search.t b/t/db_dependent/selenium/patrons_search.t index 095f2b476d..0ee86fe228 100755 --- a/t/db_dependent/selenium/patrons_search.t +++ b/t/db_dependent/selenium/patrons_search.t @@ -342,9 +342,10 @@ subtest 'Search patrons' => sub { 'Searching in standard brings back correct results' ); + # Not ideal as there are 2 select.dt-select-filter in the header (for library and category) $s->driver->find_element( '//table[@id="' . $table_id - . '"]//th[@data-filter="libraries"]/select/option[@value="^' + . '"]//th/select[@class="dt-select-filter"]/option[@value="^' . $first_patron->library->branchcode . '$"]' )->click; sleep $DT_delay && $s->wait_for_ajax;