|
| 1 | +import { expect, test } from '@playwright/test' |
| 2 | + |
| 3 | +const TEST_USER = { |
| 4 | + name: 'E2E Test User', |
| 5 | + email: `e2etest${Date.now()}@gmail.com`, |
| 6 | + password: 'TestPass1!', |
| 7 | +} |
| 8 | + |
| 9 | +test.describe('Sign Up Flow', () => { |
| 10 | + test('displays signup form elements', async ({ page }) => { |
| 11 | + await page.goto('/signup') |
| 12 | + await expect( |
| 13 | + page.getByRole('heading', { name: /Create an account/i }) |
| 14 | + ).toBeVisible() |
| 15 | + await expect(page.getByPlaceholder('Monkey D Luffy')).toBeVisible() |
| 16 | + await expect(page.getByPlaceholder('example@gmail.com')).toBeVisible() |
| 17 | + }) |
| 18 | + |
| 19 | + test('shows validation error for empty fields', async ({ page }) => { |
| 20 | + await page.goto('/signup') |
| 21 | + await page.getByRole('button', { name: /Create Account/i }).click() |
| 22 | + await expect(page.getByText('All fields are required')).toBeVisible() |
| 23 | + }) |
| 24 | + |
| 25 | + test('shows validation for non-gmail email', async ({ page }) => { |
| 26 | + await page.goto('/signup') |
| 27 | + await page.getByPlaceholder('example@gmail.com').fill('test@yahoo.com') |
| 28 | + await expect( |
| 29 | + page.getByText('Enter a valid Gmail address') |
| 30 | + ).toBeVisible() |
| 31 | + }) |
| 32 | + |
| 33 | + test('shows password strength indicator', async ({ page }) => { |
| 34 | + await page.goto('/signup') |
| 35 | + await page.getByPlaceholder('example@gmail.com').fill('test@gmail.com') |
| 36 | + await page.getByPlaceholder('••••••••').first().fill('weak') |
| 37 | + await expect(page.getByText('Weak')).toBeVisible() |
| 38 | + |
| 39 | + await page.getByPlaceholder('••••••••').first().fill('Medium1pass') |
| 40 | + await expect(page.getByText('Medium')).toBeVisible() |
| 41 | + |
| 42 | + await page.getByPlaceholder('••••••••').first().fill('Strong1!') |
| 43 | + await expect(page.getByText('Strong')).toBeVisible() |
| 44 | + }) |
| 45 | + |
| 46 | + test('shows password mismatch error', async ({ page }) => { |
| 47 | + await page.goto('/signup') |
| 48 | + await page.getByPlaceholder('Monkey D Luffy').fill(TEST_USER.name) |
| 49 | + await page.getByPlaceholder('example@gmail.com').fill(TEST_USER.email) |
| 50 | + await page.getByPlaceholder('••••••••').first().fill(TEST_USER.password) |
| 51 | + await page.getByPlaceholder('••••••••').last().fill('DifferentPass1!') |
| 52 | + await page.getByRole('button', { name: /Create Account/i }).click() |
| 53 | + await expect(page.getByText('Passwords do not match')).toBeVisible() |
| 54 | + }) |
| 55 | + |
| 56 | + test('successful signup redirects to dashboard', async ({ page }) => { |
| 57 | + await page.goto('/signup') |
| 58 | + await page.getByPlaceholder('Monkey D Luffy').fill(TEST_USER.name) |
| 59 | + await page.getByPlaceholder('example@gmail.com').fill(TEST_USER.email) |
| 60 | + await page.getByPlaceholder('••••••••').first().fill(TEST_USER.password) |
| 61 | + await page.getByPlaceholder('••••••••').last().fill(TEST_USER.password) |
| 62 | + await page.getByRole('button', { name: /Create Account/i }).click() |
| 63 | + await page.waitForURL('**/dashboard', { timeout: 15000 }) |
| 64 | + await expect(page).toHaveURL(/\/dashboard/) |
| 65 | + }) |
| 66 | + |
| 67 | + test('has link to sign in page', async ({ page }) => { |
| 68 | + await page.goto('/signup') |
| 69 | + await page.getByRole('link', { name: /Sign in/i }).click() |
| 70 | + await expect(page).toHaveURL(/\/signin/) |
| 71 | + }) |
| 72 | +}) |
| 73 | + |
| 74 | +test.describe('Sign In Flow', () => { |
| 75 | + test('displays signin form elements', async ({ page }) => { |
| 76 | + await page.goto('/signin') |
| 77 | + await expect( |
| 78 | + page.getByRole('heading', { name: /Sign in/i }) |
| 79 | + ).toBeVisible() |
| 80 | + await expect( |
| 81 | + page.getByPlaceholder('name@example.com') |
| 82 | + ).toBeVisible() |
| 83 | + await expect(page.getByPlaceholder('••••••••')).toBeVisible() |
| 84 | + }) |
| 85 | + |
| 86 | + test('shows error for empty fields', async ({ page }) => { |
| 87 | + await page.goto('/signin') |
| 88 | + await page.getByRole('button', { name: 'Sign In', exact: true }).click() |
| 89 | + await expect(page.getByText('All fields are required')).toBeVisible() |
| 90 | + }) |
| 91 | + |
| 92 | + test('shows error for invalid email format', async ({ page }) => { |
| 93 | + await page.goto('/signin') |
| 94 | + await page.getByPlaceholder('name@example.com').fill('notvalid@x') |
| 95 | + await page.getByPlaceholder('••••••••').fill('password123') |
| 96 | + await page.getByRole('button', { name: 'Sign In', exact: true }).click() |
| 97 | + await expect(page.getByText('Enter a valid email')).toBeVisible() |
| 98 | + }) |
| 99 | + |
| 100 | + test('shows error for wrong credentials', async ({ page }) => { |
| 101 | + await page.goto('/signin') |
| 102 | + await page.getByPlaceholder('name@example.com').fill('wrong@example.com') |
| 103 | + await page.getByPlaceholder('••••••••').fill('WrongPass1!') |
| 104 | + await page.getByRole('button', { name: 'Sign In', exact: true }).click() |
| 105 | + await expect( |
| 106 | + page.getByText(/Invalid|error|not found/i) |
| 107 | + ).toBeVisible({ timeout: 10000 }) |
| 108 | + }) |
| 109 | + |
| 110 | + test('has link to sign up page', async ({ page }) => { |
| 111 | + await page.goto('/signin') |
| 112 | + await page.getByRole('link', { name: /Sign up/i }).click() |
| 113 | + await expect(page).toHaveURL(/\/signup/) |
| 114 | + }) |
| 115 | + |
| 116 | + test('has Google sign in button', async ({ page }) => { |
| 117 | + await page.goto('/signin') |
| 118 | + await expect( |
| 119 | + page.getByRole('button', { name: /Sign in with Google/i }) |
| 120 | + ).toBeVisible() |
| 121 | + }) |
| 122 | +}) |
0 commit comments