From 4a5f88144de28f55535e0e0c8c12c7a63c2f4bc0 Mon Sep 17 00:00:00 2001 From: Krupa Pammi Date: Mon, 24 Jun 2024 12:47:38 +0100 Subject: [PATCH] test: update giftaid/update tests --- .../tests/update/formValidation.spec.js | 33 +++++++++++++++++-- .../internationalAddressesValidation.spec.js | 1 + playwright-staging/tests/utils/commands.js | 2 ++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/playwright-staging/tests/update/formValidation.spec.js b/playwright-staging/tests/update/formValidation.spec.js index 33779e79..cec59d79 100644 --- a/playwright-staging/tests/update/formValidation.spec.js +++ b/playwright-staging/tests/update/formValidation.spec.js @@ -6,13 +6,15 @@ const { v4: uuidv4 } = require('uuid'); const Chance = require('chance'); const chance = new Chance(); -test.describe('Giftaid Update form validation @sanity @nightly-sanity', () => { +test.describe.only('Giftaid Update form validation @sanity @nightly-sanity', () => { let commands; test.beforeEach(async ({ page }) => { commands = new Commands(page); // Navigate to the Giftaid Update form - await page.goto(`${process.env.BASE_URL}update`, { waitUntil: 'networkidle' }); + await page.goto(`${process.env.BASE_URL}update`, { timeout: 30000 }); + await page.waitForLoadState('domcontentloaded'); + await page.locator('.form__radio input[type="radio"][value="online"]').click(); }); test('empty input fields should show error messages', async ({ page }) => { @@ -22,6 +24,7 @@ test.describe('Giftaid Update form validation @sanity @nightly-sanity', () => { // Check for the error messages associated with each field await expect(page.locator('div#field-error--firstname > span')).toHaveText('Please fill in your first name'); await expect(page.locator('div#field-error--lastname > span')).toHaveText('Please fill in your last name'); + await expect(page.locator('div#field-error--email > span')).toHaveText('Please fill in your email address'); await expect(page.locator('div#field-error--postcode > span')).toHaveText('Please enter your postcode'); await expect(page.locator('div#field-error--addressDetails > span')).toHaveText('Please fill in your address'); await expect(page.locator('div#field-error--giftAidClaimChoice > span')).toHaveText('This field is required'); @@ -93,6 +96,32 @@ test.describe('Giftaid Update form validation @sanity @nightly-sanity', () => { await page.close(); }); + test.only('Validate mobile number field on giftaid update form', async ({ page }) => { + const commands = new Commands(page); + + // 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.' }, + { input: '0712345678900', error: 'Please enter a valid mobile phone number - it must be the same number associated with your donation.' }, + { input: '0712 345 6789', error: 'Please enter a valid mobile phone number - it must be the same number associated with your donation.' }, + { input: '0780ab5694245', error: 'Please enter a valid mobile phone number - it must be the same number associated with your donation.' }, + ]; + + for (let testCase of mobileTestCases) { + await page.locator('#field-input--mobile').fill(''); // Clear the field before each test + await page.locator('#field-input--mobile').type(testCase.input, { delay: 100 }); + await expect(page.locator('div#field-error--mobile > span')).toHaveText(testCase.error); + } + + // Validate correct mobile number + await page.locator('#field-input--mobile').fill(''); // Ensure the field is cleared and filled with valid data + await commands.populateUpdateFormFields(page, { mobile: '07123456789' }); + await page.click('#giftAidClaimChoice>div:nth-child(2)>label'); // Select yes for declaration + await page.click('button[type=submit]'); // Submit the form + + await expect(page.locator('div > h1')).toHaveText('Thank you, test!'); + }); + test('Postcode validation and form submission', async ({ page }) => { // Define postcodes and expected error messages const postcodes = [ diff --git a/playwright-staging/tests/update/internationalAddressesValidation.spec.js b/playwright-staging/tests/update/internationalAddressesValidation.spec.js index 696ae997..eafc456e 100644 --- a/playwright-staging/tests/update/internationalAddressesValidation.spec.js +++ b/playwright-staging/tests/update/internationalAddressesValidation.spec.js @@ -8,6 +8,7 @@ test.describe('International addresses validation on update form @sanity @nightl await page.goto(process.env.BASE_URL + 'update', { timeout: 30000 }); await page.waitForLoadState('domcontentloaded'); + await page.locator('.form__radio input[type="radio"][value="call centre"]').click(); // fill in all input fields // await page.locator('input#field-input--transactionId').fill(transactionId); diff --git a/playwright-staging/tests/utils/commands.js b/playwright-staging/tests/utils/commands.js index 3390afef..08ef6bf7 100644 --- a/playwright-staging/tests/utils/commands.js +++ b/playwright-staging/tests/utils/commands.js @@ -57,6 +57,7 @@ class Commands { firstName = 'test', lastName = chance.last(), email = `giftaid-update-staging-${chance.email()}`, + mobile = '07123456789', postcode = chance.postcode(), address1 = chance.address(), address2 = chance.street(), @@ -67,6 +68,7 @@ class Commands { await page.locator('input#field-input--lastname').fill(lastName); await page.locator('input#field-input--postcode').fill(postcode); await page.locator('input#field-input--email').fill(email); + await page.locator('#field-input--mobile').fill(mobile); await page.locator('a[aria-describedby=field-error--addressDetails]').click(); await page.locator('input#field-input--address1').fill(address1); await page.locator('input#field-input--address2').fill(address2);