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
|
// task-actions.test.mjs — button visibility logic for Cancel/Restart actions
//
// Run with: node --test web/test/task-actions.test.mjs
import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
// ── Logic under test ──────────────────────────────────────────────────────────
const RESTART_STATES = new Set(['FAILED', 'TIMED_OUT', 'CANCELLED']);
function getCardAction(state) {
if (state === 'PENDING') return 'run';
if (state === 'RUNNING') return 'cancel';
if (state === 'READY') return 'approve';
if (RESTART_STATES.has(state)) return 'restart';
return null;
}
// ── Tests ─────────────────────────────────────────────────────────────────────
describe('task card action buttons', () => {
it('shows Run button for PENDING', () => {
assert.equal(getCardAction('PENDING'), 'run');
});
it('shows Cancel button for RUNNING', () => {
assert.equal(getCardAction('RUNNING'), 'cancel');
});
it('shows Restart button for FAILED', () => {
assert.equal(getCardAction('FAILED'), 'restart');
});
it('shows Restart button for TIMED_OUT', () => {
assert.equal(getCardAction('TIMED_OUT'), 'restart');
});
it('shows Restart button for CANCELLED', () => {
assert.equal(getCardAction('CANCELLED'), 'restart');
});
it('shows approve buttons for READY', () => {
assert.equal(getCardAction('READY'), 'approve');
});
it('shows no button for COMPLETED', () => {
assert.equal(getCardAction('COMPLETED'), null);
});
it('shows no button for QUEUED', () => {
assert.equal(getCardAction('QUEUED'), null);
});
it('shows no button for BUDGET_EXCEEDED', () => {
assert.equal(getCardAction('BUDGET_EXCEEDED'), null);
});
});
|