cat / goq
clone

turns a linux box into a private steam streaming appliance: plug in, tap your key, play from another computer

release/portal-packaging
goq / portal / focus-overlay.test.mjs
focus-overlay.test.mjs 2.7K
1import test from 'node:test';2import assert from 'node:assert/strict';3import fs from 'node:fs';45import {6 focusOverlayStillCurrent,7 handoffProposalForSelf,8 preemptionCandidateForSelf,9} from './focus-overlay.mjs';1011const html = fs.readFileSync(new URL('./index.html', import.meta.url), 'utf8');12const main = fs.readFileSync(new URL('./main.js', import.meta.url), 'utf8');1314function session() {15 return {16 eligible: true,17 focused: true,18 snapshot: {19 revision: 4,20 self_presence_id: 'viewer-a',21 self_is_focus_owner: false,22 viewers: [23 { presence_id: 'viewer-a', session_id: 1, you: true, input_capable: true },24 { presence_id: 'viewer-b', session_id: 2, you: false, input_capable: true },25 ],26 focus: { state: 'held', holder: 'viewer-a', session_id: 1, focus_generation: 8 },27 focus_proposal: {28 proposal_id: 3,29 holder: 'viewer-a',30 holder_session_id: 1,31 requester: 'viewer-b',32 requester_session_id: 2,33 },34 },35 };36}3738test('holder sees one opaque handoff proposal and stale proposals dismiss immediately', () => {39 const current = session();40 const overlay = handoffProposalForSelf(current);41 assert.deepEqual(overlay, {42 type: 'handoff', proposalId: 3, requester: 'viewer-b', revision: 4,43 });44 assert.equal(focusOverlayStillCurrent(overlay, current), true);45 current.snapshot = { ...current.snapshot, revision: 5, focus_proposal: null };46 assert.equal(focusOverlayStillCurrent(overlay, current), false);47});4849test('only configured owner receives an exact-holder preemption candidate', () => {50 const current = session();51 current.focused = false;52 current.snapshot = {53 ...current.snapshot,54 self_is_focus_owner: true,55 focus_proposal: null,56 focus: { state: 'held', holder: 'viewer-b', session_id: 2, focus_generation: 9 },57 };58 const overlay = preemptionCandidateForSelf(current);59 assert.equal(overlay.holder, 'viewer-b');60 assert.equal(focusOverlayStillCurrent(overlay, current), true);61 current.snapshot = { ...current.snapshot, revision: 5, focus: { state: 'vacant', slot: 0 } };62 assert.equal(focusOverlayStillCurrent(overlay, current), false);63});6465test('handoff and preemption dialogs are controller-scoped with safe defaults and Back behavior', () => {66 assert.match(html, /id="deny-focus-handoff" data-controller-focus/);67 assert.match(html, /id="cancel-focus-preempt" data-controller-focus/);68 assert.match(main, /if \(!handoff\.classList\.contains\('hidden'\)\) return handoff/);69 assert.match(main, /if \(!preempt\.classList\.contains\('hidden'\)\) return preempt/);70 assert.match(main, /void denyFocusHandoff\(\)/);71 assert.match(main, /cancelFocusPreempt\(\)/);72});