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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
// filter-tabs.test.mjs — TDD contract tests for filterTasksByTab
//
// Run with: node --test web/test/filter-tabs.test.mjs
import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
import { filterTasksByTab } from '../app.js';
// ── Helpers ────────────────────────────────────────────────────────────────────
function makeTask(state) {
return { id: state, name: `task-${state}`, state };
}
const ALL_STATES = [
'PENDING', 'QUEUED', 'RUNNING', 'READY', 'BLOCKED',
'COMPLETED', 'FAILED', 'TIMED_OUT', 'CANCELLED', 'BUDGET_EXCEEDED',
];
// ── Tests ──────────────────────────────────────────────────────────────────────
describe('filterTasksByTab — active tab', () => {
it('includes PENDING, QUEUED, RUNNING, READY, BLOCKED', () => {
const tasks = ALL_STATES.map(makeTask);
const result = filterTasksByTab(tasks, 'active');
for (const state of ['PENDING', 'QUEUED', 'RUNNING', 'READY', 'BLOCKED']) {
assert.ok(result.some(t => t.state === state), `${state} should be included`);
}
});
it('excludes COMPLETED, FAILED, TIMED_OUT, CANCELLED, BUDGET_EXCEEDED', () => {
const tasks = ALL_STATES.map(makeTask);
const result = filterTasksByTab(tasks, 'active');
for (const state of ['COMPLETED', 'FAILED', 'TIMED_OUT', 'CANCELLED', 'BUDGET_EXCEEDED']) {
assert.ok(!result.some(t => t.state === state), `${state} should be excluded`);
}
});
it('returns empty array for empty input', () => {
assert.deepEqual(filterTasksByTab([], 'active'), []);
});
});
describe('filterTasksByTab — interrupted tab', () => {
it('includes CANCELLED and FAILED', () => {
const tasks = ALL_STATES.map(makeTask);
const result = filterTasksByTab(tasks, 'interrupted');
for (const state of ['CANCELLED', 'FAILED']) {
assert.ok(result.some(t => t.state === state), `${state} should be included`);
}
});
it('excludes all non-interrupted states', () => {
const tasks = ALL_STATES.map(makeTask);
const result = filterTasksByTab(tasks, 'interrupted');
for (const state of ['PENDING', 'QUEUED', 'RUNNING', 'READY', 'BLOCKED', 'COMPLETED', 'TIMED_OUT', 'BUDGET_EXCEEDED']) {
assert.ok(!result.some(t => t.state === state), `${state} should be excluded`);
}
});
it('returns empty array for empty input', () => {
assert.deepEqual(filterTasksByTab([], 'interrupted'), []);
});
});
describe('filterTasksByTab — done tab', () => {
it('includes COMPLETED, TIMED_OUT, BUDGET_EXCEEDED', () => {
const tasks = ALL_STATES.map(makeTask);
const result = filterTasksByTab(tasks, 'done');
for (const state of ['COMPLETED', 'TIMED_OUT', 'BUDGET_EXCEEDED']) {
assert.ok(result.some(t => t.state === state), `${state} should be included`);
}
});
it('excludes CANCELLED and FAILED (moved to interrupted tab)', () => {
const tasks = ALL_STATES.map(makeTask);
const result = filterTasksByTab(tasks, 'done');
for (const state of ['CANCELLED', 'FAILED']) {
assert.ok(!result.some(t => t.state === state), `${state} should be excluded from done`);
}
});
it('excludes PENDING, QUEUED, RUNNING, READY, BLOCKED', () => {
const tasks = ALL_STATES.map(makeTask);
const result = filterTasksByTab(tasks, 'done');
for (const state of ['PENDING', 'QUEUED', 'RUNNING', 'READY', 'BLOCKED']) {
assert.ok(!result.some(t => t.state === state), `${state} should be excluded`);
}
});
it('returns empty array for empty input', () => {
assert.deepEqual(filterTasksByTab([], 'done'), []);
});
});
describe('filterTasksByTab — all tab', () => {
it('returns all tasks unchanged', () => {
const tasks = ALL_STATES.map(makeTask);
const result = filterTasksByTab(tasks, 'all');
assert.equal(result.length, ALL_STATES.length);
assert.strictEqual(result, tasks, 'should return the same array reference');
});
it('returns empty array for empty input', () => {
assert.deepEqual(filterTasksByTab([], 'all'), []);
});
});
describe('filterTasksByTab — unknown tab', () => {
it('returns all tasks as defensive fallback', () => {
const tasks = ALL_STATES.map(makeTask);
const result = filterTasksByTab(tasks, 'unknown-tab');
assert.equal(result.length, ALL_STATES.length);
assert.strictEqual(result, tasks, 'should return the same array reference');
});
});
|