summaryrefslogtreecommitdiff
path: root/web/test/task-actions.test.mjs
blob: c7d666b703c36f982b38fb2228671ed0bcb774d0 (plain)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// 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', 'BUDGET_EXCEEDED']);

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 Restart button for BUDGET_EXCEEDED', () => {
    assert.equal(getCardAction('BUDGET_EXCEEDED'), '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);
  });
});

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');
  });

  it('BUDGET_EXCEEDED uses /run endpoint', () => {
    assert.equal(getApiEndpoint('BUDGET_EXCEEDED'), '/run');
  });
});