model-visuals.test.ts
1,190 bytes
| 1 | import { describe, expect, it } from 'vitest'; |
|---|---|
| 2 | import { participantColor, participantTag, scoreColor, stageColorVar } from './model-visuals'; |
| 3 | |
| 4 | describe('participantTag', () => { |
| 5 | it('maps index to letters', () => { |
| 6 | expect(participantTag(0)).toBe('A'); |
| 7 | expect(participantTag(2)).toBe('C'); |
| 8 | }); |
| 9 | }); |
| 10 | |
| 11 | describe('participantColor', () => { |
| 12 | it('is a stable hsl string and cycles the palette', () => { |
| 13 | expect(participantColor(0)).toMatch(/^hsl\(/); |
| 14 | expect(participantColor(0)).toBe(participantColor(6)); // 6-colour palette wraps |
| 15 | expect(participantColor(0)).not.toBe(participantColor(1)); |
| 16 | }); |
| 17 | }); |
| 18 | |
| 19 | describe('scoreColor', () => { |
| 20 | it('shifts hue upward with the score', () => { |
| 21 | const low = scoreColor(1); |
| 22 | const high = scoreColor(10); |
| 23 | const hueOf = (s: string) => Number(s.match(/hsl\(([\d.]+)/)![1]); |
| 24 | expect(hueOf(high)).toBeGreaterThan(hueOf(low)); |
| 25 | }); |
| 26 | }); |
| 27 | |
| 28 | describe('stageColorVar', () => { |
| 29 | it('maps each stage to its css variable', () => { |
| 30 | expect(stageColorVar('answer')).toBe('var(--stage-answer)'); |
| 31 | expect(stageColorVar('synthesis')).toBe('var(--stage-synthesis)'); |
| 32 | expect(stageColorVar('unknown')).toBe('var(--primary)'); |
| 33 | }); |
| 34 | }); |
| 35 | |