import type { Config, PlatformConfig, TransformedToken, } from 'style-dictionary/types' import Color from 'colorjs.io' import { beforeEach, describe, expect, it, vi } from 'vitest' import { filter, transform } from './oklch.js' describe('oklch transform', () => { const createMockToken = (value: string, type = 'color'): TransformedToken => ({ name: 'test-token', value, $value: value, type, $type: type, path: [], original: {}, filePath: '', isSource: false, }) as TransformedToken const createMockConfig = (usesDtcg = false): Config => ({ usesDtcg, platforms: {}, source: [], include: [], }) const createMockPlatformConfig = (): PlatformConfig => ({ transforms: [], buildPath: '', files: [], }) describe('filter', () => { it('should return true for color tokens with usesDtcg false', () => { const token = createMockToken('#000000', 'color') const config = createMockConfig(false) const result = filter(token, config) expect(result).toBe(true) }) it('should return true for color tokens with usesDtcg true', () => { const token = createMockToken('#000000', 'color') const config = createMockConfig(true) const result = filter(token, config) expect(result).toBe(true) }) it('should return false for non-color tokens with usesDtcg false', () => { const token = createMockToken('1rem', 'spacing') const config = createMockConfig(false) const result = filter(token, config) expect(result).toBe(false) }) it('should return false for non-color tokens with usesDtcg true', () => { const token = createMockToken('1rem', 'spacing') const config = createMockConfig(true) const result = filter(token, config) expect(result).toBe(false) }) it('should handle different token types', () => { const testCases = [ { type: 'color', expected: true }, { type: 'spacing', expected: false }, { type: 'typography', expected: false }, { type: 'border', expected: false }, { type: 'shadow', expected: false }, ] testCases.forEach(({ type, expected }) => { const token = createMockToken('test-value', type) const config = createMockConfig(false) const result = filter(token, config) expect(result).toBe(expected) }) }) }) describe('transform', () => { beforeEach(() => { vi.clearAllMocks() }) it('should convert color to OKLCH format with usesDtcg false', () => { const token = createMockToken('#ff0000', 'color') const config = createMockPlatformConfig() const options = createMockConfig(false) const result = transform(token, config, options) expect(result).toBe('oklch(62.796% 0.25768 29.234)') }) it('should convert color to OKLCH format with usesDtcg true', () => { const token = createMockToken('#ff0000', 'color') const config = createMockPlatformConfig() const options = createMockConfig(true) const result = transform(token, config, options) expect(result).toBe('oklch(62.796% 0.25768 29.234)') }) it('should handle different color formats', () => { const testCases = [ { value: '#ff0000', expected: 'oklch(62.796% 0.25768 29.234)' }, { value: 'rgb(0, 255, 0)', expected: 'oklch(86.644% 0.29483 142.5)' }, { value: 'hsl(240, 100%, 50%)', expected: 'oklch(45.201% 0.31321 264.05)', }, { value: 'rgba(255, 0, 0, 0.5)', expected: 'oklch(62.796% 0.25768 29.234 / 0.5)', }, ] testCases.forEach(({ value, expected }) => { const token = createMockToken(value, 'color') const config = createMockPlatformConfig() const options = createMockConfig(false) const result = transform(token, config, options) expect(result).toBe(expected) }) }) it('should handle color with alpha channel', () => { const token = createMockToken('rgba(255, 0, 0, 0.8)', 'color') const config = createMockPlatformConfig() const options = createMockConfig(false) const result = transform(token, config, options) expect(result).toBe('oklch(62.796% 0.25768 29.234 / 0.8)') }) it('should handle named colors', () => { const token = createMockToken('red', 'color') const config = createMockPlatformConfig() const options = createMockConfig(false) const result = transform(token, config, options) expect(result).toBe('oklch(62.796% 0.25768 29.234)') }) }) })