Files
confidence-engine/tests/smoke.test.js
T

102 lines
3.7 KiB
JavaScript

import { test, expect } from "@playwright/test";
const BASE_URL = process.env.PLAYWRIGHT_BASE_URL || "http://localhost:3000";
test.setTimeout(300000);
test("graph-backed one-turn update smoke test", async ({ page }) => {
await page.goto(BASE_URL);
// Page should load without error
await expect(page.getByText(/Confidence Engine/i)).toBeVisible();
// Type the scenario
const textarea = page.locator("textarea[placeholder*='Describe']");
await textarea.fill(
"Complaints increased by 35% while production increased by 40%.",
);
await expect(textarea).toHaveValue(
"Complaints increased by 35% while production increased by 40%.",
);
// Button should be enabled
await expect(page.getByRole("button", { name: /Analyse/i })).toBeEnabled();
// Click Analyse and wait for graph-backed result
await page.getByRole("button", { name: /Analyse/i }).click();
await expect(
page
.locator("section")
.filter({ hasText: /Selected Question/i })
.last()
.getByRole("heading", { name: /Selected Question/i }),
).toBeVisible({ timeout: 180000 });
await expect(
page.getByRole("heading", { name: /Situation Graph/i }),
).toBeVisible({ timeout: 180000 });
await expect(page.getByText(/Central statement/i)).toBeVisible();
await expect(page.getByText(/Active unknown/i)).toBeVisible();
await expect(page.getByText(/Error:/i)).toHaveCount(0);
const rawJsonToggle = page.getByText(/Raw graph JSON/i);
await expect(rawJsonToggle).toBeVisible();
await rawJsonToggle.click();
await expect(page.getByText(/centralStatement/i)).toBeVisible();
const selectedQuestionSections = page
.locator("section")
.filter({ hasText: "Selected Question" });
await expect(selectedQuestionSections).toHaveCount(1);
const questionText = await selectedQuestionSections.first().innerText();
expect(questionText.length).toBeGreaterThan(25);
const answerTextarea = page.locator(
"textarea[placeholder*='Enter the answer']",
);
await expect(answerTextarea).toBeVisible();
await answerTextarea.fill(
"The complaint rate fell from 2.0 complaints per 100 units to 1.9 complaints per 100 units.",
);
await page.getByRole("button", { name: /Update situation/i }).click();
await expect(page.getByText(/Graph update applied/i)).toBeVisible({
timeout: 240000,
});
await expect(page.getByText(/Resolved unknowns/i)).toBeVisible();
await expect(page.getByText(/Affected nodes/i)).toBeVisible();
await expect(
page.getByText(/No next question selected yet\./i),
).toBeVisible();
await expect(page.getByText(/Error:/i)).toHaveCount(0);
await expect(page.getByText(/Update error:/i)).toHaveCount(0);
await expect(answerTextarea).toHaveValue("");
const proposalToggle = page.getByText(/Proposal details/i);
await expect(proposalToggle).toBeVisible();
await rawJsonToggle.click();
await expect(page.getByText(/resolvedNodeIds/i)).toBeVisible();
// Get full body text for verification
const bodyText = await page.locator("body").innerText();
// Check key content indicators
const hasSelectedQuestion = bodyText.includes("Selected Question");
const hasComplaints =
bodyText.includes("Complaint") || bodyText.includes("complaint");
const hasProduction =
bodyText.includes("production") || bodyText.includes("Production");
const hasRateContext =
bodyText.toLowerCase().includes("rate") ||
bodyText.toLowerCase().includes("unit") ||
bodyText.toLowerCase().includes("denominator") ||
bodyText.toLowerCase().includes("per-unit");
// Basic structural checks
expect(bodyText.length).toBeGreaterThan(400);
expect(hasSelectedQuestion).toBe(true);
expect(bodyText.includes("Resolved unknowns")).toBe(true);
expect(bodyText.includes("Affected nodes")).toBe(true);
});