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
|
// deployment-badge.test.mjs — Unit tests for deployment status badge.
//
// Run with: node --test web/test/deployment-badge.test.mjs
import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
import { renderDeploymentBadge } from '../app.js';
function makeDoc() {
return {
createElement(tag) {
const el = {
tag,
className: '',
textContent: '',
title: '',
children: [],
appendChild(child) { this.children.push(child); return child; },
};
return el;
},
};
}
describe('renderDeploymentBadge', () => {
it('returns null for null status', () => {
const el = renderDeploymentBadge(null, makeDoc());
assert.equal(el, null);
});
it('returns null for undefined status', () => {
const el = renderDeploymentBadge(undefined, makeDoc());
assert.equal(el, null);
});
it('returns null when includes_fix is false', () => {
const status = { deployed_commit: 'abc123', fix_commits: [{ hash: 'aabbcc', message: 'fix' }], includes_fix: false };
const el = renderDeploymentBadge(status, makeDoc());
assert.equal(el, null);
});
it('returns element with deployment-badge class when includes_fix is true', () => {
const status = { deployed_commit: 'abc123', fix_commits: [{ hash: 'aabbcc', message: 'fix' }], includes_fix: true };
const el = renderDeploymentBadge(status, makeDoc());
assert.ok(el, 'element should not be null');
assert.ok(el.className.includes('deployment-badge'), `className should include deployment-badge, got: ${el.className}`);
});
it('shows "Deployed" text when includes_fix is true', () => {
const status = { deployed_commit: 'abc123', fix_commits: [{ hash: 'aabbcc', message: 'fix' }], includes_fix: true };
const el = renderDeploymentBadge(status, makeDoc());
assert.ok(el.textContent.includes('Deployed'), `expected "Deployed" in "${el.textContent}"`);
});
it('applies deployed class when includes_fix is true', () => {
const status = { deployed_commit: 'abc123', fix_commits: [{ hash: 'aabbcc', message: 'fix' }], includes_fix: true };
const el = renderDeploymentBadge(status, makeDoc());
assert.ok(el.className.includes('deployment-badge--deployed'), `className: ${el.className}`);
});
it('returns null for doc=null', () => {
const status = { deployed_commit: 'abc', fix_commits: [], includes_fix: true };
const el = renderDeploymentBadge(status, null);
assert.equal(el, null);
});
});
|