// task-actions.test.mjs — button visibility logic for Cancel/Restart/Resume 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', 'CANCELLED']); function getCardAction(state) { if (state === 'PENDING') return 'run'; if (state === 'RUNNING') return 'cancel'; if (state === 'READY') return 'approve'; if (state === 'TIMED_OUT') return 'resume'; if (RESTART_STATES.has(state)) return 'restart'; return null; } function getApiEndpoint(state) { if (state === 'TIMED_OUT') return '/resume'; if (RESTART_STATES.has(state)) return '/run'; 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 Resume button for TIMED_OUT', () => { assert.equal(getCardAction('TIMED_OUT'), 'resume'); }); 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); }); }); describe('task action API endpoints', () => { it('TIMED_OUT uses /resume endpoint', () => { assert.equal(getApiEndpoint('TIMED_OUT'), '/resume'); }); it('FAILED uses /run endpoint', () => { assert.equal(getApiEndpoint('FAILED'), '/run'); }); it('CANCELLED uses /run endpoint', () => { assert.equal(getApiEndpoint('CANCELLED'), '/run'); }); });