Skip to content

Commit 3ab6997

Browse files
committed
E2E: Update E2E tests.
1 parent 5a114ae commit 3ab6997

File tree

3 files changed

+9
-66
lines changed

3 files changed

+9
-66
lines changed

mailchimp_widget.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ function mailchimp_form_field( $data, $num_fields, $should_display = null, $labe
422422
case 'phone':
423423
$is_us_phone = isset( $data['options']['phone_format'] ) && 'US' === $data['options']['phone_format'];
424424
$html .= '
425-
<input type="tel" size="20" minlength="6" maxlength="20" data-pattern="^\+?[\d\s\-\(\)\.]*$" value="" name="' . esc_attr( $opt ) . '" id="' . esc_attr( $opt ) . '" class="mc_input mailchimp-sf-phone" placeholder="' . esc_attr( $is_us_phone ? '(###) ### - ####' : '' ) . '" />
425+
<input type="tel" size="20" minlength="6" maxlength="20" pattern="^\+?[\d\s\-\(\)\.]*$" value="" name="' . esc_attr( $opt ) . '" id="' . esc_attr( $opt ) . '" class="mc_input mailchimp-sf-phone" placeholder="' . esc_attr( $is_us_phone ? '(###) ### - ####' : '' ) . '" />
426426
';
427427
break;
428428
case 'email':

tests/cypress/e2e/validation/us-phone.test.js

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,11 @@ import { generateRandomEmail } from '../../support/functions/utility';
44
/**
55
* Test for Phone Number Validation
66
*/
7-
describe('US Multi-Input Phone Number Validation', () => {
7+
describe('Phone Number Validation', () => {
88
let blockPostPostURL;
99

10-
const validPhones = [
11-
{ area: '123', detail1: '456', detail2: '7890' },
12-
{ area: '987', detail1: '654', detail2: '3210' },
13-
];
14-
const invalidPhones = [
15-
{ area: '123', detail1: '456', detail2: '78a0' },
16-
{ area: '123', detail1: '45!', detail2: '7890' },
17-
];
18-
const tooShortPhones = [
19-
{ area: '12', detail1: '456', detail2: '789' },
20-
{ area: '1', detail1: '45', detail2: '7890' },
21-
];
22-
const tooLongPhones = [
23-
{ area: '1234', detail1: '567', detail2: '890' },
24-
{ area: '123', detail1: '4567', detail2: '8901' },
25-
];
10+
const validPhones = ['1234567890', '+1 (234) 567-890'];
11+
const invalidPhones = ['12345678a0', '12345!7890'];
2612

2713
before(() => {
2814
cy.login();
@@ -54,9 +40,7 @@ describe('US Multi-Input Phone Number Validation', () => {
5440
});
5541

5642
function fillPhoneInputs(phone) {
57-
cy.get('#mc_mv_PHONE-area').clear().type(phone.area);
58-
cy.get('#mc_mv_PHONE-detail1').clear().type(phone.detail1);
59-
cy.get('#mc_mv_PHONE-detail2').clear().type(phone.detail2);
43+
cy.get('#mc_mv_PHONE').clear().type(phone);
6044
}
6145

6246
it('Valid phone numbers', () => {
@@ -81,27 +65,7 @@ describe('US Multi-Input Phone Number Validation', () => {
8165
cy.get('#mc_mv_EMAIL').type(email);
8266
fillPhoneInputs(phone);
8367
cy.submitFormAndVerifyError();
84-
cy.get('.mc_error_msg').contains('must consist of only numbers');
85-
});
86-
});
87-
88-
it('Phone length validation', () => {
89-
cy.visit(blockPostPostURL);
90-
91-
tooShortPhones.forEach((phone) => {
92-
const email = generateRandomEmail('shortphone');
93-
cy.get('#mc_mv_EMAIL').type(email);
94-
fillPhoneInputs(phone);
95-
cy.submitFormAndVerifyError();
96-
cy.get('.mc_error_msg').contains('should be 10 digits long');
97-
});
98-
99-
tooLongPhones.forEach((phone) => {
100-
const email = generateRandomEmail('longphone');
101-
cy.get('#mc_mv_EMAIL').type(email);
102-
fillPhoneInputs(phone);
103-
cy.submitFormAndVerifyError();
104-
cy.get('.mc_error_msg').contains('should be 10 digits long');
68+
cy.get('.mc_error_msg').contains('Please enter a valid Phone Number.');
10569
});
10670
});
10771
});

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

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,7 @@ describe('Validate required fields', () => {
9898
cy.get('#mc_mv_EMAIL').clear().type(email); // Email is always required
9999

100100
requiredFields.forEach((field) => {
101-
if (field.selector === '#mc_mv_PHONE') {
102-
const phone = field.input.split('-');
103-
cy.get('#mc_mv_PHONE-area').clear().type(phone[0]);
104-
cy.get('#mc_mv_PHONE-detail1').clear().type(phone[1]);
105-
cy.get('#mc_mv_PHONE-detail2').clear().type(phone[2]);
106-
} else {
107-
cy.get(field.selector).clear().type(field.input);
108-
}
101+
cy.get(field.selector).clear().type(field.input);
109102
cy.get('body').click(0, 0); // Click outside the field to clear the datepicker modal
110103
});
111104

@@ -131,14 +124,7 @@ describe('Validate required fields', () => {
131124

132125
// Test validation for each required field
133126
requiredFields.forEach((field) => {
134-
// Submit the form without input to trigger validation
135-
if (field.selector === '#mc_mv_PHONE') {
136-
cy.get('#mc_mv_PHONE-area').clear();
137-
cy.get('#mc_mv_PHONE-detail1').clear();
138-
cy.get('#mc_mv_PHONE-detail2').clear();
139-
} else {
140-
cy.get(field.selector).clear(); // Ensure field is empty
141-
}
127+
cy.get(field.selector).clear(); // Ensure field is empty
142128
cy.get('body').click(0, 0); // Click outside the field to clear the datepicker modal
143129
cy.get('#mc_signup_submit').click();
144130

@@ -147,14 +133,7 @@ describe('Validate required fields', () => {
147133
cy.get('.mc_error_msg').should('include.text', field.errorMessage);
148134

149135
// Fill in the field
150-
if (field.selector === '#mc_mv_PHONE') {
151-
const phone = field.input.split('-');
152-
cy.get('#mc_mv_PHONE-area').clear().type(phone[0]);
153-
cy.get('#mc_mv_PHONE-detail1').clear().type(phone[1]);
154-
cy.get('#mc_mv_PHONE-detail2').clear().type(phone[2]);
155-
} else {
156-
cy.get(field.selector).type(field.input);
157-
}
136+
cy.get(field.selector).type(field.input);
158137
cy.get('body').click(0, 0); // Click outside the field to clear the datepicker modal
159138
});
160139
});

0 commit comments

Comments
 (0)