47 lines
1.9 KiB
TypeScript
47 lines
1.9 KiB
TypeScript
import { expect, test } from "bun:test"
|
|
import { RGBA } from "@opentui/core"
|
|
import { blendTabPulseColor, completionPulseOpacity, unreadGlowIntensity } from "../../src/component/tab-pulse"
|
|
import { tint } from "../../src/theme/color"
|
|
|
|
test("completion pulse rises quickly and fades over the remaining duration", () => {
|
|
expect(completionPulseOpacity(0)).toBe(0)
|
|
expect(completionPulseOpacity(0.08)).toBeCloseTo(0.5)
|
|
expect(completionPulseOpacity(0.16)).toBe(1)
|
|
expect(completionPulseOpacity(0.58)).toBeCloseTo(0.5)
|
|
expect(completionPulseOpacity(1)).toBe(0)
|
|
})
|
|
|
|
test("unread glow peaks behind the tab number and fades to the normal background", () => {
|
|
const intensities = Array.from({ length: 22 }, (_, index) => unreadGlowIntensity(index, 22))
|
|
|
|
expect(intensities[0]).toBe(1)
|
|
expect(intensities[1]).toBe(1)
|
|
expect(intensities[2]).toBeLessThan(1)
|
|
expect(intensities.slice(1)).toEqual(intensities.slice(1).sort((a, b) => b - a))
|
|
expect(intensities[13]).toBe(0)
|
|
expect(intensities.at(-1)).toBe(0)
|
|
})
|
|
|
|
test("unread glow reaches the normal background on compact tabs", () => {
|
|
expect(unreadGlowIntensity(0, 8)).toBe(1)
|
|
expect(unreadGlowIntensity(7, 8)).toBe(0)
|
|
})
|
|
|
|
test("reuses a color while preserving the original glow and pulse blend stages", () => {
|
|
const output = RGBA.fromInts(0, 0, 0)
|
|
const background = RGBA.fromHex("#1a1b26")
|
|
const glowColor = RGBA.fromHex("#82aaff")
|
|
const runningColor = RGBA.fromHex("#c8d3f5")
|
|
const completionColor = RGBA.fromHex("#ff9e64")
|
|
|
|
for (const glow of [0, 0.08, 0.16]) {
|
|
for (const running of [0, 0.01, 0.07, 0.14]) {
|
|
for (const completion of [0, 0.03, 0.09, 0.18]) {
|
|
blendTabPulseColor(output, background, glowColor, runningColor, completionColor, glow, running, completion)
|
|
expect(output.buffer).toEqual(
|
|
tint(tint(tint(background, glowColor, glow), runningColor, running), completionColor, completion).buffer,
|
|
)
|
|
}
|
|
}
|
|
}
|
|
})
|