stackchain-dashboard/tests/test_following_frontend.py
timmy 5c43a5678a
Some checks failed
CI / lint (pull_request) Successful in 4m15s
CI / build-release (pull_request) Successful in 9s
CI / browser-journey (pull_request) Failing after 6m46s
CI / release-candidate (pull_request) Has been skipped
feat: add mobile Following queue for watched issues (Closes #1293)
2026-08-23 04:27:23 +00:00

72 lines
2.5 KiB
Python

import json
import subprocess
from pathlib import Path
ROOT = Path(__file__).parents[1]
MODULE = ROOT / "frontend" / "following.js"
def run(script: str) -> dict:
harness = f"""
const createFollowing = require({json.dumps(str(MODULE))});
const state = {{ renders:[], counts:[], opened:[], requests:[] }};
const feature = createFollowing({{
fetchJson: async path => {{
state.requests.push(path);
return {{revision:3,items:[{{repository:'stackchain/api',number:42,title:'Quiet issue',state:'open',updated_at:'2026-08-23T03:00:00Z',url:'https://forge.example/issue/42'}}]}};
}},
render: snapshot => state.renders.push(snapshot),
onCount: count => state.counts.push(count),
onOpen: item => state.opened.push(item),
}});
(async () => {{ {script} }})().catch(error => {{ console.error(error); process.exit(1); }});
"""
completed = subprocess.run(["node", "-e", harness], text=True, capture_output=True, check=True)
return json.loads(completed.stdout)
def test_following_loads_account_collection_and_opens_existing_preview():
result = run("""
await feature.load();
feature.open(0);
process.stdout.write(JSON.stringify(state));
""")
assert result["requests"] == ["api/v1/following"]
assert result["counts"] == [1]
assert result["renders"][-1]["status"] == "ready"
assert result["renders"][-1]["items"][0]["title"] == "Quiet issue"
assert result["opened"] == [{
"repository": "stackchain/api",
"number": 42,
"title": "Quiet issue",
"state": "open",
"updated_at": "2026-08-23T03:00:00Z",
"url": "https://forge.example/issue/42",
"kind": "issue",
}]
def test_following_opens_explicitly_but_never_becomes_work_recommendation():
launcher = ROOT / "frontend" / "mobile-queue-launcher.js"
script = f"""
const createLauncher = require({json.dumps(str(launcher))});
const calls = [];
const feature = createLauncher({{
getCounts:() => ({{following:7}}),
openFollowing:() => {{ calls.push('following'); return 'opened-following'; }},
selectFilter:name => calls.push(name), firstAction:() => null,
announce:() => {{}}, openFindWork:() => calls.push('find'),
}});
process.stdout.write(JSON.stringify({{opened:feature.open('following'),recommended:feature.recommend(),calls}}));
"""
result = json.loads(subprocess.run(
["node", "-e", script], text=True, capture_output=True, check=True
).stdout)
assert result == {
"opened": "opened-following",
"recommended": {"name": "find", "count": 0, "label": "Find Work"},
"calls": ["following"],
}