feat: Puente Mayúscula-Minúscula + TTS SpeechSynthesis + E2E fixes
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
import { test, expect } from "@playwright/test"
|
||||
|
||||
test.describe("Curriculum API", () => {
|
||||
test("TTS endpoint generates audio", async ({ request }) => {
|
||||
const res = await request.get("/api/tts?text=hola%20mundo")
|
||||
expect(res.ok()).toBeTruthy()
|
||||
expect(res.headers()["content-type"]).toBe("audio/wav")
|
||||
const body = await res.body()
|
||||
expect(body.length).toBeGreaterThan(1000)
|
||||
})
|
||||
|
||||
test("TTS requires text param", async ({ request }) => {
|
||||
const res = await request.get("/api/tts")
|
||||
expect(res.status()).toBe(400)
|
||||
const json = await res.json()
|
||||
expect(json.error).toContain("text param")
|
||||
})
|
||||
|
||||
test("TTS text too long returns 400", async ({ request }) => {
|
||||
const long = "a".repeat(250)
|
||||
const res = await request.get(`/api/tts?text=${long}`)
|
||||
expect(res.status()).toBe(400)
|
||||
})
|
||||
|
||||
test("curriculum/next requires childId", async ({ request }) => {
|
||||
const res = await request.get("/api/curriculum/next")
|
||||
expect(res.status()).toBe(400)
|
||||
const json = await res.json()
|
||||
expect(json.error).toContain("childId")
|
||||
})
|
||||
|
||||
test("curriculum/next accepts childId param", async ({ request }) => {
|
||||
const res = await request.get("/api/curriculum/next?childId=any&topic=lectura")
|
||||
expect(res.status()).toBe(200)
|
||||
const json = await res.json()
|
||||
expect(json).toBeDefined()
|
||||
})
|
||||
|
||||
test("curriculum/grade missing fields returns 400", async ({ request }) => {
|
||||
const res = await request.post("/api/curriculum/grade", {
|
||||
data: {},
|
||||
})
|
||||
expect(res.status()).toBe(400)
|
||||
const json = await res.json()
|
||||
expect(json.error).toBe("Missing required fields")
|
||||
})
|
||||
|
||||
test("curriculum/grade validates required fields", async ({ request }) => {
|
||||
const res = await request.post("/api/curriculum/grade", {
|
||||
data: { childId: "test", exerciseId: "ex1", skillCode: "test" },
|
||||
headers: { "Content-Type": "application/json" },
|
||||
})
|
||||
expect(res.status()).toBe(400)
|
||||
const json = await res.json()
|
||||
expect(json.error).toBe("No active session")
|
||||
})
|
||||
|
||||
test("curriculum/progress requires childId", async ({ request }) => {
|
||||
const res = await request.get("/api/curriculum/progress")
|
||||
expect(res.status()).toBe(400)
|
||||
const json = await res.json()
|
||||
expect(json.error).toContain("childId")
|
||||
})
|
||||
|
||||
test("dashboard/summary requires childId", async ({ request }) => {
|
||||
const res = await request.get("/api/dashboard/summary")
|
||||
expect(res.status()).toBe(400)
|
||||
const json = await res.json()
|
||||
expect(json.error).toContain("childId")
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,78 @@
|
||||
import { test, expect } from "@playwright/test"
|
||||
import { readFileSync } from "fs"
|
||||
import { join } from "path"
|
||||
|
||||
const lecturaStages = 9
|
||||
const numerosStages = 8
|
||||
|
||||
test.describe("Exercise content integrity", () => {
|
||||
for (let i = 1; i <= lecturaStages; i++) {
|
||||
test(`lectura etapa ${i} file exists and has exercises`, () => {
|
||||
const file = join(process.cwd(), "curriculum", "lectura", `etapa-${i}.ts`)
|
||||
const content = readFileSync(file, "utf-8")
|
||||
expect(content.length).toBeGreaterThan(200)
|
||||
expect(content).toContain("stage")
|
||||
expect(content).toContain("exercises")
|
||||
})
|
||||
}
|
||||
|
||||
for (let i = 1; i <= numerosStages; i++) {
|
||||
test(`numeros etapa ${i} file exists and has exercises`, () => {
|
||||
const file = join(process.cwd(), "curriculum", "numeros", `etapa-${i}.ts`)
|
||||
const content = readFileSync(file, "utf-8")
|
||||
expect(content.length).toBeGreaterThan(200)
|
||||
expect(content).toContain("stage")
|
||||
expect(content).toContain("exercises")
|
||||
})
|
||||
}
|
||||
|
||||
test("curriculum index imports all stages via loadStages", () => {
|
||||
const file = join(process.cwd(), "curriculum", "index.ts")
|
||||
const content = readFileSync(file, "utf-8")
|
||||
expect(content).toContain("initCurriculum")
|
||||
expect(content).toContain("loadStages")
|
||||
expect(content).toContain("[1, 2, 3, 4, 5, 6, 7, 8, 9]")
|
||||
})
|
||||
|
||||
test("type definitions export required types", () => {
|
||||
const file = join(process.cwd(), "curriculum", "types.ts")
|
||||
const content = readFileSync(file, "utf-8")
|
||||
expect(content).toContain("export type Exercise")
|
||||
expect(content).toContain("export interface Stage")
|
||||
expect(content).toContain("export type ExerciseType")
|
||||
expect(content).toContain("export type ErrorType")
|
||||
})
|
||||
|
||||
test("exercise dispatcher maps all exercise types", () => {
|
||||
const file = join(process.cwd(), "components", "exercises", "exercise-dispatcher.tsx")
|
||||
const content = readFileSync(file, "utf-8")
|
||||
const types = ["sensibilizacion", "conciencia", "trazo", "eleccion", "emparejar", "secuencia", "palabra", "problema", "lectura"]
|
||||
for (const t of types) {
|
||||
expect(content).toContain(t)
|
||||
}
|
||||
})
|
||||
|
||||
test("all exercise component files exist", () => {
|
||||
const components = [
|
||||
"ejercicio-sensibilizacion",
|
||||
"ejercicio-conciencia",
|
||||
"ejercicio-eleccion",
|
||||
"ejercicio-secuencia",
|
||||
"ejercicio-palabra",
|
||||
"ejercicio-lectura",
|
||||
"ejercicio-trazo",
|
||||
"exercise-dispatcher",
|
||||
]
|
||||
for (const c of components) {
|
||||
const file = join(process.cwd(), "components", "exercises", `${c}.tsx`)
|
||||
const content = readFileSync(file, "utf-8")
|
||||
expect(content.length).toBeGreaterThan(100)
|
||||
}
|
||||
})
|
||||
|
||||
test("TTS route exists", () => {
|
||||
const file = join(process.cwd(), "app", "api", "tts", "route.ts")
|
||||
const content = readFileSync(file, "utf-8")
|
||||
expect(content).toContain("espeak-ng")
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,50 @@
|
||||
import { test, expect } from "@playwright/test"
|
||||
|
||||
async function dismissAudioUnlock(page: any) {
|
||||
const btn = page.getByRole("button", { name: /tocá/i })
|
||||
if (await btn.isVisible({ timeout: 2000 }).catch(() => false)) {
|
||||
await btn.click()
|
||||
await page.waitForTimeout(1200)
|
||||
}
|
||||
}
|
||||
|
||||
test.describe("Pairing flow", () => {
|
||||
|
||||
test("pairing page loads form with code input", async ({ page }) => {
|
||||
await page.goto("/child/pairing", { waitUntil: "networkidle", timeout: 15000 })
|
||||
await dismissAudioUnlock(page)
|
||||
await expect(page.getByPlaceholder("Código")).toBeVisible({ timeout: 10000 })
|
||||
})
|
||||
|
||||
test("pairing page has submit button", async ({ page }) => {
|
||||
await page.goto("/child/pairing", { waitUntil: "networkidle", timeout: 15000 })
|
||||
await dismissAudioUnlock(page)
|
||||
await expect(page.getByRole("button", { name: "Listo" })).toBeVisible({ timeout: 10000 })
|
||||
})
|
||||
|
||||
test("pairing code input accepts text", async ({ page }) => {
|
||||
await page.goto("/child/pairing", { waitUntil: "networkidle", timeout: 15000 })
|
||||
await dismissAudioUnlock(page)
|
||||
const input = page.getByPlaceholder("Código")
|
||||
await input.fill("ABCD1234")
|
||||
await expect(input).toHaveValue("ABCD1234")
|
||||
})
|
||||
|
||||
test("lectura page shows pairing message when not paired", async ({ page }) => {
|
||||
await page.goto("/child/lectura", { waitUntil: "networkidle", timeout: 15000 })
|
||||
await dismissAudioUnlock(page)
|
||||
await expect(page.getByText("emparejar", { exact: false }).first()).toBeVisible({ timeout: 10000 })
|
||||
})
|
||||
|
||||
test("numeros page shows pairing message when not paired", async ({ page }) => {
|
||||
await page.goto("/child/numeros", { waitUntil: "networkidle", timeout: 15000 })
|
||||
await dismissAudioUnlock(page)
|
||||
await expect(page.getByText("emparejar", { exact: false }).first()).toBeVisible({ timeout: 10000 })
|
||||
})
|
||||
|
||||
test("lectura page has ir a emparejar button", async ({ page }) => {
|
||||
await page.goto("/child/lectura", { waitUntil: "networkidle", timeout: 15000 })
|
||||
await dismissAudioUnlock(page)
|
||||
await expect(page.getByRole("button", { name: /emparejar/i })).toBeVisible({ timeout: 10000 })
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user