From f66df8872784a458144a2d60d069103330d3bfc9 Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Tue, 16 Apr 2024 15:40:46 -0600 Subject: [PATCH 1/2] Update cypress-wp-utils to 0.3.0 --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1b317cb27..2582773cd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,7 @@ "tippy.js": "^6.3.7" }, "devDependencies": { - "@10up/cypress-wp-utils": "^0.2.0", + "@10up/cypress-wp-utils": "^0.3.0", "@wordpress/env": "^9.4.0", "@wordpress/scripts": "^27.3.0", "cypress": "^13.6.4", @@ -32,9 +32,9 @@ } }, "node_modules/@10up/cypress-wp-utils": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/@10up/cypress-wp-utils/-/cypress-wp-utils-0.2.0.tgz", - "integrity": "sha512-5gzamtHIFojT+wx0OzSAEeVY6FVrlcVPHVFH23uExkaqQhNsJvrnpdtqtT98wAYkXg56c1qDN7Ju7ZRTaNzP5g==", + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/@10up/cypress-wp-utils/-/cypress-wp-utils-0.3.0.tgz", + "integrity": "sha512-iMjvca50TerMCY9M9vL0FIE+80ye5YohaQp3XvhgUgQdc4LS51X2fH+lhdb0uRmBTiUQcISazEvWGJxV7DeTbw==", "dev": true, "engines": { "node": ">=12.0" diff --git a/package.json b/package.json index b82e15565..2ae83d65e 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "role": "developer" }, "devDependencies": { - "@10up/cypress-wp-utils": "^0.2.0", + "@10up/cypress-wp-utils": "^0.3.0", "@wordpress/env": "^9.4.0", "@wordpress/scripts": "^27.3.0", "cypress": "^13.6.4", From 2bb336657fa54c33ada6bd0e5c8a4f14b859790a Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Tue, 16 Apr 2024 15:41:11 -0600 Subject: [PATCH 2/2] Remove a couple custom commands and instead use the ones in the Cypress WP Utils package --- .../image-generation-openai-dalle.test.js | 2 +- .../classify-content-ibm-watson.test.js | 14 +-- ...lassify-content-openapi-embeddings.test.js | 6 +- .../excerpt-generation-azure-openai.test.js | 4 +- ...rpt-generation-googleai-gemini-api.test.js | 4 +- ...excerpt-generation-openapi-chatgpt.test.js | 6 +- .../text-to-speech-amazon-polly.test.js | 4 +- .../text-to-speech-microsoft-azure.test.js | 4 +- ...xt-to-speech-openai-text-to-speech.test.js | 4 +- .../title-generation-azure-openai.test.js | 2 +- ...tle-generation-googleai-gemini-api.test.js | 2 +- .../title-generation-openapi-chatgpt.test.js | 4 +- tests/cypress/support/commands.js | 90 ------------------- 13 files changed, 28 insertions(+), 118 deletions(-) diff --git a/tests/cypress/integration/image-processing/image-generation-openai-dalle.test.js b/tests/cypress/integration/image-processing/image-generation-openai-dalle.test.js index bd19fbf27..f55bd7680 100644 --- a/tests/cypress/integration/image-processing/image-generation-openai-dalle.test.js +++ b/tests/cypress/integration/image-processing/image-generation-openai-dalle.test.js @@ -57,7 +57,7 @@ describe( 'Image Generation (OpenAI DALLĀ·E) Tests', () => { } ); // Open post settings sidebar. - cy.openDocumentSettingsSidebarCustom(); + cy.openDocumentSettingsSidebar(); // Find and open the Featured image panel. const panelButtonSelector = `.components-panel__body .components-panel__body-title button:contains("Featured image")`; diff --git a/tests/cypress/integration/language-processing/classify-content-ibm-watson.test.js b/tests/cypress/integration/language-processing/classify-content-ibm-watson.test.js index bd715c7e0..578b153da 100644 --- a/tests/cypress/integration/language-processing/classify-content-ibm-watson.test.js +++ b/tests/cypress/integration/language-processing/classify-content-ibm-watson.test.js @@ -125,7 +125,7 @@ describe( '[Language processing] Classify content (IBM Watson - NLU) Tests', () } ); // Open post settings sidebar - cy.openDocumentSettingsSidebarCustom(); + cy.openDocumentSettingsSidebar(); // Open Panel const panelButtonSelector = `.components-panel__body .components-panel__body-title button:contains("ClassifAI")`; @@ -214,7 +214,7 @@ describe( '[Language processing] Classify content (IBM Watson - NLU) Tests', () } ); // Open post settings sidebar - cy.openDocumentSettingsSidebarCustom(); + cy.openDocumentSettingsSidebar(); // Open Panel const panelButtonSelector = `.components-panel__body .components-panel__body-title button:contains("ClassifAI")`; @@ -253,7 +253,7 @@ describe( '[Language processing] Classify content (IBM Watson - NLU) Tests', () } ); // Open post settings sidebar - cy.openDocumentSettingsSidebarCustom(); + cy.openDocumentSettingsSidebar(); // Verify Each Created taxonomies. [ 'categories', 'keywords', 'concepts', 'entities' ].forEach( @@ -292,7 +292,7 @@ describe( '[Language processing] Classify content (IBM Watson - NLU) Tests', () } ); // Open post settings sidebar - cy.openDocumentSettingsSidebarCustom(); + cy.openDocumentSettingsSidebar(); // Verify Each Created taxonomies. [ 'categories', 'keywords', 'concepts', 'entities' ].forEach( @@ -340,7 +340,7 @@ describe( '[Language processing] Classify content (IBM Watson - NLU) Tests', () } ); // Open post settings sidebar - cy.openDocumentSettingsSidebarCustom(); + cy.openDocumentSettingsSidebar(); // Verify Each Created taxonomies with threshold 75. [ 'categories', 'keywords', 'concepts', 'entities' ].forEach( @@ -381,7 +381,7 @@ describe( '[Language processing] Classify content (IBM Watson - NLU) Tests', () } ); // Open post settings sidebar - cy.openDocumentSettingsSidebarCustom(); + cy.openDocumentSettingsSidebar(); // Verify Each Created taxonomies with threshold 75 as we have already created terms with threshold 75. So, those are existing terms. [ 'categories', 'keywords', 'concepts', 'entities' ].forEach( @@ -435,7 +435,7 @@ describe( '[Language processing] Classify content (IBM Watson - NLU) Tests', () } ); // Open post settings sidebar - cy.openDocumentSettingsSidebarCustom(); + cy.openDocumentSettingsSidebar(); // Verify Each Created taxonomies. cy.verifyPostTaxonomyTerms( 'tags', threshold / 100 ); diff --git a/tests/cypress/integration/language-processing/classify-content-openapi-embeddings.test.js b/tests/cypress/integration/language-processing/classify-content-openapi-embeddings.test.js index 7589784f9..127e14771 100644 --- a/tests/cypress/integration/language-processing/classify-content-openapi-embeddings.test.js +++ b/tests/cypress/integration/language-processing/classify-content-openapi-embeddings.test.js @@ -51,7 +51,7 @@ describe( '[Language processing] Classify Content (OpenAI) Tests', () => { } ); // Open post settings sidebar. - cy.openDocumentSettingsSidebarCustom(); + cy.openDocumentSettingsSidebar(); // Find and open the category panel. const panelButtonSelector = `.components-panel__body .components-panel__body-title button:contains("Categories")`; @@ -119,7 +119,7 @@ describe( '[Language processing] Classify Content (OpenAI) Tests', () => { } ); // Open post settings sidebar. - cy.openDocumentSettingsSidebarCustom(); + cy.openDocumentSettingsSidebar(); // Find and open the category panel. const panelButtonSelector = `.components-panel__body .components-panel__body-title button:contains("Categories")`; @@ -162,7 +162,7 @@ describe( '[Language processing] Classify Content (OpenAI) Tests', () => { cy.get( '#category' ).check(); cy.get( '#submit' ).click(); - cy.createClassicPost( { + cy.classicCreatePost( { title: 'Embeddings test classic', content: "This feature uses OpenAI's Embeddings capabilities.", postType: 'post', diff --git a/tests/cypress/integration/language-processing/excerpt-generation-azure-openai.test.js b/tests/cypress/integration/language-processing/excerpt-generation-azure-openai.test.js index f7f9c54e3..d01786ea2 100644 --- a/tests/cypress/integration/language-processing/excerpt-generation-azure-openai.test.js +++ b/tests/cypress/integration/language-processing/excerpt-generation-azure-openai.test.js @@ -70,7 +70,7 @@ describe( '[Language processing] Excerpt Generation Tests', () => { } ); // Open post settings sidebar. - cy.openDocumentSettingsSidebarCustom(); + cy.openDocumentSettingsSidebar(); // Find and open the excerpt panel. const panelButtonSelector = `.components-panel__body .components-panel__body-title button:contains("Excerpt")`; @@ -106,7 +106,7 @@ describe( '[Language processing] Excerpt Generation Tests', () => { const data = getChatGPTData(); - cy.createClassicPost( { + cy.classicCreatePost( { title: 'Excerpt test classic', content: 'Test GPT content.', postType: 'post', diff --git a/tests/cypress/integration/language-processing/excerpt-generation-googleai-gemini-api.test.js b/tests/cypress/integration/language-processing/excerpt-generation-googleai-gemini-api.test.js index ee2563294..07555d6ad 100644 --- a/tests/cypress/integration/language-processing/excerpt-generation-googleai-gemini-api.test.js +++ b/tests/cypress/integration/language-processing/excerpt-generation-googleai-gemini-api.test.js @@ -59,7 +59,7 @@ describe( '[Language processing] Excerpt Generation Tests', () => { } ); // Open post settings sidebar. - cy.openDocumentSettingsSidebarCustom(); + cy.openDocumentSettingsSidebar(); // Find and open the excerpt panel. const panelButtonSelector = `.components-panel__body .components-panel__body-title button:contains("Excerpt")`; @@ -95,7 +95,7 @@ describe( '[Language processing] Excerpt Generation Tests', () => { const data = getGeminiAPIData(); - cy.createClassicPost( { + cy.classicCreatePost( { title: 'Excerpt test classic', content: 'Test GPT content.', postType: 'post', diff --git a/tests/cypress/integration/language-processing/excerpt-generation-openapi-chatgpt.test.js b/tests/cypress/integration/language-processing/excerpt-generation-openapi-chatgpt.test.js index 1de34549c..335e60353 100644 --- a/tests/cypress/integration/language-processing/excerpt-generation-openapi-chatgpt.test.js +++ b/tests/cypress/integration/language-processing/excerpt-generation-openapi-chatgpt.test.js @@ -56,7 +56,7 @@ describe( '[Language processing] Excerpt Generation Tests', () => { } ); // Open post settings sidebar. - cy.openDocumentSettingsSidebarCustom(); + cy.openDocumentSettingsSidebar(); // Find and open the excerpt panel. const panelButtonSelector = `.components-panel__body .components-panel__body-title button:contains("Excerpt")`; @@ -92,7 +92,7 @@ describe( '[Language processing] Excerpt Generation Tests', () => { const data = getChatGPTData(); - cy.createClassicPost( { + cy.classicCreatePost( { title: 'Excerpt test classic', content: 'Test GPT content.', postType: 'post', @@ -212,7 +212,7 @@ describe( '[Language processing] Excerpt Generation Tests', () => { } ); // Open post settings sidebar. - cy.openDocumentSettingsSidebarCustom(); + cy.openDocumentSettingsSidebar(); // Find and open the excerpt panel. const panelButtonSelector = `.components-panel__body .components-panel__body-title button:contains("Excerpt")`; diff --git a/tests/cypress/integration/language-processing/text-to-speech-amazon-polly.test.js b/tests/cypress/integration/language-processing/text-to-speech-amazon-polly.test.js index 2de8bdab7..0ce9b95bc 100644 --- a/tests/cypress/integration/language-processing/text-to-speech-amazon-polly.test.js +++ b/tests/cypress/integration/language-processing/text-to-speech-amazon-polly.test.js @@ -35,7 +35,7 @@ describe( '[Language Processing] Text to Speech (Amazon Polly) Tests', () => { } ); cy.get( 'button[aria-label="Close panel"]' ).click(); - cy.openDocumentSettingsSidebarCustom(); + cy.openDocumentSettingsSidebar(); cy.get( '.classifai-panel' ).click(); cy.get( '#classifai-audio-controls__preview-btn' ).should( 'exist' ); } ); @@ -97,7 +97,7 @@ describe( '[Language Processing] Text to Speech (Amazon Polly) Tests', () => { it( 'Can see the enable button in a post (Classic Editor)', () => { cy.enableClassicEditor(); - cy.createClassicPost( { + cy.classicCreatePost( { title: 'Text to Speech test classic', content: "This feature uses Amazon Polly's Text to Speech capabilities.", diff --git a/tests/cypress/integration/language-processing/text-to-speech-microsoft-azure.test.js b/tests/cypress/integration/language-processing/text-to-speech-microsoft-azure.test.js index ec776de3d..f351ecebc 100644 --- a/tests/cypress/integration/language-processing/text-to-speech-microsoft-azure.test.js +++ b/tests/cypress/integration/language-processing/text-to-speech-microsoft-azure.test.js @@ -35,7 +35,7 @@ describe( '[Language Processing] Text to Speech (Microsoft Azure) Tests', () => } ); cy.get( 'button[aria-label="Close panel"]' ).click(); - cy.openDocumentSettingsSidebarCustom(); + cy.openDocumentSettingsSidebar(); cy.get( '.classifai-panel' ).click(); cy.get( '#classifai-audio-controls__preview-btn' ).should( 'exist' ); } ); @@ -97,7 +97,7 @@ describe( '[Language Processing] Text to Speech (Microsoft Azure) Tests', () => it( 'Can see the enable button in a post (Classic Editor)', () => { cy.enableClassicEditor(); - cy.createClassicPost( { + cy.classicCreatePost( { title: 'Text to Speech test classic', content: "This feature uses Microsoft's Text to Speech capabilities.", diff --git a/tests/cypress/integration/language-processing/text-to-speech-openai-text-to-speech.test.js b/tests/cypress/integration/language-processing/text-to-speech-openai-text-to-speech.test.js index 858293bf8..1d6a85bf8 100644 --- a/tests/cypress/integration/language-processing/text-to-speech-openai-text-to-speech.test.js +++ b/tests/cypress/integration/language-processing/text-to-speech-openai-text-to-speech.test.js @@ -30,7 +30,7 @@ describe( '[Language Processing] Text to Speech (OpenAI) Tests', () => { } ); cy.get( 'button[aria-label="Close panel"]' ).click(); - cy.openDocumentSettingsSidebarCustom(); + cy.openDocumentSettingsSidebar(); cy.get( '.classifai-panel' ).click(); cy.get( '#classifai-audio-controls__preview-btn' ).should( 'exist' ); } ); @@ -92,7 +92,7 @@ describe( '[Language Processing] Text to Speech (OpenAI) Tests', () => { it( 'Can see the enable button in a post (Classic Editor)', () => { cy.enableClassicEditor(); - cy.createClassicPost( { + cy.classicCreatePost( { title: 'Text to Speech test classic', content: "This feature uses OpenAI's Text to Speech capabilities.", postType: 'post', diff --git a/tests/cypress/integration/language-processing/title-generation-azure-openai.test.js b/tests/cypress/integration/language-processing/title-generation-azure-openai.test.js index 8cc538763..477e20b12 100644 --- a/tests/cypress/integration/language-processing/title-generation-azure-openai.test.js +++ b/tests/cypress/integration/language-processing/title-generation-azure-openai.test.js @@ -63,7 +63,7 @@ describe( '[Language processing] Title Generation Tests', () => { } ); // Open post settings sidebar. - cy.openDocumentSettingsSidebarCustom(); + cy.openDocumentSettingsSidebar(); // Find and open the summary panel. const panelButtonSelector = `.components-panel__body.edit-post-post-status .components-panel__body-title button`; diff --git a/tests/cypress/integration/language-processing/title-generation-googleai-gemini-api.test.js b/tests/cypress/integration/language-processing/title-generation-googleai-gemini-api.test.js index 6b097b83a..2d44f6bbf 100644 --- a/tests/cypress/integration/language-processing/title-generation-googleai-gemini-api.test.js +++ b/tests/cypress/integration/language-processing/title-generation-googleai-gemini-api.test.js @@ -47,7 +47,7 @@ describe( '[Language processing] Title Generation Tests', () => { } ); // Open post settings sidebar. - cy.openDocumentSettingsSidebarCustom(); + cy.openDocumentSettingsSidebar(); // Find and open the summary panel. const panelButtonSelector = `.components-panel__body.edit-post-post-status .components-panel__body-title button`; diff --git a/tests/cypress/integration/language-processing/title-generation-openapi-chatgpt.test.js b/tests/cypress/integration/language-processing/title-generation-openapi-chatgpt.test.js index 3970b0678..7c7419b66 100644 --- a/tests/cypress/integration/language-processing/title-generation-openapi-chatgpt.test.js +++ b/tests/cypress/integration/language-processing/title-generation-openapi-chatgpt.test.js @@ -44,7 +44,7 @@ describe( '[Language processing] Title Generation Tests', () => { } ); // Open post settings sidebar. - cy.openDocumentSettingsSidebarCustom(); + cy.openDocumentSettingsSidebar(); // Find and open the summary panel. const panelButtonSelector = `.components-panel__body.edit-post-post-status .components-panel__body-title button`; @@ -215,7 +215,7 @@ describe( '[Language processing] Title Generation Tests', () => { } ); // Open post settings sidebar. - cy.openDocumentSettingsSidebarCustom(); + cy.openDocumentSettingsSidebar(); // Find and open the summary panel. const panelButtonSelector = `.components-panel__body.edit-post-post-status .components-panel__body-title button`; diff --git a/tests/cypress/support/commands.js b/tests/cypress/support/commands.js index 7fed9bc31..2fd59d4ee 100644 --- a/tests/cypress/support/commands.js +++ b/tests/cypress/support/commands.js @@ -523,93 +523,3 @@ Cypress.Commands.add( 'enableClassicEditor', () => { } } ); } ); - -Cypress.Commands.add( - 'createClassicPost', - ( { - postType = 'post', - title = 'Test Post', - content = 'Test content', - status = 'publish', - beforeSave, - } ) => { - cy.visit( `/wp-admin/post-new.php?post_type=${ postType }` ); - - cy.get( '#title' ).click().clear().type( title ); - - cy.get( '#content_ifr' ).then( ( $iframe ) => { - const doc = $iframe.contents().find( 'body#tinymce' ); - cy.wrap( doc ).find( 'p:last-child' ).type( content ); - } ); - - if ( 'undefined' !== typeof beforeSave ) { - beforeSave(); - } - - cy.intercept( 'POST', '/wp-admin/post.php', ( req ) => { - req.alias = 'savePost'; - } ); - - if ( 'draft' === status ) { - cy.get( '#save-post' ) - .should( 'not.have.class', 'disabled' ) - .click(); - } else { - cy.get( '#publish' ).should( 'not.have.class', 'disabled' ).click(); - } - - cy.wait( '@savePost' ).then( ( response ) => { - const body = new URLSearchParams( response.request?.body ); - const id = body.get( 'post_ID' ); - cy.wrap( id ); - } ); - } -); - -/** - * Open the document settings sidebar. - * - * This has been modified to work with the new WordPress editor. - * Once the next version of Cypress WP Utils is released, we can - * remove this. - * - * @param tab - Name of the tab - * - * @example - * Open 'Post' tab - * ``` - * cy.openDocumentSettingsSidebarCustom() - * ``` - * - * @example - * Open 'Block' tab - * ``` - * cy.openDocumentSettingsSidebarCustom('Block') - * ``` - */ -Cypress.Commands.add( 'openDocumentSettingsSidebarCustom', ( tab = 'Post' ) => { - cy.get( 'body' ).then( ( $body ) => { - const $settingButtonIds = [ - 'button[aria-expanded="false"][aria-label="Settings"]', - ]; - - $settingButtonIds.forEach( ( $settingButtonId ) => { - if ( $body.find( $settingButtonId ).length ) { - cy.get( $settingButtonId ).click(); - cy.wrap( $body.find( $settingButtonId ) ).as( 'sidebarButton' ); - } - } ); - - const $tabSelectors = [ - `div[role="tablist"] button:contains("${ tab }")`, - `.edit-post-sidebar__panel-tabs button:contains("${ tab }")`, - ]; - - $tabSelectors.forEach( ( $tabSelector ) => { - if ( $body.find( $tabSelector ).length ) { - cy.get( $tabSelector ).click(); - cy.wrap( $body.find( $tabSelector ) ).as( 'selectedTab' ); - } - } ); - } ); -} );