Skip to content

Commit

Permalink
Ensure user is logged out of mailchimp accounts for admin tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxwellGarceau committed Dec 23, 2024
1 parent 6512804 commit 101d0b8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
6 changes: 6 additions & 0 deletions tests/cypress/e2e/admin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ describe('Admin can login and make sure plugin is activated', () => {
it('Admin can see "Create account" button and Can visit "Create account" settings page.', () => {
cy.visit('/wp-admin/admin.php?page=mailchimp_sf_options');

// If logged in then log out
cy.mailchimpLogout();

// Check Create account button.
cy.get('.button.mailchimp-sf-button.button-secondary').should('be.visible');
cy.get('.button.mailchimp-sf-button.button-secondary').contains('Create an account');
Expand All @@ -35,6 +38,9 @@ describe('Admin can login and make sure plugin is activated', () => {
it("Admin shouldn't able to submit create account form with invalid data", () => {
cy.visit('/wp-admin/admin.php?page=mailchimp_sf_create_account');

// If logged in then log out
cy.mailchimpLogout();

// Submit form without filling any data.
cy.get('#mailchimp-sf-create-activate-account').click();

Expand Down
15 changes: 10 additions & 5 deletions tests/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ Cypress.Commands.add('popup', () => {
return cy.wrap(popup.contents().find('body'));
});

Cypress.Commands.add('mailchimpLogout', () => {
// Logout if already connected.
cy.get('body').then(($body) => {
if ($body.find('input[value="Logout"]').length > 0) {
cy.get('input[value="Logout"]').click();
}
});
});

/**
* Log into Mailchimp account
*
Expand All @@ -59,11 +68,7 @@ Cypress.Commands.add('mailchimpLogin', () => {
cy.visit('/wp-admin/admin.php?page=mailchimp_sf_options');

// Logout if already connected.
cy.get('body').then(($body) => {
if ($body.find('input[value="Logout"]').length > 0) {
cy.get('input[value="Logout"]').click();
}
});
cy.mailchimpLogout();

// Check Mailchimp login screen for OAuth login.
cy.get('#mailchimp_sf_oauth_connect').should('exist');
Expand Down

0 comments on commit 101d0b8

Please sign in to comment.