From dee320da8aede4ec9fc4f46ecc28b8d3ab537904 Mon Sep 17 00:00:00 2001 From: Blesilda Ramirez Date: Tue, 7 Jan 2025 22:49:02 -0500 Subject: [PATCH] pkp/pkp-lib#9366 Resolve cypress issue with tinymce upgrade --- cypress/support/commands.js | 17 ++++++++++++----- cypress/support/commands_new_workflow.js | 17 ++++++++++++----- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 24766cf1d87..41e3e166a5c 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -13,10 +13,14 @@ import 'cypress-wait-until'; Cypress.Commands.add('setTinyMceContent', (tinyMceId, content) => { cy.window().then((win) => { - cy.waitUntil(() => win.tinymce?.editors[tinyMceId]?.initialized, {timeout: 10000}).then(() => { + let currentEditor; + cy.waitUntil(() => { + currentEditor = win.tinymce.get(tinyMceId); + return currentEditor?.initialized; + }, {timeout: 10000}).then(() => { // Clear any pre-existing content in the editor - const editor = win.tinymce.editors[tinyMceId].setContent(''); + currentEditor.setContent(''); // The .type() command does not accept an empty string, // so we simulate interaction with the field that leaves @@ -37,9 +41,12 @@ Cypress.Commands.add('setTinyMceContent', (tinyMceId, content) => { Cypress.Commands.add('getTinyMceContent', (tinyMceId, content) => { return cy.window().then((win) => { - return cy.waitUntil(() => win.tinymce?.editors[tinyMceId]?.initialized, {timeout: 10000}).then(() => { - const editor = win.tinymce.editors[tinyMceId]; - return editor.getContent(); + let currentEditor; + return cy.waitUntil(() => { + currentEditor = win.tinymce.get(tinyMceId); + return currentEditor?.initialized + }, {timeout: 10000}).then(() => { + return currentEditor.getContent(); }); }); }); diff --git a/cypress/support/commands_new_workflow.js b/cypress/support/commands_new_workflow.js index c2bf43b7d76..53ee4d3c633 100644 --- a/cypress/support/commands_new_workflow.js +++ b/cypress/support/commands_new_workflow.js @@ -14,10 +14,14 @@ import 'cypress-iframe' Cypress.Commands.add('setTinyMceContent', (tinyMceId, content) => { cy.window().then((win) => { - cy.waitUntil(() => win.tinymce?.editors[tinyMceId]?.initialized, {timeout: 10000}).then(() => { + let currentEditor; + cy.waitUntil(() => { + currentEditor = win.tinymce.get(tinyMceId); + return currentEditor?.initialized; + }, {timeout: 10000}).then(() => { // Clear any pre-existing content in the editor - const editor = win.tinymce.editors[tinyMceId].setContent(''); + currentEditor.setContent(''); // The .type() command does not accept an empty string, // so we simulate interaction with the field that leaves @@ -38,9 +42,12 @@ Cypress.Commands.add('setTinyMceContent', (tinyMceId, content) => { Cypress.Commands.add('getTinyMceContent', (tinyMceId, content) => { return cy.window().then((win) => { - return cy.waitUntil(() => win.tinymce?.editors[tinyMceId]?.initialized, {timeout: 10000}).then(() => { - const editor = win.tinymce.editors[tinyMceId]; - return editor.getContent(); + let currentEditor; + return cy.waitUntil(() => { + currentEditor = win.tinymce.get(tinyMceId); + return currentEditor?.initialized + }, {timeout: 10000}).then(() => { + return currentEditor.getContent(); }); }); });