import type { Token, TransformedToken } from 'style-dictionary' import { describe, expect, it } from 'vitest' import { filter, transform } from './tailwind-grid-token.js' describe('tailwind-grid-token', () => { describe('filter', () => { it('should return true for tokens with grid category', () => { const token: Token = { name: 'grid-layout-default-columns', path: ['grid', 'layout', 'default', 'columns'], original: { $value: 6 }, attributes: { category: 'grid', type: 'layout', item: 'default', subitem: 'columns', }, $value: 6, $type: 'number', } expect(filter(token)).toBe(true) }) it('should return false for tokens without grid category', () => { const token: Token = { name: 'color-primary', path: ['color', 'primary'], original: { $value: '#ff0000' }, attributes: { category: 'color', type: 'primary' }, $value: '#ff0000', $type: 'color', } expect(filter(token)).toBe(false) }) it('should return false for tokens without attributes', () => { const token: Token = { name: 'some-token', path: ['some', 'token'], original: { $value: 'value' }, $value: 'value', } expect(filter(token)).toBe(false) }) it('should return false for tokens with undefined category', () => { const token: Token = { name: 'some-token', path: ['some', 'token'], original: { $value: 'value' }, attributes: { category: undefined, type: undefined, item: undefined, subitem: undefined, }, $value: 'value', } expect(filter(token)).toBe(false) }) }) describe('transform', () => { it('should transform grid token path to expected format', () => { const token: TransformedToken = { name: 'grid-layout-default-columns', path: ['grid', 'layout', 'default', 'columns'], original: { $value: 6 }, attributes: { category: 'grid', type: 'layout', item: 'default', subitem: 'columns', }, $value: 6, $type: 'number', filePath: 'test.json', isSource: true, } const result = transform(token, {}, {}) expect(result).toBe('grid-layout-columns--default') }) it('should prepend prefix when config.prefix is set', () => { const token: TransformedToken = { name: 'grid-layout-default-columns', path: ['grid', 'layout', 'default', 'columns'], original: { $value: 6 }, attributes: { category: 'grid', type: 'layout', item: 'default', subitem: 'columns', }, $value: 6, $type: 'number', filePath: 'test.json', isSource: true, } const result = transform(token, { prefix: 'uy' }, {}) expect(result).toBe('uy-grid-layout-columns--default') }) }) })