import { fromColourData, hexToRgb, hexToRgba, rgbaToHex, rgbToHex, toColourData, } from '@/functions/colours'; import { ColourData } from '@3cr/types-ts/types/ColourData'; describe('colour tests', () => { it('should convert RGB to hex', () => { const hex = rgbToHex(255, 0, 255); expect(hex).toBe('#ff00ff'); }); it('should convert RGBA to hex', () => { const hex = rgbaToHex(255, 0, 255, 16); expect(hex).toBe('#ff00ff10'); }); it('should convert hex to RGB', () => { const [r, g, b] = hexToRgb('#fa4b8c'); expect(r).toBe(250); expect(g).toBe(75); expect(b).toBe(140); }); it('should convert hex to RGBA', () => { const [r, g, b, a] = hexToRgba('#1c7a4ff9'); expect(r).toBe(28); expect(g).toBe(122); expect(b).toBe(79); expect(a).toBe(249); }); it('should convert from colour data', () => { const data: ColourData = { Version: '0.0.0', R: 0.1, G: 0.2, B: 0.3, A: 1 }; const hex = fromColourData(data); expect(hex).toBe('#19334c'); }); it('should convert to colour data', () => { const { R, G, B } = toColourData('#9f6a4d'); expect(R).toBeCloseTo(0.62); expect(G).toBeCloseTo(0.42); expect(B).toBeCloseTo(0.3); }); });