|
| 1 | +import { test, expect, type Page } from '@playwright/test' |
| 2 | +import { |
| 3 | + continueForm, |
| 4 | + formatName, |
| 5 | + getRandomDate, |
| 6 | + loginToV2 |
| 7 | +} from '../../helpers' |
| 8 | +import { faker } from '@faker-js/faker' |
| 9 | +import { CREDENTIALS } from '../../constants' |
| 10 | + |
| 11 | +import { ensureOutboxIsEmpty, selectAction } from '../../v2-utils' |
| 12 | + |
| 13 | +test.describe.serial('1. User conditional form flow', () => { |
| 14 | + let page: Page |
| 15 | + const declaration = { |
| 16 | + applicant: { |
| 17 | + name: { |
| 18 | + firstName: faker.person.firstName('male'), |
| 19 | + middleName: faker.person.firstName('male'), |
| 20 | + familyName: faker.person.lastName('male') |
| 21 | + }, |
| 22 | + gender: 'Male', |
| 23 | + birthDate: getRandomDate(0, 200) |
| 24 | + }, |
| 25 | + recommender: { |
| 26 | + name: { |
| 27 | + firstName: faker.person.firstName('male'), |
| 28 | + familyName: faker.person.lastName('male') |
| 29 | + }, |
| 30 | + id: '123456789' |
| 31 | + } |
| 32 | + } |
| 33 | + test.beforeAll(async ({ browser }) => { |
| 34 | + page = await browser.newPage() |
| 35 | + }) |
| 36 | + |
| 37 | + test.afterAll(async () => { |
| 38 | + await page.close() |
| 39 | + }) |
| 40 | + |
| 41 | + test.describe('1.1 Declaration started by FA', async () => { |
| 42 | + test.beforeAll(async () => { |
| 43 | + await loginToV2(page, CREDENTIALS.FIELD_AGENT) |
| 44 | + await page.click('#header-new-event') |
| 45 | + await page.getByLabel('Tennis club membership application').click() |
| 46 | + await page.getByRole('button', { name: 'Continue' }).click() |
| 47 | + }) |
| 48 | + |
| 49 | + test('1.1.1 Fill applicant details', async () => { |
| 50 | + await page |
| 51 | + .locator('#firstname') |
| 52 | + .fill(declaration.applicant.name.firstName) |
| 53 | + await page.locator('#surname').fill(declaration.applicant.name.familyName) |
| 54 | + |
| 55 | + await page.getByPlaceholder('dd').fill(declaration.applicant.birthDate.dd) |
| 56 | + await page.getByPlaceholder('mm').fill(declaration.applicant.birthDate.mm) |
| 57 | + await page |
| 58 | + .getByPlaceholder('yyyy') |
| 59 | + .fill(declaration.applicant.birthDate.yyyy) |
| 60 | + |
| 61 | + await page |
| 62 | + .getByLabel('Field shown when field agent is submitting application.') |
| 63 | + .click() |
| 64 | + |
| 65 | + await continueForm(page) |
| 66 | + }) |
| 67 | + |
| 68 | + test('1.1.2 Fill senior pass details', async () => { |
| 69 | + await page.locator('#senior-pass____id').fill('123123') |
| 70 | + |
| 71 | + await continueForm(page) |
| 72 | + }) |
| 73 | + |
| 74 | + test('1.1.3 Fill recommender details', async () => { |
| 75 | + await page |
| 76 | + .locator('#firstname') |
| 77 | + .fill(declaration.applicant.name.firstName) |
| 78 | + await page.locator('#surname').fill(declaration.applicant.name.familyName) |
| 79 | + await page.locator('#recommender____id').fill(declaration.recommender.id) |
| 80 | + |
| 81 | + await continueForm(page) |
| 82 | + }) |
| 83 | + |
| 84 | + test('1.1.4 Review details', async () => { |
| 85 | + await page |
| 86 | + .getByText('Field shown when field agent is submitting application.') |
| 87 | + .isVisible() |
| 88 | + |
| 89 | + await expect( |
| 90 | + page.getByTestId('row-value-applicant.isRecommendedByFieldAgent') |
| 91 | + ).toHaveText('Yes') |
| 92 | + }) |
| 93 | + |
| 94 | + test('1.1.5 Send for review', async () => { |
| 95 | + await page.getByRole('button', { name: 'Send for review' }).click() |
| 96 | + await expect(page.getByText('Send for review?')).toBeVisible() |
| 97 | + await page.getByRole('button', { name: 'Confirm' }).click() |
| 98 | + |
| 99 | + await ensureOutboxIsEmpty(page) |
| 100 | + |
| 101 | + await page.getByText('Sent for review').click() |
| 102 | + await expect( |
| 103 | + page.getByRole('button', { |
| 104 | + name: formatName(declaration.applicant.name) |
| 105 | + }) |
| 106 | + ).toBeVisible() |
| 107 | + }) |
| 108 | + |
| 109 | + test('1.1.6 Navigate to the declaration "read-only" page', async () => { |
| 110 | + await page |
| 111 | + .getByRole('button', { |
| 112 | + name: formatName(declaration.applicant.name) |
| 113 | + }) |
| 114 | + .click() |
| 115 | + |
| 116 | + await selectAction(page, 'View') |
| 117 | + |
| 118 | + await expect( |
| 119 | + page.getByText( |
| 120 | + 'Field shown when field agent is submitting application.' |
| 121 | + ) |
| 122 | + ).toBeVisible() |
| 123 | + }) |
| 124 | + }) |
| 125 | + |
| 126 | + test.describe('1.2 Declaration Review by RA', async () => { |
| 127 | + test('1.2.1 Navigate to the declaration "read-only" page', async () => { |
| 128 | + await loginToV2(page, CREDENTIALS.REGISTRATION_AGENT) |
| 129 | + await page.getByText('Ready for review').click() |
| 130 | + await page |
| 131 | + .getByRole('button', { |
| 132 | + name: formatName(declaration.applicant.name) |
| 133 | + }) |
| 134 | + .click() |
| 135 | + |
| 136 | + await selectAction(page, 'View') |
| 137 | + |
| 138 | + await expect( |
| 139 | + page.getByText( |
| 140 | + 'Field shown when field agent is submitting application.' |
| 141 | + ) |
| 142 | + ).not.toBeVisible() |
| 143 | + }) |
| 144 | + |
| 145 | + test('1.2.1 Navigate to the declaration "read-only" page', async () => { |
| 146 | + await loginToV2(page, CREDENTIALS.REGISTRATION_AGENT) |
| 147 | + await page.getByText('Ready for review').click() |
| 148 | + await page |
| 149 | + .getByRole('button', { |
| 150 | + name: formatName(declaration.applicant.name) |
| 151 | + }) |
| 152 | + .click() |
| 153 | + |
| 154 | + await selectAction(page, 'View') |
| 155 | + |
| 156 | + await expect( |
| 157 | + page.getByText( |
| 158 | + 'Field shown when field agent is submitting application.' |
| 159 | + ) |
| 160 | + ).not.toBeVisible() |
| 161 | + |
| 162 | + await page.getByTestId('exit-button').click() |
| 163 | + }) |
| 164 | + |
| 165 | + test('1.2.2 Navigate to the declaration "Review" page', async () => { |
| 166 | + await page.getByText('Ready for review').click() |
| 167 | + await page |
| 168 | + .getByRole('button', { |
| 169 | + name: formatName(declaration.applicant.name) |
| 170 | + }) |
| 171 | + .click() |
| 172 | + |
| 173 | + await selectAction(page, 'Review') |
| 174 | + |
| 175 | + await expect( |
| 176 | + page.getByText( |
| 177 | + 'Field shown when field agent is submitting application.' |
| 178 | + ) |
| 179 | + ).not.toBeVisible() |
| 180 | + }) |
| 181 | + }) |
| 182 | +}) |
0 commit comments