Skip to content

Commit 08800a9

Browse files
committed
Fix failing E2E tests.
1 parent be4d115 commit 08800a9

File tree

3 files changed

+66
-14
lines changed

3 files changed

+66
-14
lines changed

tests/cypress/e2e/validation/validate-required-fields.test.js

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,41 @@ describe('Validate required fields', () => {
4646
cy.mailchimpLoginIfNotAlreadyLoggedIn();
4747

4848
// Set all merge fields to required in the Mailchimp test user account
49-
cy.setMergeFieldsRequired(true);
49+
cy.setMergeFieldsRequired(true, '10up', [
50+
'FNAME',
51+
'LNAME',
52+
'ADDRESS',
53+
'BIRTHDAY',
54+
'COMPANY',
55+
'MMERGE8',
56+
'MMERGE9',
57+
'MMERGE10',
58+
'MMERGE11',
59+
'MMERGE7',
60+
'MMERGE6',
61+
'PHONE',
62+
]);
5063
});
5164

5265
after(() => {
5366
// I don't know why we need to login again, but we do
5467
cy.login(); // WordPress login
5568

5669
// Cleanup: Set all merge fields to not required in the Mailchimp test user account
57-
cy.setMergeFieldsRequired(false);
70+
cy.setMergeFieldsRequired(false, '10up', [
71+
'FNAME',
72+
'LNAME',
73+
'ADDRESS',
74+
'BIRTHDAY',
75+
'COMPANY',
76+
'MMERGE8',
77+
'MMERGE9',
78+
'MMERGE10',
79+
'MMERGE11',
80+
'MMERGE7',
81+
'MMERGE6',
82+
'PHONE',
83+
]);
5884

5985
// Cleanup: Uncheck all optional merge fields
6086
cy.toggleMergeFields('uncheck');
@@ -66,7 +92,14 @@ describe('Validate required fields', () => {
6692
cy.get('#mc_mv_EMAIL').clear().type(email); // Email is always required
6793

6894
requiredFields.forEach((field) => {
69-
cy.get(field.selector).clear().type(field.input);
95+
if (field.selector === '#mc_mv_PHONE') {
96+
const phone = field.input.split('-');
97+
cy.get('#mc_mv_PHONE-area').clear().type(phone[0]);
98+
cy.get('#mc_mv_PHONE-detail1').clear().type(phone[1]);
99+
cy.get('#mc_mv_PHONE-detail2').clear().type(phone[2]);
100+
} else {
101+
cy.get(field.selector).clear().type(field.input);
102+
}
70103
cy.get('body').click(0, 0); // Click outside the field to clear the datepicker modal
71104
});
72105

@@ -88,13 +121,19 @@ describe('Validate required fields', () => {
88121
// Ensure the form exists
89122
cy.get('#mc_signup').should('exist');
90123

124+
// Fill out entire form everytime so we can narrow tests to one input at a time
125+
fillOutAllFields();
126+
91127
// Test validation for each required field
92128
requiredFields.forEach((field) => {
93-
// Fill out entire form everytime so we can narrow tests to one input at a time
94-
fillOutAllFields();
95-
96129
// Submit the form without input to trigger validation
97-
cy.get(field.selector).clear(); // Ensure field is empty
130+
if (field.selector === '#mc_mv_PHONE') {
131+
cy.get('#mc_mv_PHONE-area').clear();
132+
cy.get('#mc_mv_PHONE-detail1').clear();
133+
cy.get('#mc_mv_PHONE-detail2').clear();
134+
} else {
135+
cy.get(field.selector).clear(); // Ensure field is empty
136+
}
98137
cy.get('body').click(0, 0); // Click outside the field to clear the datepicker modal
99138
cy.get('#mc_signup_submit').click();
100139

@@ -103,7 +142,15 @@ describe('Validate required fields', () => {
103142
cy.get('.mc_error_msg').should('include.text', field.errorMessage);
104143

105144
// Fill in the field
106-
cy.get(field.selector).type(field.input);
145+
if (field.selector === '#mc_mv_PHONE') {
146+
const phone = field.input.split('-');
147+
cy.get('#mc_mv_PHONE-area').clear().type(phone[0]);
148+
cy.get('#mc_mv_PHONE-detail1').clear().type(phone[1]);
149+
cy.get('#mc_mv_PHONE-detail2').clear().type(phone[2]);
150+
} else {
151+
cy.get(field.selector).type(field.input);
152+
}
153+
cy.get('body').click(0, 0); // Click outside the field to clear the datepicker modal
107154
});
108155
});
109156
});

tests/cypress/support/commands/mailchimpApi.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,15 @@ function getContactFromList(email, listName = '10up') {
148148
* @returns {Promise} - A promise that resolves when all merge fields are updated
149149
*/
150150
Cypress.Commands.add('updateMergeFieldsByList', updateMergeFieldsByList);
151-
async function updateMergeFieldsByList(listId, data) {
151+
async function updateMergeFieldsByList(listId, data, fields = []) {
152152
const mergeFields = await getMergeFields(listId);
153153
const updatedMergeFields = mergeFields.map((field) => {
154-
return updateMergeField(listId, field.merge_id, field.name, data);
154+
// If fields are provided, check if the field is in the list
155+
if (fields.length > 0 && !fields.includes(field.tag)) {
156+
return Promise.resolve(); // Skip this field
157+
} else {
158+
return updateMergeField(listId, field.merge_id, field.name, data);
159+
}
155160
});
156161

157162
return await Promise.all(updatedMergeFields);

tests/cypress/support/commands/settings.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414
Cypress.Commands.add('selectList', (listName) => {
1515
cy.visit('/wp-admin/admin.php?page=mailchimp_sf_options');
16-
cy.get('#mc_list_id').select(listName, {force: true});
16+
cy.get('#mc_list_id').select(listName, { force: true });
1717
cy.get('input[value="Update List"]').click();
1818
});
1919

@@ -114,11 +114,11 @@ function toggleMergeFields(action) {
114114
* // Set merge fields for a specific list
115115
* cy.setMergeFieldsRequired(true, 'Custom List');
116116
*/
117-
Cypress.Commands.add('setMergeFieldsRequired', (required, listName = '10up') => {
117+
Cypress.Commands.add('setMergeFieldsRequired', (required, listName = '10up', fields = []) => {
118118
// Set all merge fields to required in the Mailchimp test user account
119119
cy.getListId(listName).then((listId) => {
120-
cy.updateMergeFieldsByList(listId, { required: required }).then(() => {
120+
cy.updateMergeFieldsByList(listId, { required }, fields).then(() => {
121121
cy.selectList(listName); // Ensure list is selected, refreshes Mailchimp data with WP
122122
});
123123
});
124-
})
124+
});

0 commit comments

Comments
 (0)