Bugzilla – Attachment 176091 Details for
Bug 38461
Table features needs to be covered by e2e tests using Cypress
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 38461: Bypass the clipboard for tests
Bug-38461-Bypass-the-clipboard-for-tests.patch (text/plain), 8.81 KB, created by
Martin Renvoize (ashimema)
on 2025-01-02 16:19:04 UTC
(
hide
)
Description:
Bug 38461: Bypass the clipboard for tests
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2025-01-02 16:19:04 UTC
Size:
8.81 KB
patch
obsolete
>From 3d0da432010b95ff272ed7f5014828b4e00d1111 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Thu, 28 Nov 2024 12:23:36 +0100 >Subject: [PATCH] Bug 38461: Bypass the clipboard for tests > >There are known bugs with Cypress trying to play with the clipboard, and >I don't manage to make the tests pass consistently (also tried realClick >from cypress-real-events) > >Here I am suggesting to not click on the button, but simply retrieve the >url (which needs a bit of work in the existing code). > >We don't test the "Copied!" tooltip and the behaviour of the button, but >at least the tests pass! > >Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > .../prog/en/modules/admin/branches.tt | 3 +- > koha-tmpl/intranet-tmpl/prog/js/datatables.js | 25 +++-- > t/cypress/integration/KohaTable_spec.ts | 96 ++++++++----------- > 3 files changed, 59 insertions(+), 65 deletions(-) > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt >index cdf73a5b864..6c6ef20c66e 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt >@@ -656,10 +656,11 @@ > var table_settings = [% TablesSettings.GetTableSettings( 'admin', 'libraries', 'libraries', 'json' ) | $raw %]; > var calendarFirstDayOfWeek = '[% Koha.Preference('CalendarFirstDayOfWeek') | html %]'; > >+ var libraries_table; > $(document).ready(function() { > > var libraries_url = '/api/v1/libraries'; >- var libraries = $("#libraries").kohaTable({ >+ libraries_table = $("#libraries").kohaTable({ > "ajax": { > "url": libraries_url > }, >diff --git a/koha-tmpl/intranet-tmpl/prog/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/js/datatables.js >index 7e490300c42..4f6d0e22c08 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/datatables.js >@@ -595,6 +595,20 @@ function _dt_default_ajax (params){ > } > } > >+function build_url_with_state(dt, table_settings){ >+ let table_key = 'DataTables_%s_%s_%s'.format( >+ table_settings.module, >+ table_settings.page, >+ table_settings.table); >+ >+ let state = JSON.stringify(dt.state()); >+ delete state.time; >+ let searchParams = new URLSearchParams(window.location.search); >+ searchParams.set(table_key + '_state', btoa(state)); >+ >+ return window.location.origin + window.location.pathname + '?' + searchParams.toString() + window.location.hash; >+} >+ > function _dt_buttons(params){ > let settings = params.settings || {}; > let table_settings = params.table_settings; >@@ -723,17 +737,8 @@ function _dt_buttons(params){ > titleAttr: __("Copy shareable link"), > text: '<i class="fa fa-lg fa-copy"></i> <span class="dt-button-text">' + __("Copy shareable link") + '</span>', > action: function (e, dt, node, config) { >- let table_key = 'DataTables_%s_%s_%s'.format( >- table_settings.module, >- table_settings.page, >- table_settings.table); >- >- let state = JSON.stringify(dt.state()); >- delete state.time; >- let searchParams = new URLSearchParams(window.location.search); >- searchParams.set(table_key + '_state', btoa(state)); >+ const url = build_url_with_state(dt, table_settings); > >- let url = window.location.origin + window.location.pathname + '?' + searchParams.toString() + window.location.hash; > if( navigator.clipboard && navigator.clipboard.writeText){ > writeToClipboard(url, node); > } >diff --git a/t/cypress/integration/KohaTable_spec.ts b/t/cypress/integration/KohaTable_spec.ts >index a9b973be66a..6803edf9fa5 100644 >--- a/t/cypress/integration/KohaTable_spec.ts >+++ b/t/cypress/integration/KohaTable_spec.ts >@@ -264,65 +264,53 @@ describe("kohaTable (using REST API)", () => { > ); > cy.get(`#${table_id} th`).contains("Name"); > cy.get(`#${table_id} th`).contains("Code"); >- >- // 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 }); >- cy.get(".tooltip").contains("Copied!"); > }); > > cy.window().then(win => { >- // Retrieve the content of the clipboard >- win.navigator.clipboard.readText().then(url => { >- expect(url).to.match( >- /branches.pl\?DataTables_admin_libraries_libraries_state=/ >+ // Copy the shareable link (Name and Code shown) >+ const url = win.build_url_with_state( >+ win.libraries_table.DataTable(), >+ win.table_settings >+ ); >+ expect(url).to.match( >+ /branches.pl\?DataTables_admin_libraries_libraries_state=/ >+ ); >+ >+ // Remove localStorage >+ win.localStorage.clear(); >+ >+ // Use it >+ cy.visit(url); >+ >+ // Code is shown whereas it is hidden in the config >+ cy.get("@columns").then(columns => { >+ cy.get(`#${table_id} th`).should( >+ "have.length", >+ columns.length >+ ); >+ cy.get(`#${table_id} th`).contains("Name"); >+ cy.get(`#${table_id} th`).contains("Code"); >+ >+ // Hide "Name" >+ cy.get(`#${table_id}_wrapper .buttons-colvis`).click(); >+ cy.get(`#${table_id}_wrapper .dt-button-collection`) >+ .contains("Name") >+ .click(); >+ }); >+ >+ // Go to the shareable link >+ // but do not remove localStorage! >+ cy.visit(url); >+ >+ // Name is hidden and Code is shown >+ cy.get("@columns").then(columns => { >+ cy.get(`#${table_id} th`).should( >+ "have.length", >+ columns.length > ); > >- // Remove localStorage >- win.localStorage.clear(); >- >- // Use it >- cy.visit(url); >- >- // Code is shown whereas it is hidden in the config >- cy.get("@columns").then(columns => { >- cy.get(`#${table_id} th`).should( >- "have.length", >- columns.length >- ); >- cy.get(`#${table_id} th`).contains("Name"); >- cy.get(`#${table_id} th`).contains("Code"); >- >- // Hide "Name" >- cy.get( >- `#${table_id}_wrapper .buttons-colvis` >- ).click(); >- cy.get(`#${table_id}_wrapper .dt-button-collection`) >- .contains("Name") >- .click(); >- }); >- >- // Go to the shareable link >- // but do not remove localStorage! >- cy.visit(url); >- >- // Name is hidden and Code is shown >- cy.get("@columns").then(columns => { >- cy.get(`#${table_id} th`).should( >- "have.length", >- columns.length >- ); >- >- cy.get(`#${table_id} th`).contains("Name"); >- cy.get(`#${table_id} th`).contains("Code"); >- }); >+ cy.get(`#${table_id} th`).contains("Name"); >+ cy.get(`#${table_id} th`).contains("Code"); > }); > }); > }); >-- >2.47.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 38461
:
174877
|
174878
|
175004
|
175005
|
175006
|
175007
|
175008
|
175009
|
175010
|
175011
|
175015
|
175016
|
175179
|
175223
|
175224
|
175225
|
175226
|
175227
|
175228
|
175229
|
175230
|
175231
|
175232
|
175233
|
175234
|
175235
|
175289
|
175290
|
175291
|
175292
|
176082
|
176083
|
176084
|
176085
|
176086
|
176087
|
176088
|
176089
|
176090
| 176091 |
176092
|
176093
|
176793
|
176846
|
176902