Skip to content

Commit 74fae4c

Browse files
committed
Added connect to mailchimp test.
1 parent 1b01593 commit 74fae4c

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

tests/cypress/e2e/connect.test.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* eslint-disable no-undef */
2+
describe('Admin can connect to "Mailchimp" Account', () => {
3+
before(() => {
4+
cy.login();
5+
});
6+
7+
it('Can connect to "Mailchimp" using OAuth flow.', () => {
8+
cy.visit('/wp-admin/admin.php?page=mailchimp_sf_options');
9+
10+
// Logout if already connected.
11+
cy.get('body').then(($body) => {
12+
if ($body.find('input[value="Logout"]').length > 0) {
13+
cy.get('input[value="Logout"]').click();
14+
}
15+
});
16+
17+
// Check Mailchimp menu.
18+
cy.get('#mailchimp_sf_oauth_connect').should('exist');
19+
20+
// Enable popup capture.
21+
cy.capturePopup();
22+
23+
cy.get('#mailchimp_sf_oauth_connect').click();
24+
cy.wait(5000);
25+
26+
cy.popup().find('input#username').clear().type(Cypress.env('MAILCHIMP_USERNAME'));
27+
cy.popup().find('input#password').clear().type(Cypress.env('MAILCHIMP_PASSWORD'));
28+
cy.popup().find('button[type="submit"]').click();
29+
cy.wait(8000); // Not a best practice, but did not find a better way to handle this.
30+
31+
cy.popup().find('input#submitButton').click();
32+
cy.wait(10000);
33+
34+
cy.get('.mc-user h3').contains('Logged in as: ');
35+
cy.get('input[value="Logout"]').should('exist');
36+
});
37+
});

tests/cypress/support/commands.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,28 @@
2323
//
2424
// -- This will overwrite an existing command --
2525
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
26+
27+
const state = {};
28+
29+
/**
30+
* Intercepts calls to window.open() to keep a reference to the new window
31+
*/
32+
Cypress.Commands.add('capturePopup', () => {
33+
cy.window().then((win) => {
34+
const { open } = win;
35+
cy.stub(win, 'open').callsFake((...params) => {
36+
// Capture the reference to the popup
37+
state.popup = open(...params);
38+
return state.popup;
39+
});
40+
});
41+
});
42+
43+
/**
44+
* Returns a wrapped body of a captured popup
45+
*/
46+
Cypress.Commands.add('popup', () => {
47+
console.log('state', state.popup);
48+
const popup = Cypress.$(state.popup.document);
49+
return cy.wrap(popup.contents().find('body'));
50+
});

tests/cypress/support/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
import '@10up/cypress-wp-utils';
1717

18+
// Import commands.js using ES2015 syntax:
19+
import './commands';
20+
1821
beforeEach( () => {
1922
cy.session( 'login', cy.login, {
2023
cacheAcrossSpecs: true,

0 commit comments

Comments
 (0)