// 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 (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 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); }); });