Skip to content

Commit

Permalink
Fix flaky tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdharmesh committed Aug 31, 2023
1 parent 7db5a6f commit ff3ab67
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 27 deletions.
4 changes: 2 additions & 2 deletions tests/cypress/e2e/block-editor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ describe('Test Autoshare for Twitter with Block Editor.', () => {
cy.get('.editor-post-publish-panel button[aria-label="Close panel"]').click();
cy.openDocumentSettingsPanel('Autotweet');
cy.get('.autoshare-for-twitter-editor-panel button.autoshare-for-twitter-tweet-now').click();
cy.get('.autoshare-for-twitter-editor-panel .autoshare-for-twitter-tweet-text textarea').clear().type(`Random Tweet ${getRandomText(6)}`);
cy.get('.autoshare-for-twitter-editor-panel .autoshare-for-twitter-tweet-text textarea').clear().type(`Random Tweet ${getRandomText(6)}`, {force: true});
cy.get('.autoshare-for-twitter-editor-panel button.autoshare-for-twitter-re-tweet').click();
cy.get('.autoshare-for-twitter-log a').contains('Tweeted on');
});
Expand All @@ -193,7 +193,7 @@ describe('Test Autoshare for Twitter with Block Editor.', () => {
// 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);
cy.get('.autoshare-for-twitter-tweet-text textarea').clear().type(customTweetBody, {force: true});

// Save Draft
cy.get('.editor-post-save-draft').should('be.visible');
Expand Down
26 changes: 17 additions & 9 deletions tests/cypress/e2e/classic-editor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ describe('Test Autoshare for Twitter with Classic Editor.', () => {
cy.enableCheckbox('#autoshare-for-twitter-enable', defaultBehavior, false);

// publish
cy.get('#publish').should('be.visible').click({force: true});
cy.get('#publish').should('not.be.disabled');
cy.get('#publish').should('be.visible').click();

// Post-publish.
cy.get('#autoshare_for_twitter_metabox').should('be.visible');
Expand All @@ -50,7 +51,8 @@ describe('Test Autoshare for Twitter with Classic Editor.', () => {

// Check enable checkbox for auto-share.
cy.enableCheckbox('#autoshare-for-twitter-enable', defaultBehavior, true);
cy.get('#publish').should('be.visible').click({force: true});
cy.get('#publish').should('not.be.disabled');
cy.get('#publish').should('be.visible').click();

// Post-publish.
cy.get('#autoshare_for_twitter_metabox',).should('be.visible');
Expand All @@ -67,7 +69,8 @@ describe('Test Autoshare for Twitter with Classic Editor.', () => {

// Uncheck the checkbox and publish
cy.enableCheckbox('#autoshare-for-twitter-enable', defaultBehavior, false);
cy.get('#publish').should('be.visible').click({force: true});
cy.get('#publish').should('not.be.disabled');
cy.get('#publish').should('be.visible').click();

// Post-publish.
cy.get('#autoshare_for_twitter_metabox').should('be.visible');
Expand All @@ -84,7 +87,8 @@ describe('Test Autoshare for Twitter with Classic Editor.', () => {

// Check the checkbox and publish
cy.enableCheckbox('#autoshare-for-twitter-enable', defaultBehavior, true);
cy.get('#publish').should('be.visible').click({force: true});
cy.get('#publish').should('not.be.disabled');
cy.get('#publish').should('be.visible').click();

// Post-publish.
cy.get('#autoshare_for_twitter_metabox').should('be.visible');
Expand All @@ -99,8 +103,9 @@ describe('Test Autoshare for Twitter with Classic Editor.', () => {
cy.enableCheckbox('#autoshare-for-twitter-enable', defaultBehavior, true);
cy.enableTweetAccount('input.autoshare-for-twitter-account-checkbox', false);

// publish
cy.get('#publish').should('be.visible').click({force: true});
// publish.
cy.get('#publish').should('not.be.disabled');
cy.get('#publish').should('be.visible').click();

// Post-publish.
cy.get('#autoshare_for_twitter_metabox').should('be.visible');
Expand All @@ -119,7 +124,8 @@ describe('Test Autoshare for Twitter with Classic Editor.', () => {
cy.enableTweetAccount('input.autoshare-for-twitter-account-checkbox', true);

// publish
cy.get('#publish').should('be.visible').click({force: true});
cy.get('#publish').should('not.be.disabled');
cy.get('#publish').should('be.visible').click();

// Post-publish.
cy.get('#autoshare_for_twitter_metabox',).should('be.visible');
Expand All @@ -135,7 +141,8 @@ describe('Test Autoshare for Twitter with Classic Editor.', () => {

// Uncheck the checkbox and publish
cy.enableCheckbox('#autoshare-for-twitter-enable', defaultBehavior, false);
cy.get('#publish').should('be.visible').click({force: true});
cy.get('#publish').should('not.be.disabled');
cy.get('#publish').should('be.visible').click();

// Post-publish.
cy.get('#autoshare_for_twitter_metabox').should('be.visible');
Expand Down Expand Up @@ -167,7 +174,8 @@ describe('Test Autoshare for Twitter with Classic Editor.', () => {
cy.get('textarea#autoshare-for-twitter-text').should('have.value', customTweetBody);

// publish
cy.get('#publish').should('be.visible').click({force: true});
cy.get('#publish').should('not.be.disabled');
cy.get('#publish').should('be.visible').click();

// Post-publish.
cy.get('#autoshare_for_twitter_metabox',).should('be.visible');
Expand Down
50 changes: 34 additions & 16 deletions tests/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Cypress.Commands.add('openPrePublishPanel', () => {

Cypress.Commands.add(
'enableCheckbox',
(checkboxSelector, defaultBehavior, check = true) => {
(checkboxSelector, defaultBehavior, check) => {
// Check/Uncheck enable checkbox for auto-share.
cy.get(checkboxSelector).should('exist');
if (true === defaultBehavior) {
Expand All @@ -65,19 +65,28 @@ Cypress.Commands.add(
cy.get(checkboxSelector).first().should('not.be.checked');
}

cy.intercept('**/autoshare/v1/post-autoshare-for-twitter-meta/*').as(
'enableCheckbox'
);
if (defaultBehavior === check) {
return;
}

if (true === check) {
cy.get(checkboxSelector).first().check({ force: true });
if (defaultBehavior !== check) {
cy.wait('@enableCheckbox');
if (checkboxSelector === '#autoshare-for-twitter-enable') {
cy.get('#publish').should('not.be.disabled');
} else {
cy.get('button.editor-post-publish-button').should(
'not.be.disabled'
);
}
cy.get(checkboxSelector).first().should('be.checked');
} else {
cy.get(checkboxSelector).first().uncheck({ force: true });
if (defaultBehavior !== check) {
cy.wait('@enableCheckbox');
if (checkboxSelector === '#autoshare-for-twitter-enable') {
cy.get('#publish').should('not.be.disabled');
} else {
cy.get('button.editor-post-publish-button').should(
'not.be.disabled'
);
}
cy.get(checkboxSelector).first().should('not.be.checked');
}
Expand Down Expand Up @@ -126,17 +135,26 @@ Cypress.Commands.add('enableTweetAccount', (selector, check = true) => {
// Check/Uncheck enable checkbox for auto-share.
const checkbox = cy.get(selector).first();
checkbox.should('exist');
cy.intercept('**/autoshare/v1/post-autoshare-for-twitter-meta/*').as(
'enableTweetAccount'
);
if (true === check) {
checkbox.check({ force: true });
cy.wait('@enableTweetAccount');
checkbox.should('be.checked');
if (selector === 'input.autoshare-for-twitter-account-checkbox') {
cy.get('#publish').should('not.be.disabled');
} else {
cy.get('button.editor-post-publish-button').should(
'not.be.disabled'
);
}
cy.get(selector).first().should('be.checked');
} else {
checkbox.uncheck({ force: true });
cy.wait('@enableTweetAccount');
checkbox.should('not.be.checked');
if (selector === 'input.autoshare-for-twitter-account-checkbox') {
cy.get('#publish').should('not.be.disabled');
} else {
cy.get('button.editor-post-publish-button').should(
'not.be.disabled'
);
}
cy.get(selector).first().should('not.be.checked');
}
});

Expand Down Expand Up @@ -183,6 +201,6 @@ Cypress.Commands.add('publishPost', () => {
}
});

cy.get('[aria-disabled="false"].editor-post-publish-button').click();
cy.get('button[aria-disabled="false"].editor-post-publish-button').click();
cy.wait('@publishPost');
});

0 comments on commit ff3ab67

Please sign in to comment.