guanghu/tests/smoke/better-sync-error-ux.spec.ts
Guanghu Domestic Migration 9b41d51231
Some checks are pending
Auto-update PR branches / Update open PR branches (push) Waiting to run
CI / Frontend Static Quality Checks (push) Waiting to run
CI / Frontend Tests & Coverage (push) Waiting to run
CI / Rust Tests & Quality Checks (push) Waiting to run
CI / Linux build verification (push) Waiting to run
Deploy docs / Build VitePress site (push) Waiting to run
Deploy docs / Deploy to GitHub Pages (push) Blocked by required conditions
Release (Alpha) / Compute alpha version (push) Waiting to run
Release (Alpha) / Build release artifacts (push) Blocked by required conditions
Release (Alpha) / GitHub Release (alpha) (push) Blocked by required conditions
Release (Alpha) / Update docs and release pages (push) Blocked by required conditions
chore: import sanitized domestic snapshot for REPO-004
Source snapshot: 514ab1975951d94342ea38e64101d5a0f1c51c77
2026-07-17 15:55:28 +08:00

81 lines
3.2 KiB
TypeScript

import { test, expect } from '@playwright/test'
import { openCommandPalette, executeCommand } from './helpers'
test.describe('Sync error UX — actionable push error messages', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/')
await page.waitForLoadState('networkidle')
await page.waitForFunction(() => {
const handlers = Reflect.get(globalThis, '__mockHandlers')
return Boolean(handlers && typeof handlers === 'object' && Reflect.get(handlers, 'git_push'))
})
await expect(page.getByRole('heading', { name: 'Inbox' })).toBeVisible()
})
test('rejected push shows actionable "Pull first" message in toast', async ({ page }) => {
// Override git_push mock to return a rejected result
await page.evaluate(() => {
const handlers = Reflect.get(globalThis, '__mockHandlers')
if (!handlers || typeof handlers !== 'object') throw new Error('Mock handlers were not installed')
Reflect.set(handlers, 'git_push', () => ({
status: 'rejected',
message: 'Push rejected: remote has new commits. Pull first, then push.',
}))
})
// Open commit dialog via command palette
await openCommandPalette(page)
await executeCommand(page, 'Commit & Push')
// Wait for the CommitDialog textarea
const textarea = page.locator('textarea[placeholder="Commit message..."]')
await textarea.waitFor({ timeout: 5000 })
await textarea.fill('test commit')
// Click the "Commit & Push" button in the dialog
const commitButton = page.getByRole('button', { name: 'Commit & Push' })
await commitButton.click()
// Verify the toast shows the actionable rejection message
const toast = page.locator('.fixed.bottom-8')
await expect(toast).toContainText('Pull first', { timeout: 5000 })
})
test('auth error push shows authentication message in toast', async ({ page }) => {
await page.evaluate(() => {
const handlers = Reflect.get(globalThis, '__mockHandlers')
if (!handlers || typeof handlers !== 'object') throw new Error('Mock handlers were not installed')
Reflect.set(handlers, 'git_push', () => ({
status: 'auth_error',
message: 'Push failed: authentication error. Check your credentials.',
}))
})
await openCommandPalette(page)
await executeCommand(page, 'Commit & Push')
const textarea = page.locator('textarea[placeholder="Commit message..."]')
await textarea.waitFor({ timeout: 5000 })
await textarea.fill('test commit')
await page.getByRole('button', { name: 'Commit & Push' }).click()
const toast = page.locator('.fixed.bottom-8')
await expect(toast).toContainText('authentication error', { timeout: 5000 })
})
test('successful push shows normal success message', async ({ page }) => {
await openCommandPalette(page)
await executeCommand(page, 'Commit & Push')
const textarea = page.locator('textarea[placeholder="Commit message..."]')
await textarea.waitFor({ timeout: 5000 })
await textarea.fill('test commit')
await page.getByRole('button', { name: 'Commit & Push' }).click()
const toast = page.locator('.fixed.bottom-8')
await expect(toast).toContainText('Committed and pushed', { timeout: 5000 })
})
})