@bongos/core 1.21.53 → 1.21.54

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -271,26 +271,33 @@ function fakeDom() {
271
271
  }
272
272
  return { document: { documentElement: mk('html'), getElementById: (id) => byId.get(id) || null, createElement: (t) => mk(t), createElementNS: (_n, t) => mk(t) }, byId, focused };
273
273
  }
274
- async function bootPage(hash, ms, { refuse = false, over = {} } = {}) {
274
+ // xhr: an XMLHttpRequest stand-in (the recorded sign-off's upload); answer(url,
275
+ // body): a response of its own for a write, else the default; extra: more feeds
276
+ async function bootPage(hash, ms, { refuse = false, over = {}, xhr = null, answer = null, extra = {} } = {}) {
275
277
  const { document, byId, focused } = fakeDom();
276
278
  const sent = [];
277
279
  const store = new Map();
278
280
  let matters = ms.slice();
279
- const feeds = () => ({ '/api/bongos/government/docket': docket(matters, over), '/api/bongos/goals': { goals: [] }, '/api/bongos/goals/rollups': { rollups: [] } });
281
+ const feeds = () => ({ '/api/bongos/government/docket': docket(matters, over), '/api/bongos/goals': { goals: [] }, '/api/bongos/goals/rollups': { rollups: [] }, ...extra });
282
+ const reads = [];
280
283
  const location = { hash, href: '' };
281
284
  const window = {
282
285
  innerWidth: 1440, innerHeight: 900, location,
283
286
  localStorage: { getItem: (k) => (store.has(k) ? store.get(k) : null), setItem: (k, v) => store.set(k, String(v)) },
284
287
  matchMedia: () => ({ matches: true, addEventListener() {} }),
285
288
  addEventListener() {}, history: { pushState() {} },
289
+ XMLHttpRequest: xhr || undefined,
286
290
  };
287
291
  const fetch = (url, init) => {
288
292
  if (init && init.method && init.method !== 'GET') {
289
293
  sent.push({ method: init.method, url, body: JSON.parse(init.body || '{}') });
294
+ const own = answer ? answer(url, JSON.parse(init.body || '{}')) : null;
295
+ if (own) return Promise.resolve({ ok: own.status < 300, status: own.status, json: async () => own.body || {} });
290
296
  if (refuse) return Promise.resolve({ ok: false, status: 409, json: async () => ({ error: { code: 'not_pending' } }) });
291
297
  matters = matters.filter((m) => !url.includes('/' + String(m.id).split(':')[1]));
292
298
  return Promise.resolve({ ok: true, status: 200, json: async () => ({ ok: true }) });
293
299
  }
300
+ reads.push(url);
294
301
  const body = feeds()[url];
295
302
  return Promise.resolve(body === undefined ? { ok: false, json: async () => ({}) } : { ok: true, json: async () => body });
296
303
  };
@@ -301,7 +308,7 @@ async function bootPage(hash, ms, { refuse = false, over = {} } = {}) {
301
308
  await new Promise((r) => setTimeout(r, 0));
302
309
  const deskEl = () => (byId.get('insideOpenA').hidden ? byId.get('insideOpenB') : byId.get('insideOpenA'));
303
310
  const part = (cls) => deskEl().children.find((c) => c.className.split(' ').includes(cls));
304
- return { window, byId, focused, sent, store, deskEl, part };
311
+ return { window, byId, focused, sent, store, deskEl, part, reads };
305
312
  }
306
313
 
307
314
  test('the page: the desk acts in place — the row clears, the floor lights with a tick, the meter takes a pip, the toast speaks', async () => {
@@ -490,13 +497,16 @@ test('Automation: switch on and off, allow a goal from the open goals, first in
490
497
  assert.ok(!none.some((r) => r.actions.some((a) => a.key === 'allow')));
491
498
  });
492
499
 
493
- test('Review: a backend-only promise signs off in one tap; a recorded one goes to its page; force sign-off only with its atom', () => {
500
+ test('Review: a backend-only promise signs off in one tap; a recorded one is recorded in place; force sign-off only with its atom', () => {
494
501
  const rows = actedRows(actedDocket(), 'review', 1);
495
502
  const backend = rows.find((r) => r.actions[0].key === 'signoff');
496
503
  assert.deepEqual(j(C.request(backend.card, 'signoff', backend.choices.signoff.options[0].input)), { method: 'POST', url: '/api/bongos/done-when/8/uat', body: { kind: 'backend_signoff', live_attested: true } });
497
504
  assert.deepEqual(j(C.request(backend.card, 'force', backend.choices.force.options[0].input)), { method: 'POST', url: '/api/bongos/done-when/8/satisfy', body: { override_reason: 'Signed off on the floor desk: tested by hand.' } });
498
505
  const ui = rows.find((r) => r.actions[0].key === 'record');
499
- assert.equal(ui.actions[0].go, '/goals#/goal/4');
506
+ assert.equal(ui.actions[0].go, null, 'no link to the goal page (task 1004579)');
507
+ assert.equal(ui.actions[0].label, 'record it');
508
+ assert.deepEqual(j(ui.choices.record), { for: 'record', ask: 'the recording', file: true, options: [] }, 'it asks for the recording in place');
509
+ assert.ok(ui.actions.every((a) => !a.go), 'nothing on the row leaves the desk');
500
510
  const noForce = actedRows(actedDocket({ force: false }), 'review', 1);
501
511
  assert.ok(noForce.every((r) => !r.actions.some((a) => a.key === 'force')));
502
512
  });
@@ -935,3 +945,358 @@ test('walkthrough 1004531: a card act that records nothing takes no pip', async
935
945
  await settle();
936
946
  assert.equal(p.byId.get('streetTodayN').textContent, '0 decided', 'a refused act is not a decision');
937
947
  });
948
+
949
+ // ── the recorded sign-off from the card (task 1004579) ───────────────────────
950
+ // A promise that needs a recording is recorded in place: the file is picked or
951
+ // dropped on its one line, sent with its progress on that line, then signed off
952
+ // through the goal page's own two routes. The row clears, the meter takes a
953
+ // pip, the toast speaks; a refused or failed upload says why on the line and
954
+ // offers to try again, and counts nothing.
955
+ const REC_NAME = 'uat-9-0123456789abcdef.mp4';
956
+ const VIDEO = { name: 'walkthrough of the city.mp4', type: 'video/mp4', size: 12 * 1024 * 1024 };
957
+ const uatMatters = () => [DK.normalizeMatter(lifeDocket.uatMatter({ id: 9, criterion_md: 'The city draws', goal_id: 4, shipped_total: 2, backend_only: false }, { force: false }), { source: 'criteria_uat', building: 'review' })];
958
+ // an XMLHttpRequest stand-in: each send takes the next planned answer; `hold`
959
+ // keeps it open until the test lets it go, so progress can be seen mid-flight
960
+ function fakeXhr(plan = []) {
961
+ const calls = [];
962
+ const held = [];
963
+ class X {
964
+ constructor() { this.upload = {}; this.headers = {}; }
965
+ open(method, url) { this.method = method; this.url = url; }
966
+ setRequestHeader(k, v) { this.headers[k] = v; }
967
+ send(file) {
968
+ calls.push({ method: this.method, url: this.url, type: this.headers['Content-Type'], file, withCredentials: this.withCredentials, xhr: this });
969
+ const p = plan.shift() || { status: 201, body: { ok: true, recording: REC_NAME } };
970
+ const go = () => {
971
+ (p.progress || []).forEach((n) => this.upload.onprogress && this.upload.onprogress({ lengthComputable: true, loaded: n, total: 100 }));
972
+ if (p.status === 0) { this.onerror(); return; }
973
+ this.status = p.status;
974
+ this.responseText = JSON.stringify(p.body || {});
975
+ this.onload();
976
+ };
977
+ if (p.hold) held.push(go); else setTimeout(go, 0);
978
+ }
979
+ }
980
+ return { X, calls, held };
981
+ }
982
+ function walk(n, pred, out = []) {
983
+ if (!n) return out;
984
+ if (pred(n)) out.push(n);
985
+ (n.kids || []).forEach((k) => walk(k, pred, out));
986
+ return out;
987
+ }
988
+ const byAct = (root, act) => walk(root, (n) => n.attrs && n.attrs['data-act'] === act)[0];
989
+ const recLine = (root) => walk(root, (n) => /\brec__line\b/.test(n.className))[0];
990
+ const recBox = (root) => walk(root, (n) => /(^| )rec( |$)/.test(n.className))[0];
991
+ const fileInput = (root) => walk(root, (n) => n.attrs && n.attrs.type === 'file')[0];
992
+ function pickFile(root, file) {
993
+ const input = fileInput(root);
994
+ input.files = [file];
995
+ input.fire('change');
996
+ }
997
+ async function reviewDesk(opts = {}) {
998
+ const p = await bootPage('#building=review', uatMatters(), opts);
999
+ const row = () => p.part('desk-rows') && p.part('desk-rows').children[0];
1000
+ return { ...p, row };
1001
+ }
1002
+
1003
+ test('1004579 the line: what it says in each phase, in one line, with at most two chips', () => {
1004
+ assert.deepEqual(j(C.recordLine({ phase: 'empty' })), { text: 'mp4 or webm, up to 100 MB', pct: null, busy: false, error: false, chips: [{ key: 'pick', label: 'pick or drop it' }] });
1005
+ const picked = C.recordPick({}, VIDEO);
1006
+ assert.equal(picked.phase, 'picked');
1007
+ assert.deepEqual(j(C.recordLine(picked)).chips, [{ key: 'pick', label: 'pick another' }, { key: 'send', label: 'tested it live' }], 'the live attestation is the one-tap chip that sends it');
1008
+ assert.equal(C.recordLine(picked).text, 'walkthrough of the city.mp4 · 12 MB');
1009
+ assert.equal(C.recordLine({ file: VIDEO, phase: 'uploading', pct: 42 }).text, 'walkthrough of the city.mp4 · 42% sent');
1010
+ assert.equal(C.recordLine({ file: VIDEO, phase: 'uploading', pct: 42 }).pct, 42);
1011
+ assert.deepEqual(C.recordLine({ file: VIDEO, phase: 'uploading', pct: 42 }).chips, [], 'nothing to tap while it is sent');
1012
+ assert.equal(C.recordLine({ file: VIDEO, phase: 'signing' }).text, 'walkthrough of the city.mp4 · sent, signing off…');
1013
+ for (const st of [{ phase: 'empty' }, picked, { file: VIDEO, phase: 'uploading', pct: 99 }, { file: VIDEO, phase: 'failed', why: C.recordWhy(0, {}), retry: true }]) {
1014
+ const ln = C.recordLine(st);
1015
+ assert.ok(!/[\r\n]/.test(ln.text), 'one line');
1016
+ assert.ok(ln.chips.length <= 2, 'at most two chips');
1017
+ assert.ok(ln.chips.every((c) => c.label.length <= D.LIMITS.chip), 'each chip within the desk chip cap');
1018
+ }
1019
+ const long = C.recordPick({}, { name: 'a very long name for a screen recording of the whole walkthrough.webm', type: 'video/webm', size: 2048 });
1020
+ assert.ok(C.recordLine(long).text.length <= 40, 'a long file name is cut, never wrapped');
1021
+ });
1022
+
1023
+ test('1004579 a wrong file says why before anything is sent, and asks for another', () => {
1024
+ const st = C.recordPick({}, { name: 'notes.pdf', type: 'application/pdf', size: 100 });
1025
+ assert.equal(st.phase, 'failed');
1026
+ assert.equal(st.why, 'Only an mp4 or webm video can go.');
1027
+ assert.deepEqual(j(C.recordLine(st).chips), [{ key: 'pick', label: 'pick another' }], 'no "try again" for a file that cannot go');
1028
+ assert.equal(C.recordPick({}, { name: 'big.mp4', type: 'video/mp4', size: C.RECORD_MAX + 1 }).why, 'Over the 100 MB cap. Record a shorter pass.');
1029
+ assert.equal(C.recordPick({}, { name: 'empty.webm', type: 'video/webm', size: 0 }).why, 'That file is empty.');
1030
+ assert.deepEqual(C.RECORD_TYPES, ['video/mp4', 'video/webm']);
1031
+ const lifecycle = SRV('modules/lifecycle/criterion-uat.js');
1032
+ assert.deepEqual(C.RECORD_TYPES.slice().sort(), Object.keys(lifecycle.EXT_BY_TYPE).sort(), 'the same types the server stores');
1033
+ assert.equal(C.RECORD_MAX, lifecycle.MAX_RECORDING_BYTES, 'the same cap the server screens');
1034
+ });
1035
+
1036
+ test('1004579 the routes are the goal page\'s own two: the raw video, then the sign-off with its stored name', () => {
1037
+ const r = C.recordRoutes(9);
1038
+ assert.equal(r.upload, '/api/bongos/done-when/9/uat/recording');
1039
+ assert.deepEqual(j(r.signoff(REC_NAME)), { method: 'POST', url: '/api/bongos/done-when/9/uat', body: { kind: 'uat', recording: REC_NAME, live_attested: true } });
1040
+ const old = read('criterion-uat-ui.js');
1041
+ assert.match(old, /\/done-when\/\$\{encodeURIComponent\(id\)\}\/uat\/recording/, 'the goal page uploads to the same route');
1042
+ assert.match(old, /kind: backend \? 'backend_signoff' : 'uat'/, 'and signs off with the same kind');
1043
+ const route = read('../../lifecycle/routes/criterion-uat.js');
1044
+ assert.match(route, /router\.post\('\/done-when\/:criterionId\/uat\/recording'/);
1045
+ assert.match(route, /router\.post\('\/done-when\/:criterionId\/uat',/);
1046
+ });
1047
+
1048
+ test('1004579 a refusal is one short sentence a person can act on', () => {
1049
+ const said = [
1050
+ [413, {}],
1051
+ [400, { error: { code: 'bad_type', message: 'A UAT recording must be an mp4 or webm video.' } }],
1052
+ [403, { error: { code: 'signer_shipped_this_work', message: 'You shipped work linked to this criterion, so someone else has to sign it off. Any other reviewer, or the project owner, can.' } }],
1053
+ [409, { error: { code: 'work_not_live', message: 'Some of this work is shipped but not running on the site yet.' } }],
1054
+ [0, {}],
1055
+ [500, { error: { code: 'uat_signoff_failed', message: 'uat_signoff_failed' } }],
1056
+ [409, { error: { code: 'something_new', message: 'A brand new refusal from the server. With a second sentence that goes on and on.' } }],
1057
+ ].map(([s, b]) => C.recordWhy(s, b));
1058
+ assert.deepEqual(said, [
1059
+ 'Over the 100 MB cap. Record a shorter pass.',
1060
+ 'Only an mp4 or webm video can go.',
1061
+ 'You built this, so someone else signs it off.',
1062
+ 'It is not on the live site yet. Sign off once it is.',
1063
+ 'The upload broke off. Try again.',
1064
+ 'It did not go through. Try again.',
1065
+ 'A brand new refusal from the server.',
1066
+ ]);
1067
+ for (const w of said) { assert.ok(w.length <= 72, w); assert.ok(!/[\r\n]/.test(w)); }
1068
+ });
1069
+
1070
+ test('1004579 recordRun: sends the video with its progress, then signs off with the stored name', async () => {
1071
+ const st = C.recordPick({}, VIDEO);
1072
+ const phases = [];
1073
+ const pcts = [];
1074
+ const sent = [];
1075
+ const out = await C.recordRun('9', st, {
1076
+ upload: async (url, file, onPct) => { assert.equal(url, '/api/bongos/done-when/9/uat/recording'); assert.equal(file, VIDEO); onPct(30); onPct(80); return { ok: true, status: 201, body: { recording: REC_NAME } }; },
1077
+ send: async (req) => { sent.push(j(req)); return { ok: true, status: 201, body: { ok: true, criterion_closed: true } }; },
1078
+ change: (s) => phases.push(s.phase),
1079
+ progress: (s) => pcts.push(s.pct),
1080
+ });
1081
+ assert.equal(out.ok, true);
1082
+ assert.deepEqual(phases, ['uploading', 'signing']);
1083
+ assert.deepEqual(pcts, [30, 80]);
1084
+ assert.deepEqual(sent, [{ method: 'POST', url: '/api/bongos/done-when/9/uat', body: { kind: 'uat', recording: REC_NAME, live_attested: true } }]);
1085
+ assert.equal(st.phase, 'done');
1086
+ });
1087
+
1088
+ test('1004579 recordRun: a failed upload says why and offers to try again; a refused sign-off keeps the upload, so trying again does not send the video twice', async () => {
1089
+ const st = C.recordPick({}, VIDEO);
1090
+ let uploads = 0;
1091
+ const broke = await C.recordRun('9', st, { upload: async () => { uploads += 1; return { ok: false, status: 0, body: {} }; }, send: async () => assert.fail('no sign-off after a failed upload') });
1092
+ assert.equal(broke.ok, false);
1093
+ assert.equal(st.phase, 'failed');
1094
+ assert.equal(C.recordLine(st).text, 'The upload broke off. Try again.');
1095
+ assert.deepEqual(C.recordLine(st).chips.map((c) => c.label), ['try again', 'pick another']);
1096
+ let signs = 0;
1097
+ const refused = await C.recordRun('9', st, {
1098
+ upload: async () => { uploads += 1; return { ok: true, status: 201, body: { recording: REC_NAME } }; },
1099
+ send: async () => { signs += 1; return signs === 1 ? { ok: false, status: 409, body: { error: { code: 'work_not_live', message: 'x' } } } : { ok: true, status: 201, body: {} }; },
1100
+ });
1101
+ assert.equal(refused.ok, false);
1102
+ assert.equal(C.recordLine(st).text, 'It is not on the live site yet. Sign off once it is.');
1103
+ assert.equal(st.recording, REC_NAME, 'the stored recording is kept');
1104
+ const again = await C.recordRun('9', st, { upload: async () => assert.fail('the video is not sent twice'), send: async () => { signs += 1; return { ok: true, status: 201, body: {} }; } });
1105
+ assert.equal(again.ok, true);
1106
+ assert.equal(uploads, 2);
1107
+ // a refusal no new try can fix offers neither a retry nor (for a sign-off that is not yours) another file
1108
+ const mine = C.recordPick({}, VIDEO);
1109
+ await C.recordRun('9', mine, { upload: async () => ({ ok: true, status: 201, body: { recording: REC_NAME } }), send: async () => ({ ok: false, status: 403, body: { error: { code: 'signer_shipped_this_work' } } }) });
1110
+ assert.deepEqual(C.recordLine(mine).chips, [], 'you built it: nothing to tap but close');
1111
+ assert.equal(C.recordLine(mine).text, 'You built this, so someone else signs it off.');
1112
+ // a file the server refused asks for another file, not the same one again
1113
+ const odd = C.recordPick({}, VIDEO);
1114
+ await C.recordRun('9', odd, { upload: async () => ({ ok: false, status: 400, body: { error: { code: 'sniff_mismatch' } } }), send: async () => assert.fail() });
1115
+ assert.deepEqual(C.recordLine(odd).chips.map((c) => c.key), ['pick']);
1116
+ });
1117
+
1118
+ test('1004579 uploadXhr: the raw file with its type, its progress, and the answer', async () => {
1119
+ const x = fakeXhr([{ status: 201, body: { ok: true, recording: REC_NAME }, progress: [25, 50, 100] }]);
1120
+ const pcts = [];
1121
+ const out = await C.uploadXhr(x.X, '/api/bongos/done-when/9/uat/recording', VIDEO, (p) => pcts.push(p));
1122
+ assert.deepEqual(out, { ok: true, status: 201, body: { ok: true, recording: REC_NAME } });
1123
+ assert.deepEqual(x.calls.map((c) => [c.method, c.url, c.type, c.file === VIDEO, c.withCredentials]), [['POST', '/api/bongos/done-when/9/uat/recording', 'video/mp4', true, true]]);
1124
+ assert.deepEqual(pcts, [25, 50, 99], 'the bar stops short of full until the server has answered');
1125
+ const broke = await C.uploadXhr(fakeXhr([{ status: 0 }]).X, '/u', VIDEO, () => {});
1126
+ assert.deepEqual(broke, { ok: false, status: 0, body: {} });
1127
+ const none = await C.uploadXhr(undefined, '/u', VIDEO, () => {});
1128
+ assert.equal(none.ok, false, 'no XMLHttpRequest: a failure, never a throw');
1129
+ });
1130
+
1131
+ test('1004579 the page: record it opens its line in place, the upload shows its progress, and the sign-off clears the row', async () => {
1132
+ const x = fakeXhr([{ status: 201, body: { ok: true, recording: REC_NAME }, hold: true }]);
1133
+ const p = await reviewDesk({ xhr: x.X });
1134
+ assert.equal(p.byId.get('insideFloors').children[1].attrs['aria-pressed'], 'true', 'Review opens on the promises waiting for a tester');
1135
+ const acts = p.row().children[0].children[2].children;
1136
+ assert.deepEqual(acts.map((b) => b.textContent), ['record it']);
1137
+ assert.ok(walk(p.deskEl(), (n) => n.tagName === 'a').length === 0, 'no link on the desk');
1138
+ acts[0].fire('click');
1139
+ const strip = p.row().children[1];
1140
+ assert.equal(strip.className, 'desk-choices');
1141
+ assert.equal(strip.children[0].textContent, 'the recording');
1142
+ assert.equal(recLine(strip).textContent, 'mp4 or webm, up to 100 MB');
1143
+ assert.equal(fileInput(strip).attrs.accept, 'video/mp4,video/webm');
1144
+ pickFile(strip, VIDEO);
1145
+ assert.equal(recLine(p.row()).textContent, 'walkthrough of the city.mp4 · 12 MB');
1146
+ const go = byAct(p.row(), 'record-send');
1147
+ assert.equal(go.textContent, 'tested it live');
1148
+ assert.equal(p.focused.el, go, 'focus moves to the chip that sends it');
1149
+ go.fire('click');
1150
+ await settle();
1151
+ assert.equal(x.calls.length, 1, 'the video went up');
1152
+ assert.match(recLine(p.row()).textContent, /0% sent$/);
1153
+ const line = recLine(p.row());
1154
+ x.held.shift()();
1155
+ await settle();
1156
+ assert.equal(p.sent.length, 1, 'then the sign-off');
1157
+ assert.deepEqual(p.sent[0], { method: 'POST', url: '/api/bongos/done-when/9/uat', body: { kind: 'uat', recording: REC_NAME, live_attested: true } });
1158
+ await new Promise((r) => setTimeout(r, 360));
1159
+ await settle();
1160
+ assert.equal(p.part('desk-rows'), undefined, 'the row cleared away');
1161
+ assert.ok(p.part('desk-quiet').className.includes('desk-quiet--cleared'), 'the floor lights');
1162
+ assert.equal(p.byId.get('streetTodayN').textContent, '1 decided', 'the meter takes a pip');
1163
+ assert.equal(p.byId.get('streetToast').textContent, 'Signed off with the recording. The promise counts as kept.');
1164
+ assert.match(p.byId.get('streetToast').className, /street-toast--desk/);
1165
+ assert.equal(p.part('desk-record').children[1].textContent, 'signed off The city dra… · now', 'the record gains the line (cut at the record cap)');
1166
+ assert.ok(line, 'the line was drawn while it was sent');
1167
+ });
1168
+
1169
+ test('1004579 the page: progress is painted on the line in place while the video is sent', async () => {
1170
+ const x = fakeXhr([{ status: 201, body: { ok: true, recording: REC_NAME }, hold: true }]);
1171
+ const p = await reviewDesk({ xhr: x.X });
1172
+ p.row().children[0].children[2].children[0].fire('click');
1173
+ pickFile(p.row(), VIDEO);
1174
+ byAct(p.row(), 'record-send').fire('click');
1175
+ await settle();
1176
+ const line = recLine(p.row());
1177
+ const fill = walk(p.row(), (n) => n.className === 'rec__fill')[0];
1178
+ assert.ok(walk(p.row(), (n) => /\brec--busy\b/.test(n.className))[0], 'the line reads as busy while it is sent');
1179
+ assert.equal(fileInput(p.row()), undefined, 'no file chip while it is sent');
1180
+ assert.equal(line.textContent, 'walkthrough of the city.mp4 · 0% sent');
1181
+ assert.equal(fill.style.width, '0%');
1182
+ // the open request reports progress through its own upload hook
1183
+ x.calls[0].xhr.upload.onprogress({ lengthComputable: true, loaded: 42, total: 100 });
1184
+ assert.equal(recLine(p.row()), line, 'the same line node: progress never redraws the desk');
1185
+ assert.equal(line.textContent, 'walkthrough of the city.mp4 · 42% sent');
1186
+ assert.equal(fill.style.width, '42%', 'the bar fills');
1187
+ x.calls[0].xhr.upload.onprogress({ lengthComputable: true, loaded: 100, total: 100 });
1188
+ assert.equal(line.textContent, 'walkthrough of the city.mp4 · 99% sent', 'never full before the server answers');
1189
+ x.held.shift()();
1190
+ await settle();
1191
+ assert.equal(p.sent.length, 1, 'the sign-off follows the upload');
1192
+ });
1193
+
1194
+ test('1004579 the page: a refused upload says why on the line, keeps the row, counts nothing, and lets them try again', async () => {
1195
+ const x = fakeXhr([{ status: 413, body: {} }, { status: 0 }, { status: 201, body: { ok: true, recording: REC_NAME } }]);
1196
+ const p = await reviewDesk({ xhr: x.X });
1197
+ p.row().children[0].children[2].children[0].fire('click');
1198
+ pickFile(p.row(), VIDEO);
1199
+ byAct(p.row(), 'record-send').fire('click');
1200
+ await settle();
1201
+ assert.equal(recLine(p.row()).textContent, 'Over the 100 MB cap. Record a shorter pass.');
1202
+ assert.equal(recLine(p.row()).attrs.role, 'alert', 'the why is said, not just shown');
1203
+ assert.equal(recBox(p.row()).attrs['data-record'], 'failed');
1204
+ assert.equal(byAct(p.row(), 'record-send'), undefined, 'a file over the cap is not offered again');
1205
+ assert.ok(fileInput(p.row()), 'pick another is offered');
1206
+ assert.equal(p.byId.get('streetTodayN').textContent, '0 decided');
1207
+ assert.equal(p.sent.length, 0, 'no sign-off after a refused upload');
1208
+ assert.equal(p.part('desk-rows').children.length, 1, 'the row stays');
1209
+ // another file; the connection breaks; try again goes through
1210
+ pickFile(p.row(), VIDEO);
1211
+ byAct(p.row(), 'record-send').fire('click');
1212
+ await settle();
1213
+ assert.equal(recLine(p.row()).textContent, 'The upload broke off. Try again.');
1214
+ const retry = byAct(p.row(), 'record-send');
1215
+ assert.equal(retry.textContent, 'try again');
1216
+ retry.fire('click');
1217
+ await settle();
1218
+ await new Promise((r) => setTimeout(r, 360));
1219
+ await settle();
1220
+ assert.equal(x.calls.length, 3);
1221
+ assert.equal(p.sent.length, 1);
1222
+ assert.equal(p.part('desk-rows'), undefined, 'signed off on the retry: the row cleared');
1223
+ assert.equal(p.byId.get('streetTodayN').textContent, '1 decided');
1224
+ });
1225
+
1226
+ test('1004579 the page: a refused sign-off says why on the line; nothing is counted', async () => {
1227
+ const x = fakeXhr();
1228
+ const p = await reviewDesk({ xhr: x.X, answer: (url) => (/\/uat$/.test(url) ? { status: 403, body: { error: { code: 'signer_shipped_this_work', message: 'You shipped work linked to this criterion.' } } } : null) });
1229
+ p.row().children[0].children[2].children[0].fire('click');
1230
+ pickFile(p.row(), VIDEO);
1231
+ byAct(p.row(), 'record-send').fire('click');
1232
+ await settle();
1233
+ assert.equal(recLine(p.row()).textContent, 'You built this, so someone else signs it off.');
1234
+ assert.equal(p.byId.get('streetToast').hidden, true, 'the line says it; no toast claims a decision');
1235
+ assert.equal(p.byId.get('streetTodayN').textContent, '0 decided');
1236
+ assert.equal(p.part('desk-rows').children.length, 1);
1237
+ });
1238
+
1239
+ test('1004579 the page: a recording dropped on its row is taken and its line opens', async () => {
1240
+ const p = await reviewDesk({ xhr: fakeXhr().X });
1241
+ const row = p.row();
1242
+ row.listeners.drop[0]({ preventDefault() {}, dataTransfer: { files: [VIDEO] } });
1243
+ assert.equal(recLine(p.row()).textContent, 'walkthrough of the city.mp4 · 12 MB');
1244
+ assert.equal(byAct(p.row(), 'record-send').textContent, 'tested it live');
1245
+ });
1246
+
1247
+ test('1004579 the page: tapping its name opens the goal page\'s three checks in place', async () => {
1248
+ const view = { uat_state: 'awaiting_uat', checks: { code: true, live: { available: true, live: true }, uat: null, stale_uat: null } };
1249
+ const p = await reviewDesk({ xhr: fakeXhr().X, extra: { '/api/bongos/done-when/9/uat': view } });
1250
+ p.row().children[0].children[1].fire('click');
1251
+ await settle();
1252
+ assert.ok(p.reads.includes('/api/bongos/done-when/9/uat'), 'the same read the goal page opens');
1253
+ assert.deepEqual(p.row().children[1].children.map((x) => x.textContent), ['code done', 'running live', 'not signed off yet']);
1254
+ assert.deepEqual(D.breaks({ ...D.deskModel({ key: 'review', floor: 1, docket: docket(uatMatters()), now: NOW }) }), []);
1255
+ });
1256
+
1257
+ test('1004579 the card: record it on the street card records in place too, and the card closes on the sign-off', async () => {
1258
+ const x = fakeXhr();
1259
+ const view = { uat_state: 'awaiting_uat', checks: { code: true, live: { available: false }, uat: null, stale_uat: { signed_off_by_login: 'mira', created_at: '2026-09-30T10:00:00.000Z' } } };
1260
+ const p = await bootPage('', uatMatters(), { xhr: x.X, extra: { '/api/bongos/done-when/9/uat': view } });
1261
+ p.window.GovStreetPage.openCard('criteria_uat:9');
1262
+ const body = p.byId.get('streetCardBody');
1263
+ const rec = byAct(body, 'record');
1264
+ assert.equal(rec.tagName, 'button', 'a button, not a link');
1265
+ assert.equal(walk(body, (n) => n.tagName === 'a').length, 0, 'no link on the card');
1266
+ // more: the checks the goal page showed
1267
+ byAct(body, 'more').fire('click');
1268
+ await settle();
1269
+ const more = walk(body, (n) => n.className === 'mcard-more')[0];
1270
+ const words = walk(more, (n) => n.className === 'mcard-more__text').map((n) => n.textContent);
1271
+ assert.ok(words.includes('code · every linked task is done'));
1272
+ assert.ok(words.includes('live · this site cannot tell, so the sign-off says you tried it live'));
1273
+ assert.ok(words.some((w) => /^sign-off · an earlier one by mira on .* no longer counts/.test(w)));
1274
+ byAct(body, 'more').fire('click');
1275
+ byAct(body, 'record').fire('click');
1276
+ assert.equal(walk(body, (n) => n.className === 'mcard-chips__ask')[0].textContent, 'the recording');
1277
+ pickFile(body, VIDEO);
1278
+ assert.equal(recLine(body).textContent, 'walkthrough of the city.mp4 · 12 MB');
1279
+ byAct(body, 'record-send').fire('click');
1280
+ await settle();
1281
+ await settle();
1282
+ assert.equal(x.calls.length, 1);
1283
+ assert.deepEqual(p.sent, [{ method: 'POST', url: '/api/bongos/done-when/9/uat', body: { kind: 'uat', recording: REC_NAME, live_attested: true } }]);
1284
+ assert.equal(p.byId.get('streetCard').hidden, true, 'the card closes: the matter is done');
1285
+ assert.equal(p.byId.get('streetTodayN').textContent, '1 decided');
1286
+ assert.equal(p.byId.get('streetToast').textContent, 'Signed off with the recording. The promise counts as kept.');
1287
+ });
1288
+
1289
+ test('1004579 the card: a failed upload says why on the card\'s line and keeps the card open', async () => {
1290
+ const x = fakeXhr([{ status: 400, body: { error: { code: 'bad_type', message: 'A UAT recording must be an mp4 or webm video.' } } }]);
1291
+ const p = await bootPage('', uatMatters(), { xhr: x.X });
1292
+ p.window.GovStreetPage.openCard('criteria_uat:9');
1293
+ const body = p.byId.get('streetCardBody');
1294
+ byAct(body, 'record').fire('click');
1295
+ pickFile(body, VIDEO);
1296
+ byAct(body, 'record-send').fire('click');
1297
+ await settle();
1298
+ assert.equal(recLine(body).textContent, 'Only an mp4 or webm video can go.');
1299
+ assert.equal(p.byId.get('streetCard').hidden, false);
1300
+ assert.equal(p.byId.get('streetTodayN').textContent, '0 decided');
1301
+ assert.equal(walk(body, (n) => n.className === 'mcard-error').length, 0, 'said once, on its own line');
1302
+ });