Skip to content

Commit f1e750b

Browse files
committed
E2E: Add e2e tests.
1 parent ae997c8 commit f1e750b

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

tests/cypress/e2e/mailchimp-block.test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,37 @@ describe('Block Tests', () => {
242242
});
243243
});
244244

245+
it('Proper error message should display if unsubscribed user try to subscribe', () => {
246+
cy.visit(`/wp-admin/post.php?post=${postId}&action=edit`);
247+
cy.getBlockEditor().find('h2[aria-label="Enter a header (optional)"]').click();
248+
cy.openDocumentSettingsPanel('Form Settings', 'Block');
249+
cy.get('.mailchimp-double-opt-in input.components-form-toggle__input').first().uncheck();
250+
cy.get('.mailchimp-update-existing-subscribers input.components-form-toggle__input')
251+
.first()
252+
.check();
253+
cy.get('button.editor-post-publish-button').click();
254+
cy.wait(500);
255+
256+
// Verify
257+
cy.visit(`/?p=${postId}`);
258+
cy.get('#mc_mv_EMAIL').should('exist');
259+
cy.get('#mc_mv_EMAIL').clear().type('unsubscribed_user@gmail.com');
260+
cy.get('#mc_signup_submit').should('exist');
261+
cy.get('#mc_signup_submit').click();
262+
cy.get('.mc_error_msg').should('exist');
263+
cy.get('.mc_error_msg').contains(
264+
'The email address cannot be subscribed because it was previously unsubscribed, bounced, or is under review. Please sign up here.',
265+
);
266+
267+
// Reset
268+
cy.visit(`/wp-admin/post.php?post=${postId}&action=edit`);
269+
cy.getBlockEditor().find('h2[aria-label="Enter a header (optional)"]').click();
270+
cy.openDocumentSettingsPanel('Form Settings', 'Block');
271+
cy.get('.mailchimp-double-opt-in input.components-form-toggle__input').first().check();
272+
cy.get('button.editor-post-publish-button').click();
273+
cy.wait(500);
274+
});
275+
245276
// TODO: Add tests for the Double Opt-in and Update existing subscribers settings.
246277
// TODO: Add tests for the block styles settings.
247278
// TODO: Add tests for the form submission.

tests/cypress/e2e/settings.test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,30 @@ describe('Admin can update plugin settings', () => {
153153
cy.get('#mc_unsub_link').should('not.exist');
154154
});
155155
});
156+
157+
it('Proper error message should display if unsubscribed user try to subscribe', () => {
158+
cy.visit('/wp-admin/admin.php?page=mailchimp_sf_options');
159+
cy.get('#mc_double_optin').uncheck();
160+
cy.get('#mc_update_existing').check();
161+
cy.get('input[value="Update Subscribe Form Settings"]').first().click();
162+
163+
// Verify
164+
[shortcodePostURL, blockPostPostURL].forEach((url) => {
165+
cy.visit(url);
166+
cy.get('#mc_mv_EMAIL').should('exist');
167+
cy.get('#mc_mv_EMAIL').clear().type('unsubscribed_user@gmail.com');
168+
cy.get('#mc_signup_submit').should('exist');
169+
cy.get('#mc_signup_submit').click();
170+
cy.get('.mc_error_msg').should('exist');
171+
cy.get('.mc_error_msg').contains(
172+
'The email address cannot be subscribed because it was previously unsubscribed, bounced, or is under review. Please sign up here.',
173+
);
174+
});
175+
176+
// Reset
177+
cy.visit('/wp-admin/admin.php?page=mailchimp_sf_options');
178+
cy.get('#mc_double_optin').check();
179+
cy.get('#mc_update_existing').check();
180+
cy.get('input[value="Update Subscribe Form Settings"]').first().click();
181+
});
156182
});

0 commit comments

Comments
 (0)