Files
gold_land_user/e2e/helpers/lesson.ts
T

48 lines
1.6 KiB
TypeScript
Raw Normal View History

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)
}