import type { Config, TransformedToken } from 'style-dictionary/types' import { describe, expect, it } from 'vitest' import { filter, transform } from './tailwind-color-token.js' describe('tailwind color token transform', () => { const createMockToken = (path: string[]): TransformedToken => ({ name: 'test-token', value: '#000000', type: 'color', path, original: {}, filePath: '', isSource: false, }) as TransformedToken const createMockConfig = (): Config => ({ platforms: {}, source: [], include: [], }) describe('filter', () => { it('should return true for tokens with color as first path element', () => { const token = createMockToken(['color', 'primary', 'default']) const config = createMockConfig() const result = filter(token, config) expect(result).toBe(true) }) it('should return false for tokens without color as first path element', () => { const testCases = [ ['spacing', '1'], ['typography', 'heading', 'h1'], ['border', 'width', 'thin'], ['shadow', 'small'], ['breakpoint', 'mobile'], ] testCases.forEach(path => { const token = createMockToken(path) const config = createMockConfig() const result = filter(token, config) expect(result).toBe(false) }) }) it('should return false for empty path', () => { const token = createMockToken([]) const config = createMockConfig() const result = filter(token, config) expect(result).toBe(false) }) it('should return false for single element path that is not color', () => { const token = createMockToken(['spacing']) const config = createMockConfig() const result = filter(token, config) expect(result).toBe(false) }) it('should handle case sensitivity', () => { const testCases = [ { path: ['Color', 'primary'], expected: false }, { path: ['COLOR', 'primary'], expected: false }, { path: ['color', 'primary'], expected: true }, ] testCases.forEach(({ path, expected }) => { const token = createMockToken(path) const config = createMockConfig() const result = filter(token, config) expect(result).toBe(expected) }) }) }) describe('transform', () => { it('should join path elements with hyphens, excluding default', () => { const token = createMockToken(['color', 'primary', 'default']) const config = createMockConfig() const result = transform(token, config, {}) expect(result).toBe('color-primary') }) it('should handle path without default', () => { const token = createMockToken(['color', 'primary', 'hover']) const config = createMockConfig() const result = transform(token, config, {}) expect(result).toBe('color-primary-hover') }) it('should handle path with multiple default occurrences', () => { const token = createMockToken(['color', 'default', 'primary', 'default']) const config = createMockConfig() const result = transform(token, config, {}) expect(result).toBe('color-primary') }) it('should handle path with only color and default', () => { const token = createMockToken(['color', 'default']) const config = createMockConfig() const result = transform(token, config, {}) expect(result).toBe('color') }) it('should handle path with only color', () => { const token = createMockToken(['color']) const config = createMockConfig() const result = transform(token, config, {}) expect(result).toBe('color') }) it('should handle complex color paths', () => { const testCases = [ { path: ['color', 'gray', '100'], expected: 'color-gray-100' }, { path: ['color', 'blue', '500', 'hover'], expected: 'color-blue-500-hover', }, { path: ['color', 'red', 'default', 'active'], expected: 'color-red-active', }, { path: ['color', 'green', 'default', 'default', 'focus'], expected: 'color-green-focus', }, ] testCases.forEach(({ path, expected }) => { const token = createMockToken(path) const config = createMockConfig() const result = transform(token, config, {}) expect(result).toBe(expected) }) }) it('should handle path with special characters', () => { const testCases = [ { path: ['color', 'primary', 'with-dash'], expected: 'color-primary-with-dash', }, { path: ['color', 'primary', 'with_underscore'], expected: 'color-primary-with_underscore', }, { path: ['color', 'primary', 'with.dot'], expected: 'color-primary-with.dot', }, ] testCases.forEach(({ path, expected }) => { const token = createMockToken(path) const config = createMockConfig() const result = transform(token, config, {}) expect(result).toBe(expected) }) }) it('should handle path with numbers', () => { const testCases = [ { path: ['color', 'gray', '100'], expected: 'color-gray-100' }, { path: ['color', 'blue', '500'], expected: 'color-blue-500' }, { path: ['color', 'red', '1000'], expected: 'color-red-1000' }, ] testCases.forEach(({ path, expected }) => { const token = createMockToken(path) const config = createMockConfig() const result = transform(token, config, {}) expect(result).toBe(expected) }) }) it('should handle path with mixed content', () => { const testCases = [ { path: ['color', 'primary', 'default', 'hover', 'active'], expected: 'color-primary-hover-active', }, { path: ['color', 'secondary', 'default', 'focus', 'default'], expected: 'color-secondary-focus', }, { path: ['color', 'tertiary', 'default', 'default', 'default'], expected: 'color-tertiary', }, ] testCases.forEach(({ path, expected }) => { const token = createMockToken(path) const config = createMockConfig() const result = transform(token, config, {}) expect(result).toBe(expected) }) }) it('should handle edge cases', () => { const testCases = [ { path: ['color', 'default', 'default', 'default'], expected: 'color' }, { path: ['color', 'primary', 'default', 'default'], expected: 'color-primary', }, { path: ['color', 'default', 'primary', 'default'], expected: 'color-primary', }, { path: ['color', 'default', 'default', 'primary'], expected: 'color-primary', }, ] testCases.forEach(({ path, expected }) => { const token = createMockToken(path) const config = createMockConfig() const result = transform(token, config, {}) expect(result).toBe(expected) }) }) it('should handle empty path elements', () => { const token = createMockToken(['color', '', 'primary', 'default']) const config = createMockConfig() const result = transform(token, config, {}) expect(result).toBe('color--primary') }) it('should handle path with whitespace', () => { const token = createMockToken(['color', 'primary', ' ', 'default']) const config = createMockConfig() const result = transform(token, config, {}) expect(result).toBe('color-primary- ') }) it('should handle path with uppercase', () => { const token = createMockToken(['color', 'PRIMARY', 'default']) const config = createMockConfig() const result = transform(token, config, {}) expect(result).toBe('color-primary') }) it('should prepend prefix when config.prefix is set', () => { const token = createMockToken(['color', 'primary', 'default']) const config = { ...createMockConfig(), prefix: 'uy' } const result = transform(token, config, {}) expect(result).toBe('uy-color-primary') }) it('should not prepend prefix when config.prefix is undefined', () => { const token = createMockToken(['color', 'blue', '500']) const config = createMockConfig() const result = transform(token, config, {}) expect(result).toBe('color-blue-500') }) }) })