From c7175ee811ef562e1a349e67bd2a163d12e3e33a Mon Sep 17 00:00:00 2001 From: Sergey Kuzmich Date: Sun, 9 Feb 2025 16:55:58 +0100 Subject: [PATCH 1/4] refactor: Remove unnecessary wait statements --- cypress/e2e/inline-spoilers.cy.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/cypress/e2e/inline-spoilers.cy.js b/cypress/e2e/inline-spoilers.cy.js index 02e626c..0b864c2 100644 --- a/cypress/e2e/inline-spoilers.cy.js +++ b/cypress/e2e/inline-spoilers.cy.js @@ -44,10 +44,8 @@ describe('Inline Spoilers', () => { // Check spoiler behaviour cy.contains('Lorem ipsum dolor sit amet.').should('be.not.visible') cy.contains('The title').click() - cy.wait(300) cy.contains('Lorem ipsum dolor sit amet.').should('be.visible') cy.contains('The title').click() - cy.wait(300) cy.contains('Lorem ipsum dolor sit amet.').should('be.not.visible') }) @@ -101,23 +99,19 @@ describe('Inline Spoilers', () => { cy.contains(spoilers[1].content).should('be.not.visible') cy.contains(spoilers[0].title).click() - cy.wait(300) cy.contains(spoilers[0].content).should('be.visible') cy.contains(spoilers[1].content).should('be.not.visible') cy.contains(spoilers[0].title).click() - cy.wait(300) cy.contains(spoilers[0].content).should('be.not.visible') cy.contains(spoilers[1].content).should('be.not.visible') cy.contains(spoilers[0].title).click() cy.contains(spoilers[1].title).click() - cy.wait(300) cy.contains(spoilers[0].content).should('be.visible') cy.contains(spoilers[1].content).should('be.visible') cy.contains(spoilers[0].title).click() - cy.wait(300) cy.contains(spoilers[0].content).should('be.not.visible') cy.contains(spoilers[1].content).should('be.visible') }) From 17e4999fd0feef50c2fabca4b133fadce075f4b6 Mon Sep 17 00:00:00 2001 From: Sergey Kuzmich Date: Sun, 9 Feb 2025 17:38:21 +0100 Subject: [PATCH 2/4] refactor: Streamline command functions and remove deprecated code --- cypress/e2e/wordpress.cy.js | 1 + cypress/support/commands.js | 25 +------------------------ 2 files changed, 2 insertions(+), 24 deletions(-) diff --git a/cypress/e2e/wordpress.cy.js b/cypress/e2e/wordpress.cy.js index 0b70bcf..f39025a 100644 --- a/cypress/e2e/wordpress.cy.js +++ b/cypress/e2e/wordpress.cy.js @@ -11,5 +11,6 @@ describe('WordPress', () => { it('credentials are valid', () => { cy.login() + cy.contains('Howdy, wordpress') }) }) diff --git a/cypress/support/commands.js b/cypress/support/commands.js index c1b76a4..fb9a362 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -32,7 +32,6 @@ Cypress.Commands.add('login', (username='wordpress', password='wpassword') => { cy.get('input[name=log]').type(username) cy.get('input[name=pwd]').type(password) cy.get('input[name=wp-submit]').click() - cy.contains('Howdy, wordpress') }); cy.visit('/wp-admin') }) @@ -45,14 +44,6 @@ Cypress.Commands.add('logout', () => { cy.get('[name=loginform]').should('exist') }) -Cypress.Commands.add('logout', () => { - cy.visit('/wp-admin') - cy.contains('Howdy, wordpress') - cy.get('[class="menupop with-avatar"] [class="ab-sub-wrapper"]').invoke('show') - cy.get('[id=wp-admin-bar-logout] a').click() - cy.get('[name=loginform]').should('exist') -}) - Cypress.Commands.add('open_new_post_page', () => { cy.get('li[id=menu-posts]').click() cy.get('a[class=page-title-action]').contains('Add New').click() @@ -61,23 +52,9 @@ Cypress.Commands.add('open_new_post_page', () => { }) Cypress.Commands.add('supress_guttenberg_wizzard', () => { - - // WordPress 5.2 throws exception `Failed to execute 'send' on 'XMLHttpRequest'` - // when you're leaving `Add New` page with unsaved changes prompt - Cypress.env('WP_CORE') == 5.2 && Cypress.on('uncaught:exception', (popup) => { - return false - }) - // Wait wizzard popup animation Cypress.env('WP_CORE') >= 5.4 && cy.wait(1500) - - // 5.0 ... 5.3 - cy.get('body').then((body) => { - let popover = body.find('[class*=nux-dot-tip]'); - popover.length && cy.get('[class*=nux-dot-tip__disable]').click() - }) - - // 5.4 ... 6.3 + cy.get('body').then((body) => { let popover = body.find('[class*=edit-post-welcome-guide]'); popover.length && cy.get('[class*=edit-post-welcome-guide] [class*=components-modal__header] [class*=components-button]').click() From c57edd1d530d246aa21a4aaa7a3de3e2cd9fe25c Mon Sep 17 00:00:00 2001 From: Sergey Kuzmich Date: Sun, 9 Feb 2025 17:38:45 +0100 Subject: [PATCH 3/4] feat(tests): Update inline spoilers test for dynamic content --- cypress/e2e/inline-spoilers.cy.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/cypress/e2e/inline-spoilers.cy.js b/cypress/e2e/inline-spoilers.cy.js index 0b864c2..7103be9 100644 --- a/cypress/e2e/inline-spoilers.cy.js +++ b/cypress/e2e/inline-spoilers.cy.js @@ -19,6 +19,11 @@ describe('Inline Spoilers', () => { }) it('can be added with guttenberg', () => { + const spoiler = { + title: 'The orpan', + content: 'Phasellus tempor tellus quis felis dignissim, a elementum purus malesuada.' + } + cy.open_new_post_page() // Create post with spoiler @@ -26,13 +31,13 @@ describe('Inline Spoilers', () => { cy.get('div[class*=edit-post-header] button[class*=inserter][class*=toggle]') .click() cy.get('[class*=editor-inserter__menu] input[type=search]').type('inline') - cy.get('[class*=editor-block-list-item-inline-spoilers-block').click() - Cypress.env('WP_CORE') > 5.4 && cy.get('div[class*=edit-post-header] button[class*=inserter][class*=toggle]') + cy.get('[class*=editor-block-list-item-inline-spoilers-block]').click() + cy.get('div[class*=edit-post-header] button[class*=inserter][class*=toggle]') .click() cy.get('[class=wp-block-inline-spoilers-block] [class=spoiler-title]') - .type('The title') + .type(spoiler.title) cy.get('[class=wp-block-inline-spoilers-block] [class=spoiler-content] [role=textbox]') - .type('Lorem ipsum dolor sit amet.') + .type(spoiler.content) cy.get('[class*=edit-post-header] [class*=editor-post-publish]').click() cy.get('[class*=editor-post-publish-panel] [class*=editor-post-publish-button]') .click() @@ -42,11 +47,11 @@ describe('Inline Spoilers', () => { .click() // Check spoiler behaviour - cy.contains('Lorem ipsum dolor sit amet.').should('be.not.visible') - cy.contains('The title').click() - cy.contains('Lorem ipsum dolor sit amet.').should('be.visible') - cy.contains('The title').click() - cy.contains('Lorem ipsum dolor sit amet.').should('be.not.visible') + cy.contains(spoiler.content).should('be.not.visible') + cy.contains(spoiler.title).click() + cy.contains(spoiler.content).should('be.visible') + cy.contains(spoiler.title).click() + cy.contains(spoiler.content).should('be.not.visible') }) it('can be added multiple times', () => { From 725951c190a3063604389bd11995f615fe7a4e8d Mon Sep 17 00:00:00 2001 From: Sergey Kuzmich Date: Sun, 9 Feb 2025 19:07:07 +0100 Subject: [PATCH 4/4] feat(tests): update inline spoilers tests to cover shortcode scenario --- cypress/e2e/inline-spoilers.cy.js | 78 +++++++++++++++++++------------ 1 file changed, 47 insertions(+), 31 deletions(-) diff --git a/cypress/e2e/inline-spoilers.cy.js b/cypress/e2e/inline-spoilers.cy.js index 7103be9..3b14b5f 100644 --- a/cypress/e2e/inline-spoilers.cy.js +++ b/cypress/e2e/inline-spoilers.cy.js @@ -18,10 +18,39 @@ describe('Inline Spoilers', () => { .should('be.visible') }) - it('can be added with guttenberg', () => { + it('can be added with shortcode', () => { const spoiler = { - title: 'The orpan', - content: 'Phasellus tempor tellus quis felis dignissim, a elementum purus malesuada.' + title: 'Who Survives in the Final Episode? 🎬', + content: 'Against all odds, the main character fakes their death and escapes to another country.' + } + + cy.open_new_post_page() + + // Create post with spoiler + cy.get('[class*=editor-post-title__input]').type('Shortcode Spoiler') + cy.get('p[class*=block-editor-default-block-appender]').click() + cy.get('p[class*=block-editor-rich-text__editable]').last().focus() + .type(`[spoiler title="${spoiler.title}"]${spoiler.content}[/spoiler]{esc}`) + + cy.get('[class*=edit-post-header] [class*=editor-post-publish]').click() + cy.get('[class*=editor-post-publish-panel] [class*=editor-post-publish-button]') + .click() + + // Preview the post + cy.contains('View Post').click() + + // Check spoiler behaviour + cy.contains(spoiler.content).should('be.not.visible') + cy.contains(spoiler.title).click() + cy.contains(spoiler.content).should('be.visible') + cy.contains(spoiler.title).click() + cy.contains(spoiler.content).should('be.not.visible') + }) + + it('can be added with Guttenberg', () => { + const spoiler = { + title: 'The Secret Ingredient in Grandma’s Cookies 🍪', + content: 'It’s actually a pinch of cinnamon! That’s what makes them so special.' } cy.open_new_post_page() @@ -43,8 +72,7 @@ describe('Inline Spoilers', () => { .click() // Preview the post - cy.contains('View Post') - .click() + cy.contains('View Post').click() // Check spoiler behaviour cy.contains(spoiler.content).should('be.not.visible') @@ -56,48 +84,36 @@ describe('Inline Spoilers', () => { it('can be added multiple times', () => { const spoilers = [{ - title: 'The first one', - content: 'Etiam augue urna, ullamcorper dapibus ex quis, elementum tristique libero.' + title: 'Hidden Feature in Our New App Update 📱', + content: 'You can now double-tap the logo in the settings to unlock a dark mode easter egg!' },{ - title: 'The second spoilier', - content: 'Phasellus nec turpis semper, fermentum magna ut, lobortis lacus.' + title: 'Unexpected Plot Twist in the Latest Mystery Novel 📖', + content: 'The detective was the real culprit all along, covering up their own crimes!' }] cy.open_new_post_page() // Create post with spoiler cy.get('[class*=editor-post-title__input]').type('Multiple Spoilers') - cy.get('div[class*=edit-post-header] button[class*=inserter][class*=toggle]') + for(const spoiler of spoilers) { + cy.get('div[class*=edit-post-header] button[class*=inserter][class*=toggle]') .click() - cy.get('[class*=editor-inserter__menu] input[type=search]').type('inline') - cy.get('[class*=editor-block-list-item-inline-spoilers-block').click() - Cypress.env('WP_CORE') > 5.4 && cy.get('div[class*=edit-post-header] button[class*=inserter][class*=toggle]') + cy.get('[class*=editor-inserter__menu] input[type=search]').type('inline') + cy.get('[class*=editor-block-list-item-inline-spoilers-block').click() + cy.get('div[class*=edit-post-header] button[class*=inserter][class*=toggle]') .click() - cy.get('[class=wp-block-inline-spoilers-block] [class=spoiler-title]') - .type(spoilers[0].title) + cy.get('[class=wp-block-inline-spoilers-block] [class=spoiler-title]') + .last().type(spoiler.title) cy.get('[class=wp-block-inline-spoilers-block] [class=spoiler-content] [role=textbox]') - .type(spoilers[0].content) - - cy.get('div[class*=edit-post-header] button[class*=inserter][class*=toggle]') - .click() - cy.get('[class*=editor-inserter__menu] input[type=search]').type('inline') - cy.get('[class*=editor-block-list-item-inline-spoilers-block').click() - Cypress.env('WP_CORE') > 5.4 && cy.get('div[class*=edit-post-header] button[class*=inserter][class*=toggle]') - .click() - cy.get('[class=wp-block-inline-spoilers-block] [class=spoiler-title]') - .last() - .type(spoilers[1].title) - cy.get('[class=wp-block-inline-spoilers-block] [class=spoiler-content] [role=textbox]') - .last() - .type(spoilers[1].content) + .last().type(spoiler.content) + } cy.get('[class*=edit-post-header] [class*=editor-post-publish]').click() cy.get('[class*=editor-post-publish-panel] [class*=editor-post-publish-button]') .click() // Preview the post - cy.contains('View Post') - .click() + cy.contains('View Post').click() // Check spoilers behaviour cy.contains(spoilers[0].content).should('be.not.visible')