From fe15e5cd7da6ec0ac26856ee005ed1cb769e841b Mon Sep 17 00:00:00 2001 From: Dharmesh Patel Date: Tue, 15 Aug 2023 15:22:31 +0530 Subject: [PATCH] Add e2e tests. --- tests/cypress/e2e/block-editor.test.js | 34 ++++++++++++++++++++++++ tests/cypress/e2e/classic-editor.test.js | 28 +++++++++++++++++++ tests/cypress/support/commands.js | 2 +- 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/tests/cypress/e2e/block-editor.test.js b/tests/cypress/e2e/block-editor.test.js index bfdf93a0..08bded9d 100644 --- a/tests/cypress/e2e/block-editor.test.js +++ b/tests/cypress/e2e/block-editor.test.js @@ -183,4 +183,38 @@ describe('Test Autoshare for Twitter with Block Editor.', () => { cy.get('.autoshare-for-twitter-log a').contains('Tweeted on'); }); }); + + it('Tests that custom tweet message remain persistent for Tweet', () => { + const customTweetBody = `Custom Tweet ${getRandomText(6)}`; + // Start create new post by enter post title + cy.startCreatePost(); + + // Open AutoTweet Panel and set custom tweet message. + cy.openDocumentSettingsPanel('Autotweet enabled'); + cy.get('.autoshare-for-twitter-prepublish__override-row button').click(); + cy.get('.autoshare-for-twitter-tweet-text textarea').clear().type(customTweetBody); + + // Save Draft + cy.get('.editor-post-save-draft').should('be.visible'); + cy.get('.editor-post-save-draft').click(); + cy.get('.editor-post-saved-state').should('have.text', 'Saved'); + + // Verify custom tweet message. + cy.reload(); + cy.get('.autoshare-for-twitter-tweet-text textarea').should('have.value', customTweetBody); + + // Open pre-publish Panel. + cy.openPrePublishPanel(); + + // Publish + cy.publishPost(); + + // Post-publish. + cy.get('.autoshare-for-twitter-post-status').should('be.visible'); + cy.get('.autoshare-for-twitter-post-status').contains('Tweeted on'); + + // Verify custom tweet message is cleared on publish. + cy.get('.post-publish-panel__postpublish button.autoshare-for-twitter-tweet-now').click(); + cy.get('.post-publish-panel__postpublish .autoshare-for-twitter-tweet-text textarea').should('have.value', ''); + }); }); diff --git a/tests/cypress/e2e/classic-editor.test.js b/tests/cypress/e2e/classic-editor.test.js index 1151945c..ad6680bb 100644 --- a/tests/cypress/e2e/classic-editor.test.js +++ b/tests/cypress/e2e/classic-editor.test.js @@ -148,4 +148,32 @@ describe('Test Autoshare for Twitter with Classic Editor.', () => { cy.get('.autoshare-for-twitter-status-log-data').contains('Tweeted on'); }); }); + + it('Tests that custom tweet message remain persistent for Tweet', () => { + const customTweetBody = `Custom Tweet ${getRandomText(6)}`; + // Start create post. + cy.classicStartCreatePost(); + + // Set custom tweet message. + cy.enableCheckbox('#autoshare-for-twitter-enable', true, true); + cy.get('#autoshare-for-twitter-edit').click(); + cy.get('textarea#autoshare-for-twitter-text').clear().type(customTweetBody); + + // Save Draft + cy.get('#save-post').click(); + + // verify custom tweet message. + cy.get('textarea#autoshare-for-twitter-text').should('have.value', customTweetBody); + + // publish + cy.get('#publish').should('be.visible').click({force: true}); + + // Post-publish. + cy.get('#autoshare_for_twitter_metabox',).should('be.visible'); + cy.get('#autoshare_for_twitter_metabox',).contains('Tweeted on'); + + // Verify custom tweet message is cleared on publish. + cy.get('button.tweet-now-button').click(); + cy.get('textarea#autoshare-for-twitter-text').should('have.value', ''); + }); }); diff --git a/tests/cypress/support/commands.js b/tests/cypress/support/commands.js index 4f9b8a36..85d1056c 100644 --- a/tests/cypress/support/commands.js +++ b/tests/cypress/support/commands.js @@ -110,7 +110,7 @@ Cypress.Commands.add( 'markAccountForAutoshare', ( enable = true ) => { Cypress.Commands.add( 'enableEditor', ( editor = 'block' ) => { cy.visit('/wp-admin/options-writing.php#classic-editor-options'); cy.get(`#classic-editor-${editor}`).click(); - cy.get('#classic-editor-allow').click(); + cy.get('#classic-editor-disallow').click(); cy.get('#submit').click(); });