import json import subprocess from pathlib import Path import pytest from tests.dashboard_bundle import dashboard MOBILE_LAUNCH = Path(__file__).resolve().parents[1] / "frontend" / "mobile-launch.js" def test_mobile_launch_selects_priority_queue_without_overriding_saved_choice(): script = f""" const mobileLaunch = require({json.dumps(str(MOBILE_LAUNCH))}); process.stdout.write(JSON.stringify({{ today: mobileLaunch.chooseFilter({{saved:null, today:2, attention:4}}), attention: mobileLaunch.chooseFilter({{saved:null, today:0, attention:4}}), all: mobileLaunch.chooseFilter({{saved:null, today:0, attention:0}}), saved: mobileLaunch.chooseFilter({{saved:'review', today:2, attention:4}}), }})); """ result = subprocess.run(["node", "-e", script], capture_output=True, text=True) assert result.returncode == 0, result.stderr assert json.loads(result.stdout) == { "today": "today", "attention": "attention", "all": "all", "saved": "review", } def test_mobile_disclosure_closes_on_escape_and_restores_launcher_focus(): script = f""" const mobileLaunch = require({json.dumps(str(MOBILE_LAUNCH))}); const listeners = {{}}; const disclosure = {{open:true, addEventListener(name, fn) {{ listeners[name] = fn; }}}}; const launcher = {{focuses:0, focus() {{ this.focuses += 1; }}}}; const controller = mobileLaunch.createDisclosure({{disclosure, launcher}}); controller.start(); let prevented = false; listeners.keydown({{key:'Escape', preventDefault() {{ prevented = true; }}}}); process.stdout.write(JSON.stringify({{open:disclosure.open, focuses:launcher.focuses, prevented}})); """ result = subprocess.run(["node", "-e", script], capture_output=True, text=True) assert result.returncode == 0, result.stderr assert json.loads(result.stdout) == {"open": False, "focuses": 1, "prevented": True} @pytest.mark.anyio async def test_mobile_launch_progressively_discloses_secondary_controls(): html = await dashboard() assert 'class="app-brand"' in html assert 'class="app-live-status"' in html assert 'class="app-menu"' in html assert 'id="app-menu-toggle"' in html assert 'class="work-settings"' in html assert 'id="work-settings-toggle"' in html assert 'id="active-work-queue"' in html assert '' in html service_worker = (Path(__file__).resolve().parents[1] / "frontend" / "service-worker.js").read_text() assert "BASE + 'static/mobile-launch.js'" in service_worker assert "mobileLaunch.chooseFilter" in html assert "mobileLaunch.createDisclosure" in html assert "@media (max-width: 600px)" in html assert "header { min-height:56px; max-height:64px;" in html assert ".work-settings:not([open]) > .work-settings-panel { display:none; }" in html assert ".app-menu:not([open]) > .app-menu-panel { display:none; }" in html assert ".my-work-actions { display:none; }" in html