stackchain-dashboard/tests/e2e/test_mobile_today_handoff_release.py
timmy ea08f566ff
Some checks failed
CI / lint (pull_request) Successful in 2m44s
CI / build-release (pull_request) Successful in 5s
CI / browser-journey (pull_request) Failing after 2m7s
CI / release-candidate (pull_request) Has been skipped
feat: add timed mobile Today breaks (Closes #1036)
2026-08-17 19:20:07 +00:00

170 lines
9.3 KiB
Python

from __future__ import annotations
import os
import threading
from pathlib import Path
import pytest
if os.getenv("STACKCHAIN_RUN_RELEASE_E2E") != "1":
pytest.skip("packaged Plan Today handoff journey runs only in its gated CI job", allow_module_level=True)
pytest.importorskip("playwright.sync_api")
from playwright.sync_api import expect, sync_playwright
from fake_gitea import FakeGiteaServer
from test_mobile_offline_issue_release import ACCESS_TOKEN, ROOT, release_server
def test_release_artifact_plans_hands_off_and_opens_next_mobile_issue(tmp_path: Path):
archives = sorted((ROOT / "dist").glob("stackchain-dashboard-*.tar.gz"))
assert len(archives) == 1, "browser job must download exactly one assembled release archive"
fake = FakeGiteaServer(("127.0.0.1", 0))
fake_thread = threading.Thread(target=fake.serve_forever, daemon=True)
fake_thread.start()
fake_url = f"http://127.0.0.1:{fake.server_port}"
browser_errors: list[str] = []
failed_responses: list[str] = []
try:
with release_server(archives[0], tmp_path, fake_url) as origin, sync_playwright() as playwright:
browser = playwright.chromium.launch(args=["--ignore-certificate-errors"])
context = browser.new_context(viewport={"width": 390, "height": 844}, ignore_https_errors=True)
page = context.new_page()
page.on("pageerror", lambda error: browser_errors.append(error.stack or str(error)))
page.on("console", lambda message: browser_errors.append(message.text) if message.type == "error" else None)
page.on(
"response",
lambda response: failed_responses.append(f"{response.status} {response.url}")
if response.status >= 400
else None,
)
page.goto(origin + "/", wait_until="networkidle")
page.locator('input[name="device_label"]').fill("Plan Today release phone")
page.locator('input[name="access_token"]').fill(ACCESS_TOKEN)
page.locator("#submit-sign-in").click()
page.wait_for_url(origin + "/", wait_until="networkidle")
expect(page.locator("#my-work-status")).to_contain_text("2")
page.locator('[data-mobile-task="work"]').click()
expect(page.locator("#plan-today-sheet")).to_be_visible()
expect(page.locator("#plan-today-candidates .plan-today-item")).to_have_count(2)
navigation = page.locator(".mobile-plan-today-nav")
expect(navigation).to_be_visible()
for control in navigation.locator("button").all():
bounds = control.bounding_box()
assert bounds and bounds["height"] >= 44
page.locator("#plan-today-available").fill("90")
page.locator("#plan-today-available").press("Tab")
page.locator("#build-today-plan").click()
missing_estimates = page.locator("[data-plan-missing-estimate]")
expect(missing_estimates).to_have_count(2)
for _ in range(2):
missing_estimates.nth(0).fill("30")
missing_estimates.nth(0).press("Tab")
expect(page.locator("#plan-today-list .plan-today-item")).to_have_count(2)
estimates = page.locator("[data-plan-estimate]")
expect(estimates).to_have_count(2)
page.locator("#save-and-start-today").click()
try:
expect(page.locator("#plan-today-sheet")).to_be_hidden(timeout=5_000)
except AssertionError as error:
raise AssertionError(page.evaluate("({hidden:document.querySelector('#plan-today-sheet').hidden, state:history.state, bodyClass:document.body.className})")) from error
expect(page.locator("#issue-sheet")).to_have_class("issue-sheet open")
expect(page.locator("#issue-sheet-title")).to_have_text("Ship mobile capture")
expect(page.locator("#send-issue-comment-next")).to_be_visible()
assert page.evaluate("document.documentElement.scrollWidth <= window.innerWidth")
expect(page.locator("#plan-today-sheet")).to_be_hidden()
page.locator("#close-issue-sheet").click()
if page.locator("#plan-today-sheet").is_visible():
page.locator("#cancel-plan-today").click()
expect(page.locator("[data-mobile-today-hud]")).to_be_visible()
take_break = page.locator("[data-today-break-open]")
expect(take_break).to_be_visible()
take_break.click()
expect(page.locator("#today-break-sheet")).to_be_visible()
for control in page.locator(".today-break-actions button").all():
bounds = control.bounding_box()
assert bounds and bounds["height"] >= 44
page.go_back()
expect(page.locator("#today-break-sheet")).to_be_hidden()
take_break.click()
page.locator('[data-today-break-minutes="5"]').click()
expect(page.locator("#today-break-status")).to_have_text("On break · resume in 5:00")
expect(page.locator("[data-mobile-today-toggle]")).to_have_text("Resume timer")
page.reload(wait_until="networkidle")
expect(page.locator("#my-work-status")).to_contain_text("2")
expect(page.locator("#today-break-status")).to_contain_text("On break · resume in")
if page.locator("#issue-sheet").get_attribute("class") == "issue-sheet open":
page.locator("#close-issue-sheet").click()
if page.locator("#plan-today-sheet").is_visible():
page.locator("#cancel-plan-today").click()
expect(page.locator("#resume-today-break")).to_be_visible()
page.locator("#resume-today-break").click()
expect(page.locator("#today-break-status")).to_be_hidden()
expect(page.locator("#issue-sheet")).to_have_class("issue-sheet open")
expect(page.locator("#issue-sheet-title")).to_have_text("Ship mobile capture")
page.locator("#close-issue-sheet").click()
if page.locator("#plan-today-sheet").is_visible():
page.locator("#cancel-plan-today").click()
page.set_viewport_size({"width": 320, "height": 568})
page.locator("[data-today-break-open]").click()
expect(page.locator("#today-break-sheet")).to_be_visible()
assert page.evaluate("document.documentElement.scrollWidth <= window.innerWidth")
custom = page.locator("#today-break-custom-minutes")
bounds = custom.bounding_box()
assert bounds and bounds["height"] >= 44
page.locator("#cancel-today-break").click()
expect(page.locator("#today-break-sheet")).to_be_hidden()
page.set_viewport_size({"width": 390, "height": 844})
page.locator("[data-mobile-today-open]").click()
expect(page.locator("#issue-sheet")).to_have_class("issue-sheet open")
page.locator('[data-issue-section="reply"]').click()
page.locator("#issue-comment").fill("Handoff complete; continuing with the next Today item.")
page.locator("#send-issue-comment-next").click()
expect(page.locator("#issue-sheet-title")).to_have_text("Polish desktop filters")
expect(page.locator("#issue-comment")).to_have_value("")
expect(page.locator("[data-mobile-today-hud]")).to_have_attribute("data-overlay-hidden", "true")
expect(page.locator("[data-mobile-today-hud]")).to_contain_text("Polish desktop filters")
assert fake.comments == [(41, "Handoff complete; continuing with the next Today item.")]
receipt = page.locator("#today-completion-undo")
expect(receipt).to_be_visible()
expect(receipt).to_contain_text("Removed from Today. Undo?")
undo = page.locator("#undo-today-completion")
bounds = undo.bounding_box()
assert bounds and bounds["height"] >= 44
page.locator("#close-issue-sheet").click()
expect(page.locator("[data-mobile-today-hud]")).to_be_visible()
expect(page.locator(".mobile-task-dock")).to_be_visible()
layout = page.evaluate("""() => {
const receipt = document.querySelector('#today-completion-undo').getBoundingClientRect();
const hud = document.querySelector('[data-mobile-today-hud]').getBoundingClientRect();
const dock = document.querySelector('.mobile-task-dock').getBoundingClientRect();
return {receiptBottom:receipt.bottom, hudTop:hud.top, dockTop:dock.top};
}""")
assert layout["receiptBottom"] <= min(layout["hudTop"], layout["dockTop"])
undo.click()
expect(receipt).to_be_hidden()
expect(page.locator("[data-mobile-today-hud]")).to_contain_text("Polish desktop filters")
today = page.evaluate("JSON.parse(localStorage.getItem('stackchain.today-work.v1.timmy') || '[]')")
assert today == ["issue:acme/mobile:41:", "issue:acme/mobile:42:"]
assert page.evaluate("document.documentElement.scrollWidth <= window.innerWidth")
assert browser_errors == []
assert failed_responses == []
browser.close()
finally:
fake.shutdown()
fake.server_close()
fake_thread.join(timeout=5)