feat: complete server-backed six-lesson app and trial tooling
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
import type { Page } from '@playwright/test'
|
||||
|
||||
export function uniqueUsername(prefix = 'e2e'): string {
|
||||
return `${prefix}_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`
|
||||
}
|
||||
|
||||
export async function registerViaUi(
|
||||
page: Page,
|
||||
username: string,
|
||||
password: string,
|
||||
displayName?: string,
|
||||
) {
|
||||
await page.goto('/login')
|
||||
await page.getByRole('button', { name: 'ثبتنام کن' }).click()
|
||||
if (displayName) {
|
||||
await page.getByLabel('نام نمایشی').fill(displayName)
|
||||
}
|
||||
await page.getByLabel('نام کاربری').fill(username)
|
||||
await page.getByLabel('رمز عبور').fill(password)
|
||||
await page.getByRole('button', { name: 'ثبتنام' }).click()
|
||||
await page.waitForURL('/')
|
||||
}
|
||||
|
||||
export async function loginViaUi(page: Page, username: string, password: string) {
|
||||
await page.goto('/login')
|
||||
await page.getByLabel('نام کاربری').fill(username)
|
||||
await page.getByLabel('رمز عبور').fill(password)
|
||||
await page.getByRole('button', { name: 'ورود', exact: true }).click()
|
||||
await page.waitForURL('/')
|
||||
}
|
||||
|
||||
export async function logoutViaProfile(page: Page) {
|
||||
await page.goto('/profile')
|
||||
await page.getByRole('button', { name: 'خروج' }).click()
|
||||
await page.waitForURL('/login')
|
||||
}
|
||||
|
||||
export async function getAuthToken(page: Page): Promise<string | null> {
|
||||
return page.evaluate(() => localStorage.getItem('gold-land-auth-token'))
|
||||
}
|
||||
|
||||
export async function fetchMe(page: Page) {
|
||||
const token = await getAuthToken(page)
|
||||
if (!token) throw new Error('no auth token')
|
||||
const res = await page.request.get('/api/me', {
|
||||
headers: { authorization: `Bearer ${token}` },
|
||||
})
|
||||
if (!res.ok()) throw new Error(`GET /api/me failed: ${res.status()}`)
|
||||
return res.json() as Promise<{
|
||||
user: { xp: number; coins: number; name: string }
|
||||
progress: {
|
||||
mapLevels: Array<{ id: number; stars: number; status: string }>
|
||||
totalStars: number
|
||||
completedChallenges: string[]
|
||||
claimedRewards: string[]
|
||||
ownedItems: string[]
|
||||
}
|
||||
wallet: { cash: number; goldGrams: number }
|
||||
}>
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user