diff options
Diffstat (limited to 'web/test/task-actions.test.mjs')
| -rw-r--r-- | web/test/task-actions.test.mjs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/web/test/task-actions.test.mjs b/web/test/task-actions.test.mjs new file mode 100644 index 0000000..f2c21c4 --- /dev/null +++ b/web/test/task-actions.test.mjs @@ -0,0 +1,53 @@ +// 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); + }); +}); |
