Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Match Update form 'Mobile' regex pattern to B/E #428

Merged
merged 6 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions playwright-local/tests/update/formValidation.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// @ts-check
const { test, expect } = require('@playwright/test');
const { Commands } = require('../utils/commands');
const Chance = require('chance');
const chance = new Chance();

const email = `giftaid-staging-${Date.now().toString()}@email.sls.comicrelief.com`;

Expand Down Expand Up @@ -177,7 +179,14 @@ test.describe('Giftaid update form validation', () => {

test('Validate mobile number field', async ({ page }) => {
const commands = new Commands(page);

// List of allowed prefixes for UK mobile numbers
const prefixes = ['074', '075', '077', '078', '079'];
// Randomly select one prefix from the list
const prefix = chance.pickone(prefixes);
// Generate the remaining 8 digits randomly
const mobile = `${prefix}${chance.string({ pool: '0123456789', length: 8 })}`;
console.log('mobile number generated', mobile);

// Test cases for various mobile number validations
const mobileTestCases = [
{ input: '0712345678', error: 'Please enter a valid mobile phone number - it must be the same number associated with your donation.' },
Expand All @@ -195,7 +204,7 @@ test.describe('Giftaid update form validation', () => {
// Validate correct mobile number
await page.locator('#field-input--mobile').fill(''); // Ensure the field is cleared before filling with valid data

await commands.populateUpdateFormFields(page);
await commands.populateUpdateFormFields(page, { mobile: mobile });

// Select yes for giftaid declaration to complete the form
await page.locator('#giftAidClaimChoice>div:nth-child(2)>label').click();
Expand Down
2 changes: 1 addition & 1 deletion playwright-local/tests/utils/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Commands {
address2 = chance.street(),
address3 = 'test address 3',
town = chance.city(),
mobile = chance.phone({ country: 'uk', mobile: true }).replace(/\s/g, ''), // Remove spaces from the phone number
mobile = '07516144519'
} = {}) {
await page.locator('input#field-input--firstname').fill(firstName);
await page.locator('input#field-input--lastname').fill(lastName);
Expand Down
11 changes: 9 additions & 2 deletions playwright-staging/tests/update/formValidation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,15 @@ test.describe('Giftaid Update form validation @sanity @nightly-sanity', () => {
await page.close();
});

test.only('Validate mobile number field on giftaid update form', async ({ page }) => {
test('Validate mobile number field on giftaid update form', async ({ page }) => {
const commands = new Commands(page);
// List of allowed prefixes for UK mobile numbers
const prefixes = ['074', '075', '077', '078', '079'];
// Randomly select one prefix from the list
const prefix = chance.pickone(prefixes);
// Generate the remaining 8 digits randomly
const mobile = `${prefix}${chance.string({ pool: '0123456789', length: 8 })}`;
console.log('mobile number generated', mobile);

// Test cases for various mobile number validations
const mobileTestCases = [
Expand All @@ -118,7 +125,7 @@ test.describe('Giftaid Update form validation @sanity @nightly-sanity', () => {
// Validate correct mobile number
await page.locator('#field-input--mobile').fill(''); // Ensure the field is cleared and filled with valid data
await page.locator('.form__radio input[type="radio"][value="call centre"]').click();
await commands.populateUpdateFormFields(page, { mobile: '07123456789' });
await commands.populateUpdateFormFields(page, { mobile: mobile });
await page.click('#giftAidClaimChoice>div:nth-child(2)>label'); // Select yes for declaration
await page.click('button[type=submit]'); // Submit the form

Expand Down
2 changes: 1 addition & 1 deletion playwright-staging/tests/utils/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Commands {
firstName = 'test',
lastName = chance.last(),
email = `giftaid-update-staging-${chance.email()}`,
mobile = '07123456789',
mobile = '07516144519',
postcode = chance.postcode(),
address1 = chance.address(),
address2 = chance.street(),
Expand Down
2 changes: 1 addition & 1 deletion src/pages/GiftAid/UpdateForm/UpdateFormFields.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const updateFormFields = {
placeholder: 'In the format 07123456789',
label: 'Mobile number',
required: false,
pattern: '^07[0-9]{9}$', // Matches the validation in the main 'submit' form
pattern: '^(?:(?:00)?44|0)7(?:[457-9]\\d{2}|624)\\d{6}$', // As per Update.action.js in serverless-giftaid
helpText: 'Enter the one associated with your donation',
emptyFieldErrorText: 'Please fill in your mobile number',
invalidErrorText: 'Please enter a valid mobile phone number - it must be the same number associated with your donation.',
Expand Down
Loading