import test from 'brittle'
import { PALETTE, pushRecent, addSwatch, removeSwatch, sameColor } from '../static/swatches.js'
test('palette: named lighting colours, all valid 0..1', (t) => {
t.ok(PALETTE.length >= 12)
for (const p of PALETTE) {
t.ok(p.name && [p.r, p.g, p.b].every((v) => v >= 0 && v <= 1), p.name)
t.ok(Math.max(p.r, p.g, p.b) === 1, p.name + ' normalised to full drive')
}
})
test('recent: newest first, no duplicates, capped at 8', (t) => {
let r = []
for (let i = 0; i < 10; i++) r = pushRecent(r, { r: i / 10, g: 0, b: 1 })
t.is(r.length, 8)
t.is(r[0].r, 0.9)
r = pushRecent(r, { r: 0.5, g: 0, b: 1 })
t.is(r[0].r, 0.5, 'reused colour moves to the front')
t.is(r.filter((c) => sameColor(c, { r: 0.5, g: 0, b: 1 })).length, 1, 'not duplicated')
})
test('my swatches: add skips duplicates, remove by index', (t) => {
let m = addSwatch([], { r: 1, g: 0, b: 0 })
m = addSwatch(m, { r: 1, g: 0, b: 0 })
t.is(m.length, 1)
m = addSwatch(m, { r: 0, g: 1, b: 0 })
t.alike(removeSwatch(m, 0), [{ r: 0, g: 1, b: 0 }])
})
test('colours within 1/255 count as the same', (t) => {
t.ok(sameColor({ r: 1, g: 0.5, b: 0 }, { r: 1, g: 0.501, b: 0 }))
t.absent(sameColor({ r: 1, g: 0.5, b: 0 }, { r: 1, g: 0.52, b: 0 }))
})