|
| 1 | +import { test, expect, generateTestUser } from '../../src/fixtures'; |
| 2 | + |
| 3 | +test.describe('Passwordless Registration', () => { |
| 4 | + test.describe('Registration Mode Toggle', () => { |
| 5 | + test('should show passwordless toggle on registration page', async ({ |
| 6 | + registerPage, |
| 7 | + }) => { |
| 8 | + await registerPage.goto(); |
| 9 | + await registerPage.page.waitForLoadState('networkidle'); |
| 10 | + |
| 11 | + // The toggle should be visible (WebAuthn is supported in Chromium) |
| 12 | + const toggle = registerPage.page.locator('#registrationModeToggle'); |
| 13 | + await expect(toggle).toBeVisible(); |
| 14 | + |
| 15 | + // Both mode buttons should be present |
| 16 | + const passwordBtn = registerPage.page.locator('#modePassword'); |
| 17 | + const passwordlessBtn = registerPage.page.locator('#modePasswordless'); |
| 18 | + await expect(passwordBtn).toBeVisible(); |
| 19 | + await expect(passwordlessBtn).toBeVisible(); |
| 20 | + |
| 21 | + // Password mode should be active by default |
| 22 | + await expect(passwordBtn).toHaveClass(/active/); |
| 23 | + await expect(passwordlessBtn).not.toHaveClass(/active/); |
| 24 | + }); |
| 25 | + |
| 26 | + test('should hide password fields when passwordless mode is selected', async ({ |
| 27 | + registerPage, |
| 28 | + }) => { |
| 29 | + await registerPage.goto(); |
| 30 | + await registerPage.page.waitForLoadState('networkidle'); |
| 31 | + |
| 32 | + // Password fields should be visible initially |
| 33 | + const passwordFields = registerPage.page.locator('#passwordFields'); |
| 34 | + await expect(passwordFields).toBeVisible(); |
| 35 | + await expect(registerPage.passwordInput).toBeVisible(); |
| 36 | + await expect(registerPage.confirmPasswordInput).toBeVisible(); |
| 37 | + |
| 38 | + // Click passwordless mode button |
| 39 | + await registerPage.page.locator('#modePasswordless').click(); |
| 40 | + |
| 41 | + // Password fields should be hidden |
| 42 | + await expect(passwordFields).toBeHidden(); |
| 43 | + |
| 44 | + // Passwordless info alert should be visible |
| 45 | + const passwordlessInfo = registerPage.page.locator('#passwordlessInfo'); |
| 46 | + await expect(passwordlessInfo).toBeVisible(); |
| 47 | + }); |
| 48 | + |
| 49 | + test('should show password fields when switching back to password mode', async ({ |
| 50 | + registerPage, |
| 51 | + }) => { |
| 52 | + await registerPage.goto(); |
| 53 | + await registerPage.page.waitForLoadState('networkidle'); |
| 54 | + |
| 55 | + // Switch to passwordless |
| 56 | + await registerPage.page.locator('#modePasswordless').click(); |
| 57 | + const passwordFields = registerPage.page.locator('#passwordFields'); |
| 58 | + await expect(passwordFields).toBeHidden(); |
| 59 | + |
| 60 | + // Switch back to password mode |
| 61 | + await registerPage.page.locator('#modePassword').click(); |
| 62 | + |
| 63 | + // Password fields should be visible again |
| 64 | + await expect(passwordFields).toBeVisible(); |
| 65 | + await expect(registerPage.passwordInput).toBeVisible(); |
| 66 | + await expect(registerPage.confirmPasswordInput).toBeVisible(); |
| 67 | + |
| 68 | + // Passwordless info alert should be hidden |
| 69 | + const passwordlessInfo = registerPage.page.locator('#passwordlessInfo'); |
| 70 | + await expect(passwordlessInfo).toBeHidden(); |
| 71 | + }); |
| 72 | + |
| 73 | + test('should toggle active state on mode buttons', async ({ |
| 74 | + registerPage, |
| 75 | + }) => { |
| 76 | + await registerPage.goto(); |
| 77 | + await registerPage.page.waitForLoadState('networkidle'); |
| 78 | + |
| 79 | + const passwordBtn = registerPage.page.locator('#modePassword'); |
| 80 | + const passwordlessBtn = registerPage.page.locator('#modePasswordless'); |
| 81 | + |
| 82 | + // Switch to passwordless |
| 83 | + await passwordlessBtn.click(); |
| 84 | + await expect(passwordlessBtn).toHaveClass(/active/); |
| 85 | + await expect(passwordBtn).not.toHaveClass(/active/); |
| 86 | + |
| 87 | + // Switch back to password |
| 88 | + await passwordBtn.click(); |
| 89 | + await expect(passwordBtn).toHaveClass(/active/); |
| 90 | + await expect(passwordlessBtn).not.toHaveClass(/active/); |
| 91 | + }); |
| 92 | + |
| 93 | + test('should keep name and email fields visible in passwordless mode', async ({ |
| 94 | + registerPage, |
| 95 | + }) => { |
| 96 | + await registerPage.goto(); |
| 97 | + await registerPage.page.waitForLoadState('networkidle'); |
| 98 | + |
| 99 | + // Switch to passwordless |
| 100 | + await registerPage.page.locator('#modePasswordless').click(); |
| 101 | + |
| 102 | + // Name and email fields should still be visible |
| 103 | + await expect(registerPage.firstNameInput).toBeVisible(); |
| 104 | + await expect(registerPage.lastNameInput).toBeVisible(); |
| 105 | + await expect(registerPage.emailInput).toBeVisible(); |
| 106 | + |
| 107 | + // Terms checkbox should still be visible |
| 108 | + await expect(registerPage.termsCheckbox).toBeVisible(); |
| 109 | + }); |
| 110 | + |
| 111 | + test('should remove required attribute from password fields in passwordless mode', async ({ |
| 112 | + registerPage, |
| 113 | + }) => { |
| 114 | + await registerPage.goto(); |
| 115 | + await registerPage.page.waitForLoadState('networkidle'); |
| 116 | + |
| 117 | + // Password fields should be required initially |
| 118 | + await expect(registerPage.passwordInput).toHaveAttribute('required', ''); |
| 119 | + await expect(registerPage.confirmPasswordInput).toHaveAttribute('required', ''); |
| 120 | + |
| 121 | + // Switch to passwordless |
| 122 | + await registerPage.page.locator('#modePasswordless').click(); |
| 123 | + |
| 124 | + // Password fields should no longer be required |
| 125 | + await expect(registerPage.passwordInput).not.toHaveAttribute('required', ''); |
| 126 | + await expect(registerPage.confirmPasswordInput).not.toHaveAttribute('required', ''); |
| 127 | + |
| 128 | + // Switch back - should be required again |
| 129 | + await registerPage.page.locator('#modePassword').click(); |
| 130 | + await expect(registerPage.passwordInput).toHaveAttribute('required', ''); |
| 131 | + await expect(registerPage.confirmPasswordInput).toHaveAttribute('required', ''); |
| 132 | + }); |
| 133 | + }); |
| 134 | + |
| 135 | + test.describe('Passwordless Form Submission', () => { |
| 136 | + test('should send passwordless registration request to correct endpoint', async ({ |
| 137 | + page, |
| 138 | + registerPage, |
| 139 | + }) => { |
| 140 | + await registerPage.goto(); |
| 141 | + await page.waitForLoadState('networkidle'); |
| 142 | + |
| 143 | + // Switch to passwordless mode |
| 144 | + await page.locator('#modePasswordless').click(); |
| 145 | + |
| 146 | + // Fill name and email |
| 147 | + await registerPage.firstNameInput.fill('Test'); |
| 148 | + await registerPage.lastNameInput.fill('User'); |
| 149 | + await registerPage.emailInput.fill('test-pwless-endpoint@example.com'); |
| 150 | + await registerPage.acceptTerms(); |
| 151 | + |
| 152 | + // Intercept the fetch request to verify it goes to the right endpoint |
| 153 | + const requestPromise = page.waitForRequest( |
| 154 | + request => request.url().includes('/user/registration/passwordless') && request.method() === 'POST' |
| 155 | + ); |
| 156 | + |
| 157 | + await registerPage.submit(); |
| 158 | + |
| 159 | + // Verify the request was sent to the passwordless endpoint |
| 160 | + const request = await requestPromise; |
| 161 | + expect(request.url()).toContain('/user/registration/passwordless'); |
| 162 | + |
| 163 | + // Verify the payload contains only name and email (no password) |
| 164 | + const postData = JSON.parse(request.postData() || '{}'); |
| 165 | + expect(postData.firstName).toBe('Test'); |
| 166 | + expect(postData.lastName).toBe('User'); |
| 167 | + expect(postData.email).toBe('test-pwless-endpoint@example.com'); |
| 168 | + expect(postData.password).toBeUndefined(); |
| 169 | + expect(postData.matchingPassword).toBeUndefined(); |
| 170 | + }); |
| 171 | + |
| 172 | + test('should send standard registration request when in password mode', async ({ |
| 173 | + page, |
| 174 | + registerPage, |
| 175 | + }) => { |
| 176 | + await registerPage.goto(); |
| 177 | + await page.waitForLoadState('networkidle'); |
| 178 | + |
| 179 | + // Stay in password mode (default) |
| 180 | + await registerPage.fillForm('Test', 'User', 'test-standard@example.com', 'Test@Pass123!'); |
| 181 | + await registerPage.acceptTerms(); |
| 182 | + |
| 183 | + // Intercept the fetch request |
| 184 | + const requestPromise = page.waitForRequest( |
| 185 | + request => request.url().includes('/user/registration') && request.method() === 'POST' |
| 186 | + ); |
| 187 | + |
| 188 | + await registerPage.submit(); |
| 189 | + |
| 190 | + // Verify the request goes to the standard endpoint (not passwordless) |
| 191 | + const request = await requestPromise; |
| 192 | + expect(request.url()).not.toContain('passwordless'); |
| 193 | + }); |
| 194 | + }); |
| 195 | +}); |
0 commit comments