Skip to content

Commit

Permalink
Add e2e tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdharmesh committed Aug 15, 2023
1 parent a06c49b commit fe15e5c
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
34 changes: 34 additions & 0 deletions tests/cypress/e2e/block-editor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', '');
});
});
28 changes: 28 additions & 0 deletions tests/cypress/e2e/classic-editor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', '');
});
});
2 changes: 1 addition & 1 deletion tests/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand Down

0 comments on commit fe15e5c

Please sign in to comment.