/* eslint-disable @typescript-eslint/no-require-imports */ const { chromium } = require("playwright"); const path = require("path"); const appUrl = "http://127.0.0.1:3001"; const outputDir = "C:/Users/USER/OneDrive/Desktop/STARTUP/artifacts/e2e"; async function submitAssistant(page, text) { const composer = page.getByPlaceholder(/Ask or change your plan|Why change the plan|Which chapters/); await composer.fill(text); await page.getByRole("button", { name: "Send to DocDoe" }).click(); } (async () => { const browser = await chromium.launch({ headless: true }); const context = await browser.newContext({ viewport: { width: 1600, height: 1000 }, deviceScaleFactor: 1, }); await context.addInitScript(() => { const now = "2026-07-14T12:00:00.000Z"; localStorage.setItem("exam_success_access_token", "docdoe-demo-preview-token"); localStorage.setItem("docdoe-onboarding-completed", "true"); localStorage.setItem("docdoe-onboarding-profile", JSON.stringify({ goal: "Score 90% and above", class: "SSLC / 10th", board: "Kerala State Board", subjects: ["Physics", "Chemistry", "Mathematics"], examDate: "2027-03-10", dailyTime: "90 min", preferredTime: "Evening", focus: ["Board answers"], languagePreference: "English", learningStyle: "Step-by-step", })); localStorage.setItem("docdoe:beta-access", JSON.stringify({ hasAccess: true, accessCodeLabel: "DOCDOE-BETA", grantedAt: now, classLevel: "Class 10", board: "Kerala SSLC", languagePreference: "English", })); localStorage.removeItem("docdoe:page-guide:/home:v2"); }); const page = await context.newPage(); const pageErrors = []; const failedResponses = []; page.on("pageerror", (error) => pageErrors.push(error.message)); page.on("response", (response) => { if (response.status() >= 400) failedResponses.push(`${response.status()} ${response.url()}`); }); await page.goto(`${appUrl}/home`, { waitUntil: "domcontentloaded" }); await page.getByRole("heading", { name: /Let.s make today productive/i }).waitFor({ timeout: 30000 }); await page.waitForTimeout(1500); console.log(JSON.stringify({ buttonsBeforeGuide: await page.getByRole("button").allTextContents(), assistantOpenButtonCount: await page.getByRole("button", { name: "Open DocDoe AI" }).count(), guideTextCount: await page.getByText(/Home guide/).count(), earlyPageErrors: pageErrors, }, null, 2)); await page.getByText(/Home guide/).waitFor({ state: "visible", timeout: 10000 }); await page.screenshot({ path: path.join(outputDir, "assistant-home-page-guide.png"), fullPage: true }); await page.getByRole("button", { name: "Close page guide" }).click(); await page.getByRole("button", { name: "Open DocDoe AI" }).waitFor({ state: "visible" }); await page.screenshot({ path: path.join(outputDir, "assistant-idle-head.png"), fullPage: true }); await page.getByRole("button", { name: "Open DocDoe AI" }).click(); await page.getByText("DocDoe AI", { exact: true }).waitFor({ state: "visible" }); await page.screenshot({ path: path.join(outputDir, "assistant-mini-chat-open.png"), fullPage: true }); await submitAssistant(page, "I need to study Physics instead of Chemistry"); await page.getByText(/Why do you need the change/i).waitFor({ state: "visible" }); await submitAssistant(page, "I have a Physics exam tomorrow"); await page.getByText(/Which Physics chapters are in the exam/i).waitFor({ state: "visible" }); await submitAssistant(page, "1, 2, 3"); await page.getByText("Confirm plan change", { exact: true }).waitFor({ state: "visible" }); await page.screenshot({ path: path.join(outputDir, "assistant-plan-confirmation.png"), fullPage: true }); await page.getByRole("button", { name: "Update my plan" }).click(); await page.getByText(/Open Home or Tuition and you will see the change/i).waitFor({ state: "visible", timeout: 30000 }); await page.screenshot({ path: path.join(outputDir, "assistant-plan-updated.png"), fullPage: true }); const stateResponse = await context.request.get("http://127.0.0.1:8000/learning-state/me", { headers: { Authorization: "Bearer docdoe-demo-preview-token" }, }); const learningState = await stateResponse.json(); const assistantTasks = learningState.tasks.filter((task) => task.title.startsWith("Physics revision:"), ); const visibleTaskTitles = await page.locator("main").getByText(/Physics|Sound Waves/).allTextContents(); console.log(JSON.stringify({ stateStatus: stateResponse.status(), assistantTaskCount: assistantTasks.length, activeTaskTitles: learningState.tasks.map((task) => task.title), visibleTaskTitles: visibleTaskTitles.slice(0, 12), pageErrors, failedResponses: failedResponses.filter((item) => !item.includes("favicon")), }, null, 2)); await browser.close(); })().catch((error) => { console.error(error); process.exitCode = 1; });