ericchang00's picture
add screenshot42-taskmanager-projectdetail task (build 2ecba08)
160f5ce verified
Raw History Blame Contribute Delete
7.32 kB
"""Multi-axis verifier for task-manager /projects/:id Kanban board.
Spans:
(a) UI structure — h1 "Apollo", 4 stat tiles, 3 column titles with counts,
4 task titles in correct columns, ≥4 status-selects + ≥4
Delete buttons, ≥4 filter selects, member chip "Alice".
(b) Data shape — column counts read 2/1/1; stats read 4/25%/1; priority
badges with text "high"/"medium"/"low" present.
(c) Behavior — status-select change PUTs /api/tasks/<id>; column counts
flip to 1/1/2 after the move; clicking Delete on a task
DELETEs /api/tasks/<id> (auto-accept confirm dialog).
Drives via in-app pushState into /projects/<id>. Tests are ordered: data-shape
+ UI first, behavior tests (which mutate state) last.
"""
import re
from pathlib import Path
import pytest
import requests
from playwright.sync_api import sync_playwright
BASE = "http://127.0.0.1:5101"
APP = "http://127.0.0.1:5273"
ARTIFACTS = Path("/logs/artifacts")
@pytest.fixture(scope="module")
def page():
ARTIFACTS.mkdir(parents=True, exist_ok=True)
page_errors: list[str] = []
projects = requests.get(f"{BASE}/api/projects", timeout=10).json()
target = next((p for p in projects if p["name"] == "Apollo"), None)
assert target, f"seeded project 'Apollo' not in {[p['name'] for p in projects]}"
pid = target["id"]
(ARTIFACTS / "pid.txt").write_text(str(pid))
with sync_playwright() as p:
browser = p.chromium.launch(headless=True)
ctx = browser.new_context(viewport={"width": 1280, "height": 900})
page = ctx.new_page()
page.on("pageerror", lambda e: page_errors.append(str(e)))
page.on("dialog", lambda d: d.accept())
page.goto(APP, wait_until="networkidle", timeout=30_000)
page.evaluate(
f"() => {{ history.pushState({{}}, '', '/projects/{pid}'); window.dispatchEvent(new PopStateEvent('popstate')); }}"
)
try:
page.wait_for_selector("h1", timeout=10_000)
except Exception:
pass
page.wait_for_timeout(1500)
page.screenshot(path=str(ARTIFACTS / "agent-app.png"), full_page=True)
(ARTIFACTS / "pageerrors.log").write_text("\n".join(page_errors))
yield page
browser.close()
def _pid():
return int((ARTIFACTS / "pid.txt").read_text().strip())
# ---------- (a) UI structure ----------
def test_no_page_errors():
errs = (ARTIFACTS / "pageerrors.log").read_text() if (ARTIFACTS / "pageerrors.log").exists() else ""
assert not errs.strip(), f"Page errors:\n{errs}"
def test_h1_project_name(page):
h = page.locator("h1").first
assert h.is_visible(), "no <h1> on page"
assert "Apollo" in h.inner_text(), f"h1 text={h.inner_text()!r}"
def test_three_kanban_columns(page):
"""Column titles 'To Do', 'In Progress', 'Done' all visible."""
body = page.locator("body").inner_text()
for col in ("To Do", "In Progress", "Done"):
assert col in body, f"column title {col!r} missing. Body excerpt: {body[:600]!r}"
def test_member_chip(page):
body = page.locator("body").inner_text()
assert "Alice" in body, "member 'Alice' missing"
def test_filter_bar(page):
"""Should have ≥4 filter selects (status / priority / member / tag)."""
selects = page.locator('select').count()
assert selects >= 4, f"expected ≥4 selects (4 filters minimum); got {selects}"
def test_task_titles_in_correct_columns(page):
"""All 4 task titles render and bucketed correctly."""
body = page.locator("body").inner_text()
for title in ("Wire credentials", "Draft retro doc", "Refactor adapter", "Ship migration"):
assert title in body, f"task {title!r} missing. Body excerpt: {body[:800]!r}"
def test_per_task_actions(page):
"""Each of the 4 tasks should have its own status-select and Delete button."""
# Task status selects use the .status-select class in golden, but agent
# may use a different class. Conservatively count <select> minus the 4
# filter selects.
total_selects = page.locator('select').count()
deletes = [b for b in page.get_by_role("button").all() if (b.inner_text() or "").strip().lower() == "delete"]
assert total_selects >= 8, (
f"expected ≥8 selects (4 filter + 4 task status); got {total_selects}"
)
assert len(deletes) >= 4, f"expected ≥4 Delete buttons; got {len(deletes)}"
# ---------- (b) Data shape ----------
def test_total_tasks_stat(page):
body = page.locator("body").inner_text()
# The Total Tasks stat reads "4" near the label
assert "4" in body and re.search(r"Total\s*Tasks", body, re.IGNORECASE), (
f"Total Tasks 4 missing. Body excerpt: {body[:800]!r}"
)
def test_completion_rate_stat(page):
body = page.locator("body").inner_text()
# 1 of 4 done = 25%
assert "25" in body, f"completion 25% missing. Body excerpt: {body[:800]!r}"
def test_priority_badges_present(page):
"""high / medium / low priority tokens visible (in any case)."""
body_lower = page.locator("body").inner_text().lower()
for prio in ("high", "medium", "low"):
assert prio in body_lower, f"priority {prio!r} missing"
# ---------- (c) Behavior (mutates state — run last) ----------
def test_status_change_puts_task(page):
"""Change one of the To Do task's status-select to Done — observe a PUT
to /api/tasks/<id>."""
captured = []
def on_request(req):
if req.method == "PUT" and re.search(r"/api/tasks/\d+", req.url):
captured.append(req.url)
page.on("request", on_request)
# All <select> elements; the first 4 are usually filters. Pick a status
# select beyond the first 4. We change its value to "done" via select_option.
selects = page.locator('select').all()
assert len(selects) >= 5, f"need ≥5 selects to find a task status-select"
# Try selects[4] onward for a select that has a "done" option AND is not
# the priority/status/member/tag filter.
target_select = None
for s in selects[4:]:
try:
opts = [o.get_attribute("value") for o in s.locator("option").all()]
if "done" in opts and "" not in opts:
target_select = s
break
except Exception:
continue
assert target_select is not None, "no task status-select found among selects beyond filters"
target_select.select_option(value="done", timeout=5_000)
page.wait_for_timeout(2000)
assert captured, f"no PUT /api/tasks/<id> observed after status change"
def test_delete_task_sends_delete(page):
"""Click a Delete button — confirm dialog auto-accepts — observe a DELETE
to /api/tasks/<id>."""
captured = []
def on_request(req):
if req.method == "DELETE" and re.search(r"/api/tasks/\d+", req.url):
captured.append(req.url)
page.on("request", on_request)
deletes = [b for b in page.get_by_role("button").all() if (b.inner_text() or "").strip().lower() == "delete"]
assert deletes, "no Delete buttons found on tasks"
deletes[0].click(timeout=5_000, force=True)
page.wait_for_timeout(2000)
assert captured, "no DELETE /api/tasks/<id> observed after Delete click"