1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
// cancel-blocked.test.mjs — cancel button visibility for BLOCKED tasks
//
// Run with: node --test web/test/cancel-blocked.test.mjs
import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
// ── Logic under test ──────────────────────────────────────────────────────────
// BLOCKED tasks must show a Cancel button (in addition to question/subtask UI).
// The cancel button should be visible for BLOCKED, RUNNING, and other active states.
const CANCEL_STATES = new Set(['RUNNING', 'BLOCKED']);
function showCancelButton(state) {
return CANCEL_STATES.has(state);
}
function getCancelEndpoint(taskId) {
return `/api/tasks/${taskId}/cancel`;
}
// ── Tests ─────────────────────────────────────────────────────────────────────
describe('cancel button visibility for BLOCKED tasks', () => {
it('shows Cancel button for BLOCKED', () => {
assert.equal(showCancelButton('BLOCKED'), true);
});
it('shows Cancel button for RUNNING', () => {
assert.equal(showCancelButton('RUNNING'), true);
});
it('does not show Cancel button for PENDING', () => {
assert.equal(showCancelButton('PENDING'), false);
});
it('does not show Cancel button for COMPLETED', () => {
assert.equal(showCancelButton('COMPLETED'), false);
});
it('does not show Cancel button for QUEUED', () => {
assert.equal(showCancelButton('QUEUED'), false);
});
it('does not show Cancel button for FAILED', () => {
assert.equal(showCancelButton('FAILED'), false);
});
it('does not show Cancel button for CANCELLED', () => {
assert.equal(showCancelButton('CANCELLED'), false);
});
it('does not show Cancel button for READY', () => {
assert.equal(showCancelButton('READY'), false);
});
});
describe('cancel API endpoint for BLOCKED tasks', () => {
it('uses correct cancel endpoint for a BLOCKED task', () => {
assert.equal(getCancelEndpoint('task-123'), '/api/tasks/task-123/cancel');
});
it('cancel endpoint uses POST method (no-op check — method is always POST)', () => {
// The cancel action always calls POST /api/tasks/{id}/cancel
const method = 'POST';
assert.equal(method, 'POST');
});
});
|