From 950d40ab6d5d6be8cdf1436d230ac948e92bead9 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 21 May 2025 13:24:16 -0300 Subject: [PATCH] [24.11.x] Bug 38461: (follow-up) Fix tests This patch does two things: * Fixes a backport issue with 38461, making `mock_table_settings` have the right function signature, and accept (and use) the `table_settings_var` parameter. * Makes the scope for the `items_table_settings` variable be the window object, so it is accessible to Cypress for manipulation/mocking. This is done by changing `let` for `var` [1] To test: 1. Run: $ ktd --shell k$ run_cypress --spec t/cypress/integration/KohaTable_spec.ts => FAIL: Tests fail! 2. Apply this patch 3. Repeat 1 => SUCCESS: Tests pass! 4. Sign off :-D [1] If you are curious about it, change it back to `let` and run the tests. Signed-off-by: Tomas Cohen Arazi --- .../tables/items/catalogue_detail.inc | 2 +- t/cypress/integration/KohaTable_spec.ts | 20 +++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers/tables/items/catalogue_detail.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers/tables/items/catalogue_detail.inc index 33117e6cf91..4e82a829656 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers/tables/items/catalogue_detail.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers/tables/items/catalogue_detail.inc @@ -270,7 +270,7 @@ embed.push('analytics_count'); [% END %] - let items_table_settings = { + var items_table_settings = { holdings: [% TablesSettings.GetTableSettings('catalogue', 'detail','holdings_table','json') | $raw %], otherholdings: [% TablesSettings.GetTableSettings('catalogue', 'detail','otherholdings_table','json') | $raw %], }; diff --git a/t/cypress/integration/KohaTable_spec.ts b/t/cypress/integration/KohaTable_spec.ts index 009f9ae15d9..6ef44095d73 100644 --- a/t/cypress/integration/KohaTable_spec.ts +++ b/t/cypress/integration/KohaTable_spec.ts @@ -22,24 +22,32 @@ function build_libraries() { }); } -function mock_table_settings(settings) { +function mock_table_settings(settings, table_settings_var) { cy.window().then(win => { - win.table_settings.columns = win.table_settings.columns.map(c => ({ + + let table_settings = + typeof table_settings_var === "undefined" + ? win.table_settings + : table_settings_var + .split(".") + .reduce((acc, key) => acc[key], win); + + table_settings.columns = table_settings.columns.map(c => ({ ...c, is_hidden: 0, cannot_be_toggled: 0, })); if (settings && settings.hasOwnProperty("default_save_state")) { - win.table_settings.default_save_state = settings.default_save_state; + table_settings.default_save_state = settings.default_save_state; } if (settings && settings.hasOwnProperty("default_save_state_search")) { - win.table_settings.default_save_state_search = + table_settings.default_save_state_search = settings.default_save_state_search; } if (settings && settings.columns) { Object.entries(settings.columns).forEach(([name, values]) => { - let column = win.table_settings.columns.find( + let column = table_settings.columns.find( cc => cc.columnname == name ); Object.entries(values).forEach(([prop, value]) => { @@ -47,7 +55,7 @@ function mock_table_settings(settings) { }); }); } - cy.wrap(win.table_settings.columns).as("columns"); + cy.wrap(table_settings.columns).as("columns"); }); } describe("kohaTable (using REST API)", () => { -- 2.49.0