From 5f3314c6da595b4a0059dfea0723e11ff8cc4c11 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 28 Nov 2024 11:25:03 +0100 Subject: [PATCH] Bug 38461: Fix ramdom failures All this is weird. I found this an implemented it: https://stackoverflow.com/questions/69425289/javascript-prompt-cause-document-is-not-focused It was still not enough for reduced the failures. The wait and adding the focus to the window seems ok. If I remove one of those 3 hacks, I still get failures... --- koha-tmpl/intranet-tmpl/prog/js/datatables.js | 8 ++++++-- t/cypress/integration/KohaTable_spec.ts | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/js/datatables.js index bf3be9c64fe..1fd348d9336 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js +++ b/koha-tmpl/intranet-tmpl/prog/js/datatables.js @@ -711,6 +711,10 @@ function _dt_buttons(params){ ); if ( table_settings ) { + const writeToClipboard= async (text, node) => { + await navigator.clipboard.writeText(text); + $(node).tooltip({trigger: 'manual', title: __("Copied!")}).tooltip('show'); + }; buttons.push( { autoClose: true, @@ -728,10 +732,10 @@ function _dt_buttons(params){ delete state.time; let searchParams = new URLSearchParams(window.location.search); searchParams.set(table_key + '_state', btoa(state)); + let url = window.location.origin + window.location.pathname + '?' + searchParams.toString() + window.location.hash; if( navigator.clipboard && navigator.clipboard.writeText){ - navigator.clipboard.writeText( url ); - $(node).tooltip({trigger: 'manual', title: __("Copied!")}).tooltip('show'); + writeToClipboard(url, node); } }, } diff --git a/t/cypress/integration/KohaTable_spec.ts b/t/cypress/integration/KohaTable_spec.ts index 48364401d86..a9b973be66a 100644 --- a/t/cypress/integration/KohaTable_spec.ts +++ b/t/cypress/integration/KohaTable_spec.ts @@ -268,8 +268,10 @@ describe("kohaTable (using REST API)", () => { // Close the 'Columns' list cy.get(".dt-button-background").click(); cy.get(".dt-button-background").should("not.exist"); + cy.wait(500); // ensure the animation completes, random failures? // Copy the shareable link (Name and Code shown) + cy.window().focus(); cy.get( `#${table_id}_wrapper .copyConditions_controls` ).click({ force: true }); -- 2.34.1