diff --git a/playwright-local/tests/update/formValidation.spec.js b/playwright-local/tests/update/formValidation.spec.js index 10dcc1b4..cc0219ef 100644 --- a/playwright-local/tests/update/formValidation.spec.js +++ b/playwright-local/tests/update/formValidation.spec.js @@ -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`; @@ -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.' }, @@ -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(); diff --git a/playwright-local/tests/utils/commands.js b/playwright-local/tests/utils/commands.js index 516111e3..bd570c92 100644 --- a/playwright-local/tests/utils/commands.js +++ b/playwright-local/tests/utils/commands.js @@ -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); diff --git a/playwright-staging/tests/update/formValidation.spec.js b/playwright-staging/tests/update/formValidation.spec.js index d6520009..0772b653 100644 --- a/playwright-staging/tests/update/formValidation.spec.js +++ b/playwright-staging/tests/update/formValidation.spec.js @@ -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 = [ @@ -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 diff --git a/playwright-staging/tests/utils/commands.js b/playwright-staging/tests/utils/commands.js index 08ef6bf7..49fd8043 100644 --- a/playwright-staging/tests/utils/commands.js +++ b/playwright-staging/tests/utils/commands.js @@ -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(), diff --git a/src/pages/GiftAid/UpdateForm/UpdateFormFields.js b/src/pages/GiftAid/UpdateForm/UpdateFormFields.js index 858fb84d..99e1f5b0 100644 --- a/src/pages/GiftAid/UpdateForm/UpdateFormFields.js +++ b/src/pages/GiftAid/UpdateForm/UpdateFormFields.js @@ -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.',