Skip to content
18 changes: 10 additions & 8 deletions playwright-local/tests/submit/addressValidation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,31 @@ test.describe('Address validation', () => {

test.beforeEach(async ({ page }) => {
await page.goto('/', { timeout: 30000 });

await page.waitForLoadState('domcontentloaded');
await page.locator('#field-label--giftaid').click();
await page.locator('#field-input--mobile').fill('07123456789');
await page.locator('input#field-input--firstname').fill('test');
await page.locator('input#field-input--lastname').fill('user');
});

test('empty postcode should show error message', async ({ page }) => {
await page.locator('input#field-input--postcode').fill('');
await page.locator('button[type=submit]').click();
await expect(page.locator('div#field-error--postcode > span')).toHaveText('Please enter your postcode');
await page.close();
});

test('invalid postcodes should show error messages', async ({ page }) => {
await page.locator('input#field-input--postcode').fill('12SE17TP');
await expect(page.locator('div#field-error--postcode > span')).toHaveText('Please enter a valid UK postcode, using a space. For non-UK addresses, please use manual entry below.');
await page.locator('input#field-input--postcode').fill('comic relief');
await expect(page.locator('div#field-error--postcode > span')).toHaveText('Please enter a valid UK postcode, using a space. For non-UK addresses, please use manual entry below.');
await page.locator('input#field-input--postcode').fill('cro 7tp');
await expect(page.locator('div#field-error--postcode > span')).toHaveText('Please enter a valid UK postcode, using a space. For non-UK addresses, please use manual entry below.');
await page.close();
});

test('enter postcode but submit without selecting address should show error message', async ({ page }) => {
await page.locator('input#field-input--postcode').fill('SE1 7TP');
await page.locator('#postcode_button').click();
Expand All @@ -36,7 +38,7 @@ test.describe('Address validation', () => {
await expect(page.locator('div#field-error--addressSelect > span')).toHaveText('Please select your address');
await page.close();
});

test('clicking on manual address link should show address fields', async ({ page }) => {
await page.locator('input#field-input--postcode').fill('SE1 7TP');
await expect(page.locator('a[aria-describedby=field-error--addressDetails]')).toBeVisible();
Expand All @@ -48,17 +50,17 @@ test.describe('Address validation', () => {
await expect(page.locator('select#field-select--country')).toBeVisible();
await page.close();
});

test('validate address fields', async ({ page }) => {
await page.locator('input#field-input--postcode').fill('SE1 7TP');
await page.locator('a[aria-describedby=field-error--addressDetails]').click();

// Should see error message for address1 when inout with special characters is entered
await page.locator('#field-input--address1').fill('@£%3dComic Relief');
await expect(page.locator('#field-error--address1 > span')).toHaveText("This field only accepts alphanumeric characters and ' . - & _ /");
await page.locator('#field-input--town').fill(' Comic Relief');
await expect(page.locator('#field-error--town > span')).toHaveText("This field only accepts alphanumeric characters and ' . - & _ /");

await page.close();
});
});
2 changes: 0 additions & 2 deletions playwright-local/tests/submit/postcodeLookup.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ test.describe('Postcode validation', () => {
test('Postcode formatting errors', async ({ page }) => {
const postcodes = [
{ code: 'S E 1 7 T P', message: 'Please enter a valid UK postcode, using a space. For non-UK addresses, please use manual entry below.' },
{ code: 'se17tp', message: 'Please enter a valid UK postcode, using a space. For non-UK addresses, please use manual entry below.' },
{ code: 'SE17TP', message: 'Please enter a valid UK postcode, using a space. For non-UK addresses, please use manual entry below.' },
{ code: 'SE$%TP', message: 'Please enter a valid UK postcode, using a space. For non-UK addresses, please use manual entry below.' }
];

Expand Down
Loading
Loading