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 <lucas@bywatersolutions.com>
This commit is contained in:
Jonathan Druart 2025-12-02 11:19:20 +01:00 committed by Lucas Gass
parent 87fb6f273a
commit f4d8525806
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
3 changed files with 60 additions and 25 deletions

View File

@ -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 %]
}

View File

@ -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;

View File

@ -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;