skillhub/web/e2e/profile-settings.spec.ts
huishi3 20b5accf6e test(e2e): use exact text match for profile field labels
getByText('Display Name') is a substring match by default, so it also
matched the description paragraph "Manage your display name and
personal information." (strict mode violation: resolved to 2 elements).
Use { exact: true } to match the field label only.
2026-05-08 07:40:26 -07:00

60 lines
2.3 KiB
TypeScript

import { expect, test } from '@playwright/test'
import { setEnglishLocale } from './helpers/auth-fixtures'
import { registerSession } from './helpers/session'
test.describe('Profile Settings (Real API)', () => {
test.beforeEach(async ({ page }, testInfo) => {
await setEnglishLocale(page)
await registerSession(page, testInfo)
})
test('TC_PROFILE_001: displays profile settings page with user info fields', async ({ page }) => {
await page.goto('/settings/profile')
await expect(page.getByRole('heading', { name: 'Profile Settings' })).toBeVisible()
await expect(page.getByText('Display Name', { exact: true })).toBeVisible()
await expect(page.getByText('Email', { exact: true })).toBeVisible()
})
test('TC_PROFILE_002: edit button toggles to save and cancel', async ({ page }) => {
await page.goto('/settings/profile')
const editButton = page.getByRole('button', { name: 'Edit' })
const hasEdit = await editButton.isVisible().catch(() => false)
if (!hasEdit) return
await editButton.click()
await expect(page.getByRole('button', { name: 'Save' })).toBeVisible()
await expect(page.getByRole('button', { name: 'Cancel' })).toBeVisible()
})
test('TC_PROFILE_003: cancel edit returns to view mode', async ({ page }) => {
await page.goto('/settings/profile')
const editButton = page.getByRole('button', { name: 'Edit' })
const hasEdit = await editButton.isVisible().catch(() => false)
if (!hasEdit) return
await editButton.click()
await page.getByRole('button', { name: 'Cancel' }).click()
await expect(page.getByRole('button', { name: 'Edit' })).toBeVisible()
})
test('TC_PROFILE_004: validates display name minimum length', async ({ page }) => {
await page.goto('/settings/profile')
const editButton = page.getByRole('button', { name: 'Edit' })
const hasEdit = await editButton.isVisible().catch(() => false)
if (!hasEdit) return
await editButton.click()
const nameInput = page.getByLabel('Display Name')
const hasInput = await nameInput.isVisible().catch(() => false)
if (!hasInput) return
await nameInput.clear()
await nameInput.fill('a')
await page.getByRole('button', { name: 'Save' }).click()
await expect(page.getByText(/2.*32|length|characters/i)).toBeVisible()
})
})