|
| 1 | +import { test, expect } from '../../fixtures/app'; |
| 2 | +import { Join } from '../../fixtures/pages/Join'; |
| 3 | +import { Step1 } from '../../fixtures/pages/Join/Step1'; |
| 4 | +import { Step2 } from '../../fixtures/pages/Join/Step2'; |
| 5 | +import { Step3 } from '../../fixtures/pages/Join/Step3'; |
| 6 | + |
| 7 | +test.describe('The Join page first step - case new user', () => { |
| 8 | + let join: Join; |
| 9 | + let step1: Step1; |
| 10 | + let step2: Step2; |
| 11 | + |
| 12 | + test.beforeEach(async ({ page }) => { |
| 13 | + join = new Join(page); |
| 14 | + await join.notLoggedIn(); |
| 15 | + step1 = new Step1(page); |
| 16 | + step2 = new Step2(page); |
| 17 | + await join.open(); |
| 18 | + }); |
| 19 | + |
| 20 | + test('display a form with user email and password input, a CTA to go to the next step', async () => { |
| 21 | + await expect(step1.elements().container()).toBeVisible(); |
| 22 | + await expect(step1.elements().emailInput()).toBeVisible(); |
| 23 | + await expect(step1.elements().passwordInput()).toBeVisible(); |
| 24 | + await expect(step1.elements().buttonGoToStep2()).toBeVisible(); |
| 25 | + }); |
| 26 | + |
| 27 | + test('the password input check if the password is strong enough', async ({ |
| 28 | + page, |
| 29 | + i18n, |
| 30 | + }) => { |
| 31 | + await step1.elements().buttonGoToStep2().click(); |
| 32 | + await expect(step1.elements().passwordError()).toHaveText( |
| 33 | + i18n.t('SIGNUP_FORM_PASSWORD_IS_A_REQUIRED_FIELD') |
| 34 | + ); |
| 35 | + |
| 36 | + await expect(step1.elements().passwordRequirements()).toBeVisible(); |
| 37 | + |
| 38 | + await step1.fillPassword('weak'); |
| 39 | + await expect( |
| 40 | + page.getByText( |
| 41 | + i18n.t('SIGNUP_FORM_PASSWORD_MUST_BE_AT_LEAST_6_CHARACTER_LONG') |
| 42 | + ) |
| 43 | + ).toBeVisible(); |
| 44 | + |
| 45 | + await step1.fillPassword('weakpassword'); |
| 46 | + await expect( |
| 47 | + page.getByText( |
| 48 | + i18n.t('SIGNUP_FORM_PASSWORD_MUST_CONTAIN_AT_LEAST_A_NUMBER') |
| 49 | + ) |
| 50 | + ).toBeVisible(); |
| 51 | + |
| 52 | + await step1.fillPassword('weakpassword123'); |
| 53 | + await expect( |
| 54 | + page.getByText( |
| 55 | + i18n.t('SIGNUP_FORM_PASSWORD_MUST_CONTAIN_AT_LEAST_AN_UPPERCASE_LETTER') |
| 56 | + ) |
| 57 | + ).toBeVisible(); |
| 58 | + |
| 59 | + await step1.fillPassword('WEAKPASSWORD123'); |
| 60 | + await expect( |
| 61 | + page.getByText( |
| 62 | + i18n.t('SIGNUP_FORM_PASSWORD_MUST_CONTAIN_AT_LEAST_A_LOWERCASE_LETTER') |
| 63 | + ) |
| 64 | + ).toBeVisible(); |
| 65 | + |
| 66 | + await step1.fillValidPassword(); |
| 67 | + await expect(page.getByTestId('message-error-password')).not.toBeVisible(); |
| 68 | + }); |
| 69 | + |
| 70 | + test('the email input check if the email is valid', async ({ |
| 71 | + page, |
| 72 | + i18n, |
| 73 | + }) => { |
| 74 | + await step1.elements().buttonGoToStep2().click(); |
| 75 | + await expect(step1.elements().emailError()).toHaveText( |
| 76 | + i18n.t('SIGNUP_FORM_EMAIL_IS_REQUIRED') |
| 77 | + ); |
| 78 | + await step1.fillEmail('invalid-email'); |
| 79 | + await expect( |
| 80 | + page.getByText(i18n.t('SIGNUP_FORM_EMAIL_MUST_BE_A_VALID_EMAIL')) |
| 81 | + ).toBeVisible(); |
| 82 | + |
| 83 | + await step1.fillRegisteredEmail(); |
| 84 | + await expect( |
| 85 | + page.getByText(i18n.t('SIGNUP_FORM_EMAIL_ALREADY_TAKEN')) |
| 86 | + ).toBeVisible(); |
| 87 | + |
| 88 | + await step1.fillValidEmail(); |
| 89 | + await expect(page.getByTestId('message-error-email')).not.toBeVisible(); |
| 90 | + }); |
| 91 | + |
| 92 | + test('when the user click the next step cta we validate current inputs and if ok goes to the next step', async () => { |
| 93 | + await step1.goToNextStep(); |
| 94 | + await expect(step1.elements().container()).not.toBeVisible(); |
| 95 | + await expect(step2.elements().container()).toBeVisible(); |
| 96 | + }); |
| 97 | + test('display two links to go to app.unguess and a link to terms and conditions', async () => {}); |
| 98 | +}); |
| 99 | + |
| 100 | +test.describe('The Join page second step', () => { |
| 101 | + let join: Join; |
| 102 | + let step1: Step1; |
| 103 | + let step2: Step2; |
| 104 | + let step3: Step3; |
| 105 | + |
| 106 | + test.beforeEach(async ({ page }) => { |
| 107 | + join = new Join(page); |
| 108 | + await join.notLoggedIn(); |
| 109 | + step1 = new Step1(page); |
| 110 | + step2 = new Step2(page); |
| 111 | + step3 = new Step3(page); |
| 112 | + |
| 113 | + await step2.mockGetRoles(); |
| 114 | + await step2.mockGetCompanySizes(); |
| 115 | + await join.open(); |
| 116 | + await step1.goToNextStep(); |
| 117 | + }); |
| 118 | + test('display required inputs for name, surname, job role and company size dropdowns populated from api userRole and companySize', async ({ |
| 119 | + i18n, |
| 120 | + }) => { |
| 121 | + await expect(step2.elements().nameInput()).toBeVisible(); |
| 122 | + await expect(step2.elements().surnameInput()).toBeVisible(); |
| 123 | + await expect(step2.elements().roleSelect()).toBeVisible(); |
| 124 | + await step2.elements().roleSelect().click(); |
| 125 | + await expect(step2.elements().roleSelectOptions()).toHaveCount(3); |
| 126 | + |
| 127 | + await expect(step2.elements().companySizeSelect()).toBeVisible(); |
| 128 | + await step2.elements().companySizeSelect().click(); |
| 129 | + await expect(step2.elements().companySizeSelectOptions()).toHaveCount(3); |
| 130 | + |
| 131 | + await step2.elements().buttonGoToStep3().click(); |
| 132 | + |
| 133 | + await expect(step2.elements().nameError()).toHaveText( |
| 134 | + i18n.t('SIGNUP_FORM_NAME_IS_REQUIRED') |
| 135 | + ); |
| 136 | + await expect(step2.elements().surnameError()).toHaveText( |
| 137 | + i18n.t('SIGNUP_FORM_SURNAME_IS_REQUIRED') |
| 138 | + ); |
| 139 | + await expect(step2.elements().roleSelectError()).toHaveText( |
| 140 | + i18n.t('SIGNUP_FORM_ROLE_IS_REQUIRED') |
| 141 | + ); |
| 142 | + await expect(step2.elements().companySizeSelectError()).toHaveText( |
| 143 | + i18n.t('SIGNUP_FORM_COMPANY_SIZE_IS_REQUIRED') |
| 144 | + ); |
| 145 | + |
| 146 | + await step2.fillValidFields(); |
| 147 | + await expect(step2.elements().nameError()).not.toBeVisible(); |
| 148 | + await expect(step2.elements().surnameError()).not.toBeVisible(); |
| 149 | + await expect(step2.elements().roleSelectError()).not.toBeVisible(); |
| 150 | + }); |
| 151 | + test('display back and next navigation, clicking on next validate this step and goes to step 3', async () => { |
| 152 | + await expect(step2.elements().buttonBackToStep1()).toBeVisible(); |
| 153 | + await expect(step2.elements().buttonGoToStep3()).toBeVisible(); |
| 154 | + await step2.goToNextStep(); |
| 155 | + await expect(step2.elements().container()).not.toBeVisible(); |
| 156 | + await expect(step3.elements().container()).toBeVisible(); |
| 157 | + }); |
| 158 | +}); |
| 159 | + |
| 160 | +test.describe('The Join page third step', () => { |
| 161 | + let join: Join; |
| 162 | + let step1: Step1; |
| 163 | + let step2: Step2; |
| 164 | + let step3: Step3; |
| 165 | + |
| 166 | + test.beforeEach(async ({ page }) => { |
| 167 | + join = new Join(page); |
| 168 | + await join.notLoggedIn(); |
| 169 | + step1 = new Step1(page); |
| 170 | + step2 = new Step2(page); |
| 171 | + step3 = new Step3(page); |
| 172 | + |
| 173 | + await join.open(); |
| 174 | + await join.mockPostNewUser(); |
| 175 | + await step1.goToNextStep(); |
| 176 | + await step2.goToNextStep(); |
| 177 | + }); |
| 178 | + test('display a required text input for the workspace name and a back button to return to step 2', async () => { |
| 179 | + await expect(step3.elements().workspaceInput()).toBeVisible(); |
| 180 | + await expect(step3.elements().buttonBackToStep2()).toBeVisible(); |
| 181 | + await step3.elements().buttonBackToStep2().click(); |
| 182 | + await expect(step3.elements().container()).not.toBeVisible(); |
| 183 | + await expect(step2.elements().container()).toBeVisible(); |
| 184 | + }); |
| 185 | + test('display a submit-button, clicking on submit-button validate the whole form and calls the api post', async ({ |
| 186 | + page, |
| 187 | + i18n, |
| 188 | + }) => { |
| 189 | + const postPromise = page.waitForResponse( |
| 190 | + (response) => |
| 191 | + /\/api\/users/.test(response.url()) && |
| 192 | + response.status() === 200 && |
| 193 | + response.request().method() === 'POST' |
| 194 | + ); |
| 195 | + await step3.elements().buttonSubmit().click(); |
| 196 | + await expect(step3.elements().workspaceError()).toHaveText( |
| 197 | + i18n.t('SIGNUP_FORM_WORKSPACE_IS_REQUIRED') |
| 198 | + ); |
| 199 | + await step3.fillValidWorkspace(); |
| 200 | + await expect(step3.elements().workspaceError()).not.toBeVisible(); |
| 201 | + await step3.elements().buttonSubmit().click(); |
| 202 | + const response = await postPromise; |
| 203 | + const data = response.request().postDataJSON(); |
| 204 | + expect(data).toEqual( |
| 205 | + expect.objectContaining({ |
| 206 | + type: 'new', |
| 207 | + email: 'new.user@example.com', |
| 208 | + password: 'ValidPassword123', |
| 209 | + name: step2.name, |
| 210 | + surname: step2.surname, |
| 211 | + roleId: step2.roleId, |
| 212 | + companySizeId: step2.companySizeId, |
| 213 | + workspace: step3.workspace, |
| 214 | + }) |
| 215 | + ); |
| 216 | + }); |
| 217 | +}); |
0 commit comments