fix CAST SKY click opening tray instead of Sky Select — TDD

CAST SKY btn click handler in sig-select.js init() was bound to `Tray.open()` — wrong on two counts: (1) the tray was already played during the `polarity_room_done` → `Tray.placeSig` sequence (sig stage card slides into the tray cell before the overlay dismisses), so re-opening it on CAST SKY click pops the tray a second time; (2) Sky Select never opens — `_sky_overlay.html` is only `{% include %}`d server-side when `room.table_status == "SKY_SELECT"`, so during SIG_SELECT the partial + its `openSky` handler aren't in the DOM and `Tray.open()` is the only thing the click does. Bug surfaced symmetrically in both polarity rooms regardless of which finished first ; fix: replace `Tray.open()` w. `window.location.reload()` so the server re-renders the room w. table_status=SKY_SELECT — which surfaces the sky overlay partial + the `openSky` handler bound at _sky_overlay.html:192-193. Same pattern as `_onSkyConfirmed` in the sky partial (location.reload after sky save) ; testability hook mirrors `RoleSelect.setReload` (role-select.js:236): `var _reload = function () { window.location.reload(); };` at module scope, listener calls `_reload()` (closure looks up the var at click time so reassignment works), `setReload(fn)` exposed on the module's test API. SigSelectSpec.js adds `describe("CAST SKY click (post pick_sky_available)")` w. 2 specs — reload spy hit on click + `Tray.open` spy NOT hit on click; the negative assertion catches the original bug, the positive verifies the fix's intent. Existing 363 specs untouched ; Jasmine FT green in 8.6s; full IT/UT 999 green in 44s ; collectstatic mirror at src/static/apps/epic/sig-select.js refreshed in same commit so the served JS carries the fix (Django serves from STATIC_ROOT, not from app static dirs, in StaticLiveServerTestCase)

Code architected by Disco DeDisco <discodedisco@outlook.com>
Git commit message Co-Authored-By:
Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Disco DeDisco
2026-05-18 17:21:32 -04:00
parent 1ccb045889
commit fbe6c12ded
3 changed files with 93 additions and 4 deletions

View File

@@ -894,4 +894,44 @@ describe("SigSelect", () => {
expect(document.getElementById("id_hex_waiting_msg")).toBe(null);
});
});
// ── CAST SKY click (post pick_sky_available reveal) ──────────────────── //
//
// After room:pick_sky_available reveals the hidden #id_pick_sky_btn, a
// click on CAST SKY must reload the page — the _sky_overlay.html partial
// is only rendered server-side once room.table_status == "SKY_SELECT", so
// reloading is the only way to bring its modal + openSky handler into the
// DOM. The handler must NOT call Tray.open: the tray was already played
// during the polarity_room_done sequence (Tray.placeSig) and re-opening it
// here would swap Sky Select for the tray.
describe("CAST SKY click (post pick_sky_available)", () => {
let pickSkyBtn, reloadSpy;
beforeEach(() => {
pickSkyBtn = document.createElement("button");
pickSkyBtn.id = "id_pick_sky_btn";
pickSkyBtn.style.display = "none";
document.body.appendChild(pickSkyBtn);
makeFixture({ polarity: "levity", userRole: "PC" });
reloadSpy = jasmine.createSpy("reload");
SigSelect.setReload(reloadSpy);
spyOn(Tray, "open");
});
afterEach(() => {
if (pickSkyBtn) pickSkyBtn.remove();
SigSelect.setReload(function () { window.location.reload(); });
});
it("reloads the page so the sky overlay partial renders", () => {
pickSkyBtn.dispatchEvent(new MouseEvent("click", { bubbles: true }));
expect(reloadSpy).toHaveBeenCalled();
});
it("does NOT call Tray.open (tray was already played by Tray.placeSig)", () => {
pickSkyBtn.dispatchEvent(new MouseEvent("click", { bubbles: true }));
expect(Tray.open).not.toHaveBeenCalled();
});
});
});