Files
gold_land_user/e2e/helpers/lesson.ts
T
safavimohadeseh78andCursor e3f0457dc9
Frontend CI / unit (test, type-check, build) (push) Successful in 1m11s
Frontend CI / browser E2E (frontend + pinned backend) (push) Failing after 2m48s
feat: complete server-backed six-lesson app and trial tooling
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-12 14:40:37 +03:30

48 lines
1.6 KiB
TypeScript

import type { Page } from '@playwright/test'
import { level1ChoiceLabels } from '../fixtures/level1-answers'
export async function openLevel1FromMap(page: Page) {
await page.goto('/map')
await page.getByRole('heading', { name: 'سرزمین طلا' }).waitFor()
await page.getByRole('button', { name: /مرحله 1:/ }).click()
await page.getByRole('button', { name: 'شروع درس' }).click()
await page.waitForURL(/\/gold-land\/levels\/1/)
await page.getByText('در حال بارگذاری').waitFor({ state: 'detached', timeout: 30_000 })
}
export async function playCurrentLessonSteps(page: Page) {
const pending = [...level1ChoiceLabels]
for (let step = 0; step < 50; step++) {
if (await page.getByText('امتیاز').isVisible().catch(() => false)) return
const finish = page.getByRole('button', { name: 'اتمام درس' })
if ((await finish.isVisible().catch(() => false)) && (await finish.isEnabled())) {
await finish.click()
await page.getByText('امتیاز').waitFor({ timeout: 30_000 })
return
}
if (pending.length > 0) {
const label = pending[0]!
const chip = page.getByRole('button', { name: label, exact: true })
if (await chip.isVisible().catch(() => false)) {
await chip.click()
pending.shift()
}
}
const next = page.getByRole('button', { name: 'بعدی' })
if (await next.isEnabled().catch(() => false)) {
await next.click()
}
}
throw new Error('lesson steps did not complete')
}
export async function completeLevel1Lesson(page: Page) {
await openLevel1FromMap(page)
await playCurrentLessonSteps(page)
}