feat: watch assigned work from mobile detail (Closes #1309)
This commit is contained in:
1 parent
4e3f67df3d
commit
35a88bb398
7 files changed
+296
-3
No files matched your search
@@ -0,0 +1,44 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
if os.getenv("STACKCHAIN_RUN_RELEASE_E2E") != "1":
|
||||
pytest.skip("packaged mobile detail-watch 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
|
||||
|
||||
|
||||
ROOT = Path(__file__).parents[2]
|
||||
FRONTEND = ROOT / "frontend"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("viewport", [
|
||||
{"width": 320, "height": 568},
|
||||
{"width": 390, "height": 844},
|
||||
])
|
||||
def test_issue_and_pull_detail_watch_controls_are_phone_usable(viewport):
|
||||
with sync_playwright() as playwright:
|
||||
browser = playwright.chromium.launch(headless=True)
|
||||
page = browser.new_page(viewport=viewport)
|
||||
page.set_content((FRONTEND / "index.html").read_text())
|
||||
page.add_style_tag(path=FRONTEND / "dashboard.css")
|
||||
page.add_script_tag(path=FRONTEND / "search-preview.js")
|
||||
|
||||
for sheet, button, expected in [
|
||||
("#issue-sheet", "#watch-issue-detail", "Watch issue"),
|
||||
("#pull-sheet", "#watch-pull-detail", "Watch pull request"),
|
||||
]:
|
||||
page.locator(sheet).evaluate("node => node.classList.add('open')")
|
||||
control = page.locator(button)
|
||||
expect(control).to_be_visible()
|
||||
expect(control).to_have_text(expected)
|
||||
assert control.bounding_box()["height"] >= 44
|
||||
control.focus()
|
||||
expect(control).to_be_focused()
|
||||
page.locator(sheet).evaluate("node => node.classList.remove('open')")
|
||||
|
||||
assert page.evaluate(
|
||||
"document.documentElement.scrollWidth > document.documentElement.clientWidth"
|
||||
) is False
|
||||
browser.close()
|
||||
@@ -0,0 +1,184 @@
|
||||
import json
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
ROOT = Path(__file__).parents[1]
|
||||
MODULE = ROOT / "frontend" / "search-preview.js"
|
||||
|
||||
|
||||
def run(script: str) -> dict:
|
||||
harness = f"""
|
||||
require({json.dumps(str(MODULE))});
|
||||
const createDetailWatch = globalThis.createDetailWatch;
|
||||
const state = {{ requests:[], renders:[], refreshes:0 }};
|
||||
const feature = createDetailWatch({{
|
||||
fetchJson: async (path, options={{}}) => {{
|
||||
state.requests.push({{path,method:options.method || 'GET'}});
|
||||
return {{watching:false,following_synced:true}};
|
||||
}},
|
||||
refreshFollowing: async () => {{ state.refreshes += 1; }},
|
||||
onState: (status,watching,error) => state.renders.push({{status,watching,error:error?.message}}),
|
||||
}});
|
||||
(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_detail_watch_loads_authoritative_typed_subscription_state():
|
||||
result = run("""
|
||||
await feature.open({repository:'stackchain/api',kind:'pull',number:84,state:'open'});
|
||||
process.stdout.write(JSON.stringify(state));
|
||||
""")
|
||||
|
||||
assert result["requests"] == [{
|
||||
"path": "api/v1/repos/stackchain/api/issues/84/preview/subscription?kind=pull",
|
||||
"method": "GET",
|
||||
}]
|
||||
assert result["renders"] == [
|
||||
{"status": "loading", "watching": False},
|
||||
{"status": "ready", "watching": False},
|
||||
]
|
||||
assert result["refreshes"] == 0
|
||||
|
||||
|
||||
def test_detail_watch_mutation_is_single_flight_and_refreshes_following_after_confirmation():
|
||||
script = f"""
|
||||
require({json.dumps(str(MODULE))});
|
||||
const createDetailWatch = globalThis.createDetailWatch;
|
||||
const state={{requests:[],renders:[],refreshes:0}};
|
||||
let finishMutation;
|
||||
const feature=createDetailWatch({{
|
||||
fetchJson:async (path,options={{}}) => {{
|
||||
state.requests.push({{path,method:options.method || 'GET'}});
|
||||
if (!options.method) return {{watching:false}};
|
||||
return new Promise(resolve => {{finishMutation=() => resolve({{watching:true,following_synced:true,following_count:3}});}});
|
||||
}},
|
||||
refreshFollowing:async () => {{state.refreshes += 1;}},
|
||||
onState:(status,watching,error) => state.renders.push({{status,watching,error:error?.message}}),
|
||||
}});
|
||||
(async () => {{
|
||||
const item={{repository:'stackchain/api',kind:'issue',number:42,state:'open'}};
|
||||
await feature.open(item);
|
||||
const first=feature.toggle();
|
||||
const second=feature.toggle();
|
||||
await new Promise(resolve => setImmediate(resolve));
|
||||
state.samePromise=first === second;
|
||||
finishMutation();
|
||||
await Promise.all([first,second]);
|
||||
process.stdout.write(JSON.stringify(state));
|
||||
}})().catch(error => {{console.error(error);process.exit(1);}});
|
||||
"""
|
||||
result = json.loads(subprocess.run(
|
||||
["node", "-e", script], text=True, capture_output=True, check=True
|
||||
).stdout)
|
||||
|
||||
assert result["samePromise"] is True
|
||||
assert [request["method"] for request in result["requests"]] == ["GET", "PUT"]
|
||||
assert result["refreshes"] == 1
|
||||
assert result["renders"][-2]["status"] == "watching"
|
||||
assert result["renders"][-1]["status"] == "watched"
|
||||
assert result["renders"][-1]["watching"] is True
|
||||
|
||||
|
||||
def test_detail_watch_partial_sync_never_claims_success_or_refreshes_following():
|
||||
script = f"""
|
||||
require({json.dumps(str(MODULE))});
|
||||
const createDetailWatch = globalThis.createDetailWatch;
|
||||
const state={{renders:[],refreshes:0}};
|
||||
const feature=createDetailWatch({{
|
||||
fetchJson:async (_path,options={{}}) => options.method
|
||||
? {{watching:true,following_synced:false,error:'Following could not sync.'}}
|
||||
: {{watching:false}},
|
||||
refreshFollowing:async () => {{state.refreshes += 1;}},
|
||||
onState:(status,watching,error) => state.renders.push({{status,watching,error:error?.message}}),
|
||||
}});
|
||||
(async () => {{
|
||||
await feature.open({{repository:'stackchain/api',kind:'issue',number:42,state:'open'}});
|
||||
try {{ await feature.toggle(); }} catch (error) {{ state.rejected=error.message; }}
|
||||
process.stdout.write(JSON.stringify(state));
|
||||
}})().catch(error => {{console.error(error);process.exit(1);}});
|
||||
"""
|
||||
result = json.loads(subprocess.run(
|
||||
["node", "-e", script], text=True, capture_output=True, check=True
|
||||
).stdout)
|
||||
|
||||
assert result["rejected"] == "Following could not sync."
|
||||
assert result["refreshes"] == 0
|
||||
assert result["renders"][-1]["status"] == "error"
|
||||
assert result["renders"][-1]["watching"] is False
|
||||
assert all(state["status"] != "watched" for state in result["renders"])
|
||||
|
||||
|
||||
def test_detail_watch_is_wired_into_both_mobile_work_details_and_bundle():
|
||||
html = (ROOT / "frontend" / "index.html").read_text()
|
||||
dashboard = (ROOT / "frontend" / "dashboard.js").read_text()
|
||||
css = (ROOT / "frontend" / "dashboard.css").read_text()
|
||||
bundle = (ROOT / "src" / "frontend_bundle.py").read_text()
|
||||
search_preview = (ROOT / "frontend" / "search-preview.js").read_text()
|
||||
|
||||
assert '<button id="watch-issue-detail" type="button">Watch issue</button>' in html
|
||||
assert '<button id="watch-pull-detail" type="button">Watch pull request</button>' in html
|
||||
assert 'id="issue-watch-status"' in html
|
||||
assert 'id="pull-watch-status"' in html
|
||||
assert 'static/search-preview.js' in bundle
|
||||
assert 'root.createDetailWatch' in search_preview
|
||||
assert 'function bindDetailWatch(' in dashboard
|
||||
assert 'issueDetailWatch.open(item)' in dashboard
|
||||
assert 'pullDetailWatch.open(item)' in dashboard
|
||||
assert '#watch-issue-detail' in css
|
||||
assert '#watch-pull-detail' in css
|
||||
|
||||
|
||||
def test_detail_watch_ignores_a_late_subscription_response_for_the_previous_item():
|
||||
script = f"""
|
||||
require({json.dumps(str(MODULE))});
|
||||
const createDetailWatch = globalThis.createDetailWatch;
|
||||
const state={{renders:[]}};
|
||||
const completions={{}};
|
||||
const feature=createDetailWatch({{
|
||||
fetchJson:path => new Promise(resolve => {{completions[path]=resolve;}}),
|
||||
onState:(status,watching,error) => state.renders.push({{status,watching,error:error?.message}}),
|
||||
}});
|
||||
(async () => {{
|
||||
const first=feature.open({{repository:'stackchain/api',kind:'issue',number:1,state:'open'}});
|
||||
const second=feature.open({{repository:'stackchain/api',kind:'issue',number:2,state:'open'}});
|
||||
completions[Object.keys(completions)[1]]({{watching:true}});
|
||||
await second;
|
||||
completions[Object.keys(completions)[0]]({{watching:false}});
|
||||
await first;
|
||||
process.stdout.write(JSON.stringify(state));
|
||||
}})().catch(error => {{console.error(error);process.exit(1);}});
|
||||
"""
|
||||
result = json.loads(subprocess.run(
|
||||
["node", "-e", script], text=True, capture_output=True, check=True
|
||||
).stdout)
|
||||
|
||||
ready = [state for state in result["renders"] if state["status"] == "ready"]
|
||||
assert len(ready) == 1
|
||||
assert ready[0]["watching"] is True
|
||||
|
||||
|
||||
def test_detail_watch_reports_subscription_load_failure_as_recoverable_error():
|
||||
script = f"""
|
||||
require({json.dumps(str(MODULE))});
|
||||
const state={{renders:[]}};
|
||||
const feature=globalThis.createDetailWatch({{
|
||||
fetchJson:async () => {{throw new Error('temporarily unavailable');}},
|
||||
onState:(status,watching,error) => state.renders.push({{status,watching,error:error?.message}}),
|
||||
}});
|
||||
(async () => {{
|
||||
try {{ await feature.open({{repository:'stackchain/api',kind:'issue',number:1,state:'open'}}); }}
|
||||
catch (error) {{ state.rejected=error.message; }}
|
||||
process.stdout.write(JSON.stringify(state));
|
||||
}})().catch(error => {{console.error(error);process.exit(1);}});
|
||||
"""
|
||||
result = json.loads(subprocess.run(
|
||||
["node", "-e", script], text=True, capture_output=True, check=True
|
||||
).stdout)
|
||||
|
||||
assert result["rejected"] == "temporarily unavailable"
|
||||
assert result["renders"][-1] == {
|
||||
"status": "error", "watching": False, "error": "temporarily unavailable"
|
||||
}
|
||||
Reference in new issue
Block a user