|
| 1 | +import { test, expect } from '@playwright/test' |
| 2 | + |
| 3 | +async function fillDate( |
| 4 | + page: import('@playwright/test').Page, |
| 5 | + name: string, |
| 6 | + date: { month: number; day: number; year: number }, |
| 7 | +) { |
| 8 | + const dateGroup = page.getByRole('group', { name }) |
| 9 | + await dateGroup.getByRole('spinbutton', { name: /month/i }).fill(String(date.month)) |
| 10 | + await dateGroup.getByRole('spinbutton', { name: /day/i }).fill(String(date.day)) |
| 11 | + await dateGroup.getByRole('spinbutton', { name: /year/i }).fill(String(date.year)) |
| 12 | +} |
| 13 | + |
| 14 | +test.describe('ContractorOnboardingFlow', () => { |
| 15 | + test('displays the contractor list and can navigate to add contractor', async ({ page }) => { |
| 16 | + await page.goto('/?flow=contractor-onboarding&companyId=123') |
| 17 | + |
| 18 | + // Page - Contractor List |
| 19 | + await page.getByRole('heading', { name: /contractor/i }).waitFor() |
| 20 | + |
| 21 | + // Verify list is visible |
| 22 | + await expect(page.getByRole('heading', { name: /contractor/i })).toBeVisible() |
| 23 | + |
| 24 | + // Click Add Contractor button |
| 25 | + const addButton = page.getByRole('button', { name: /add/i }) |
| 26 | + await addButton.waitFor() |
| 27 | + await addButton.click() |
| 28 | + |
| 29 | + // Page - Profile |
| 30 | + await page.getByRole('heading', { name: /profile|contractor/i }).waitFor() |
| 31 | + await expect(page.getByRole('heading', { name: /profile|contractor/i })).toBeVisible() |
| 32 | + }) |
| 33 | + |
| 34 | + test('can fill out the contractor profile form', async ({ page }) => { |
| 35 | + await page.goto('/?flow=contractor-onboarding&companyId=123') |
| 36 | + |
| 37 | + // Page - Contractor List |
| 38 | + await page.getByRole('heading', { name: /contractor/i }).waitFor() |
| 39 | + await page.getByRole('button', { name: /add/i }).click() |
| 40 | + |
| 41 | + // Page - Profile |
| 42 | + await page.getByRole('heading', { name: /profile|contractor/i }).waitFor() |
| 43 | + |
| 44 | + // Select contractor type - Individual |
| 45 | + const individualRadio = page.getByRole('radio', { name: /individual/i }) |
| 46 | + if (await individualRadio.isVisible().catch(() => false)) { |
| 47 | + await individualRadio.click() |
| 48 | + } |
| 49 | + |
| 50 | + // Fill profile information |
| 51 | + await page.getByLabel(/first name/i).fill('Jane') |
| 52 | + await page.getByLabel(/last name/i).fill('Contractor') |
| 53 | + |
| 54 | + // SSN field |
| 55 | + const ssnField = page.getByLabel(/social security/i) |
| 56 | + if (await ssnField.isVisible().catch(() => false)) { |
| 57 | + await ssnField.fill('456789012') |
| 58 | + } |
| 59 | + |
| 60 | + // Start date |
| 61 | + await fillDate(page, 'Start Date', { month: 1, day: 15, year: 2025 }) |
| 62 | + |
| 63 | + // Verify form is filled |
| 64 | + await expect(page.getByLabel(/first name/i)).toHaveValue('Jane') |
| 65 | + await expect(page.getByLabel(/last name/i)).toHaveValue('Contractor') |
| 66 | + |
| 67 | + // Create contractor |
| 68 | + await page.getByRole('button', { name: /create contractor/i }).click() |
| 69 | + |
| 70 | + // Should proceed to next step (Address) |
| 71 | + await expect(page.getByRole('heading', { name: /address/i })).toBeVisible({ timeout: 10000 }) |
| 72 | + }) |
| 73 | + |
| 74 | + test('can navigate back to contractor list from profile', async ({ page }) => { |
| 75 | + await page.goto('/?flow=contractor-onboarding&companyId=123') |
| 76 | + |
| 77 | + // Page - Contractor List |
| 78 | + await page.getByRole('heading', { name: /contractor/i }).waitFor() |
| 79 | + await page.getByRole('button', { name: /add/i }).click() |
| 80 | + |
| 81 | + // Page - Profile |
| 82 | + await page.getByRole('heading', { name: /profile|contractor/i }).waitFor() |
| 83 | + |
| 84 | + // Click back button |
| 85 | + const backButton = page.getByRole('button', { name: /back/i }) |
| 86 | + if (await backButton.isVisible().catch(() => false)) { |
| 87 | + await backButton.click() |
| 88 | + |
| 89 | + // Should return to contractor list |
| 90 | + await expect(page.getByRole('heading', { name: /contractor/i })).toBeVisible({ |
| 91 | + timeout: 5000, |
| 92 | + }) |
| 93 | + } |
| 94 | + }) |
| 95 | +}) |
0 commit comments