feat: complete the thirteen-stage learning experience and E2E journey
Play levels 7-13 in the app and pin E2E to the local thirteen-stage backend commit. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,149 @@
|
||||
import { test, expect } from '@playwright/test'
|
||||
import { fetchMe, registerViaUi, uniqueUsername } from './helpers/auth'
|
||||
|
||||
const lessons: Record<number, Array<Record<string, unknown>>> = {
|
||||
1: [
|
||||
{ questionId: 'money-q1', answerId: 'option-a' },
|
||||
{ questionId: 'money-q2', answerId: 'true' },
|
||||
{ questionId: 'money-q3', answerId: 'option-a' },
|
||||
{ questionId: 'money-q4', answerId: 'true' },
|
||||
{ questionId: 'money-q5', answerId: 'option-b' },
|
||||
],
|
||||
2: [
|
||||
{ questionId: 'saving-q1', answerId: 'option-b' },
|
||||
{ questionId: 'saving-q2', answerId: 'true' },
|
||||
{ questionId: 'saving-q3', answerId: 'option-a' },
|
||||
{ questionId: 'saving-q4', answerId: 'true' },
|
||||
{ questionId: 'saving-q5', answerId: 'option-a' },
|
||||
],
|
||||
3: [
|
||||
{ questionId: 'needs-q1', answerId: 'option-a' },
|
||||
{ questionId: 'needs-q2', answerId: 'true' },
|
||||
{ questionId: 'needs-q3', orderedItemIds: ['water', 'food', 'medicine', 'shoes', 'toy', 'crown'] },
|
||||
{ questionId: 'needs-q4', answerId: 'option-a' },
|
||||
{ questionId: 'needs-q5', answerId: 'true' },
|
||||
],
|
||||
4: [
|
||||
{ questionId: 'gold-q1', answerId: 'option-a' },
|
||||
{ questionId: 'gold-q2', answerId: 'true' },
|
||||
{ questionId: 'gold-q3', answerId: 'option-a' },
|
||||
{ questionId: 'gold-q4', answerId: 'false' },
|
||||
{ questionId: 'gold-q5', answerId: 'option-b' },
|
||||
],
|
||||
5: [
|
||||
{ questionId: 'market-q1', answerId: 'option-a' },
|
||||
{ questionId: 'market-q2', answerId: 'false' },
|
||||
{ questionId: 'market-q3', answerId: 'option-a' },
|
||||
{ questionId: 'market-q4', answerId: 'true' },
|
||||
{ questionId: 'market-q5', answerId: 'option-b' },
|
||||
],
|
||||
6: [
|
||||
{ questionId: 'inflation-q1', answerId: 'option-b' },
|
||||
{ questionId: 'inflation-q2', answerId: 'true' },
|
||||
{ questionId: 'inflation-q3', answerId: 'option-a' },
|
||||
{ questionId: 'inflation-q4', answerId: 'false' },
|
||||
{ questionId: 'inflation-q5', answerId: 'option-b' },
|
||||
],
|
||||
}
|
||||
|
||||
async function answerCompound(page: import('@playwright/test').Page) {
|
||||
const choices = [
|
||||
'رشد دوره بعد بر موجودی جدید، شامل رشد قبلی، محاسبه میشود',
|
||||
'۱۲۱ سکه',
|
||||
'چون ۱۰٪ از ۱۱۰ محاسبه شده است',
|
||||
'مرکب؛ ۱۳۳٫۱ در برابر ۱۳۰',
|
||||
]
|
||||
for (const label of choices) {
|
||||
await page.getByRole('button', { name: label, exact: true }).click()
|
||||
await page.getByRole('button', { name: 'بعدی' }).click()
|
||||
}
|
||||
await page.getByRole('button', { name: 'نادرست', exact: true }).click()
|
||||
await page.getByRole('button', { name: 'بعدی' }).click()
|
||||
}
|
||||
|
||||
test('compound interest lesson from the map', async ({ page }) => {
|
||||
const user = uniqueUsername('cmp')
|
||||
await registerViaUi(page, user, 'pass1234', 'مرکب')
|
||||
const token = await page.evaluate(() => localStorage.getItem('gold-land-auth-token'))
|
||||
const headers = { authorization: `Bearer ${token}` }
|
||||
|
||||
for (let levelId = 1; levelId <= 6; levelId += 1) {
|
||||
expect((await page.request.post(`/api/gold-land/levels/${levelId}/start`, { headers })).ok()).toBeTruthy()
|
||||
expect((await page.request.post(`/api/gold-land/levels/${levelId}/complete`, {
|
||||
headers,
|
||||
data: { answers: lessons[levelId] },
|
||||
})).ok()).toBeTruthy()
|
||||
}
|
||||
expect((await page.request.post('/api/gold-land/levels/7/start', { headers })).ok()).toBeTruthy()
|
||||
expect((await page.request.post('/api/gold-land/levels/7/complete', {
|
||||
headers,
|
||||
data: {
|
||||
answers: [
|
||||
{ questionId: 'initial', allocations: { transport: 20, food: 25, savings: 20, fun: 0 } },
|
||||
{ questionId: 'final', allocations: { transport: 30, food: 25, savings: 20, fun: 0 } },
|
||||
],
|
||||
},
|
||||
})).ok()).toBeTruthy()
|
||||
expect((await page.request.post('/api/gold-land/levels/8/start', { headers })).ok()).toBeTruthy()
|
||||
expect((await page.request.post('/api/gold-land/levels/8/complete', {
|
||||
headers,
|
||||
data: {
|
||||
answers: [
|
||||
{ questionId: 'q-loss', answerId: 'b' },
|
||||
{ questionId: 'q-certain', answerId: 'no' },
|
||||
{ questionId: 'q-need', answerId: 'keep' },
|
||||
{ questionId: 'q-compare', answerId: 'range' },
|
||||
{ questionId: 'q-promise', answerId: 'check' },
|
||||
],
|
||||
},
|
||||
})).ok()).toBeTruthy()
|
||||
expect((await page.request.post('/api/gold-land/levels/9/start', { headers })).ok()).toBeTruthy()
|
||||
expect((await page.request.post('/api/gold-land/levels/9/complete', {
|
||||
headers,
|
||||
data: {
|
||||
answers: [
|
||||
{ questionId: 'portfolio', holdings: { sun: 40, rain: 30, wind: 30 } },
|
||||
{ questionId: 'q-one', answerId: 'depend' },
|
||||
{ questionId: 'q-loss', answerId: 'no' },
|
||||
{ questionId: 'q-name', answerId: 'no' },
|
||||
{ questionId: 'q-best', answerId: 'no' },
|
||||
{ questionId: 'q-approach', answerId: 'balanced' },
|
||||
],
|
||||
},
|
||||
})).ok()).toBeTruthy()
|
||||
|
||||
await page.goto('/map')
|
||||
await page.getByRole('button', { name: 'مرحله 10: سود مرکب' }).click()
|
||||
await page.getByRole('button', { name: 'شروع درس' }).click()
|
||||
await page.getByRole('button', { name: 'بعدی' }).click()
|
||||
await page.getByRole('button', { name: 'دوره بعد' }).click()
|
||||
await page.getByRole('button', { name: 'دوره بعد' }).click()
|
||||
await page.getByRole('button', { name: 'دوره بعد' }).click()
|
||||
await expect(page.getByText('۱۳۳٫۱ سکه').first()).toBeVisible()
|
||||
await expect(page.getByText('۱۲۱ + ۱۲٫۱ = ۱۳۳٫۱')).toBeVisible()
|
||||
await page.getByRole('button', { name: 'دوره قبل' }).click()
|
||||
await page.getByRole('button', { name: 'بعدی' }).click()
|
||||
await answerCompound(page)
|
||||
const before = await fetchMe(page)
|
||||
await page.getByRole('button', { name: 'اتمام درس' }).click()
|
||||
await expect(page.getByText('۱۰٪ آن ۱۱ سکه')).toBeVisible()
|
||||
await page.getByRole('button', { name: 'بازگشت به نقشه' }).click()
|
||||
await page.reload()
|
||||
const after = await fetchMe(page)
|
||||
expect(after.progress.mapLevels.find((level) => level.id === 10)?.stars).toBe(3)
|
||||
expect(after.user.coins).toBe(before.user.coins + 18 + 9)
|
||||
|
||||
await page.getByRole('button', { name: 'مرحله 10: سود مرکب' }).click()
|
||||
await page.getByRole('button', { name: 'مرور مجدد' }).click()
|
||||
await page.getByRole('button', { name: 'بعدی' }).click()
|
||||
await page.getByRole('button', { name: 'بعدی' }).click()
|
||||
await answerCompound(page)
|
||||
const replayBefore = await fetchMe(page)
|
||||
await page.getByRole('button', { name: 'اتمام درس' }).click()
|
||||
await expect(page.getByText('امتیاز')).toBeVisible()
|
||||
const replayAfter = await fetchMe(page)
|
||||
expect(replayAfter.user.coins).toBe(replayBefore.user.coins)
|
||||
|
||||
await page.goto('/map')
|
||||
await expect(page.getByRole('button', { name: 'مرحله 12: هدف مالی' })).toBeDisabled()
|
||||
})
|
||||
Reference in New Issue
Block a user