Files
vela-colorcast/tests/colorcast.cjs
T

57 lines
1.7 KiB
JavaScript

// ColorCast logic tests — pure module (no Vela APIs)
'use strict'
const assert = require('assert/strict')
const cast = require('/tmp/vela-colorcast/src/common/colorcast.js')
let passed = 0
function test(name, fn) {
try { fn(); passed++; console.log(' ok -', name) }
catch (e) { console.error(' FAIL -', name, '\n ', e.message); process.exitCode = 1 }
}
console.log('colorcast tests')
test('nextColor cycles RED -> GREEN', () => {
const n = cast.nextColor(-1) // initial state: nothing cast yet
assert.equal(n.name, 'RED')
assert.equal(cast.nextColor(n.index).name, 'GREEN')
})
test('full cycle RED, GREEN, BLUE, YELLOW, wraps to RED', () => {
const names = []
let idx = -1
for (let i = 0; i < 5; i++) {
const n = cast.nextColor(idx)
idx = n.index
names.push(n.name)
}
assert.deepEqual(names, ['RED', 'GREEN', 'BLUE', 'YELLOW', 'RED'])
})
test('payload is 3 bytes RGB matching the color', () => {
const blue = cast.COLORS[2]
const p = cast.payload(blue)
assert.equal(p.byteLength, 3)
const v = new Uint8Array(p)
assert.deepEqual([...v], [blue.r, blue.g, blue.b])
})
test('UUIDs match the Android companion', () => {
assert.equal(cast.SERVICE_UUID, '0000fee7-0000-1000-8000-00805f9b34fb')
assert.equal(cast.CHAR_UUID, '0000fee8-0000-1000-8000-00805f9b34fb')
})
test('advertised name matches Android NAME constant', () => {
assert.equal(cast.ADVERTISED_NAME, 'ILIAS-COLOR')
})
test('every color has r/g/b in range', () => {
for (const c of cast.COLORS) {
for (const k of ['r', 'g', 'b']) {
assert.ok(c[k] >= 0 && c[k] <= 255, c.name + '.' + k)
}
}
})
console.log(process.exitCode ? 'FAILED' : 'ALL PASSED (' + passed + ')')