refactor(design): drop rounded classes, swap bg-white and gray borders for tokens
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { transformSource } from '../../scripts/modernist-codemod.mjs'
|
||||
|
||||
const t = (s: string): string => transformSource(s)
|
||||
|
||||
describe('modernist codemod', () => {
|
||||
it('removes rounded-* sizes but keeps rounded-full', () => {
|
||||
expect(t('<div className="rounded-xl p-4 rounded-full" />')).toBe('<div className="p-4 rounded-full" />')
|
||||
expect(t('<div className="p-4 rounded" />')).toBe('<div className="p-4" />')
|
||||
expect(t('<div className="rounded-t-lg border" />')).toBe('<div className="border" />')
|
||||
})
|
||||
|
||||
it('removes variant-prefixed rounded classes whole', () => {
|
||||
expect(t('<a className="hover:rounded-lg px-2" />')).toBe('<a className="px-2" />')
|
||||
})
|
||||
|
||||
it('swaps bg-white for bg-surface, keeping variants and opacity', () => {
|
||||
expect(t('<div className="bg-white p-2" />')).toBe('<div className="bg-surface p-2" />')
|
||||
expect(t('<div className="hover:bg-white/80" />')).toBe('<div className="hover:bg-surface/80" />')
|
||||
})
|
||||
|
||||
it('swaps light gray borders and dividers for the divider token', () => {
|
||||
expect(t('<div className="border border-gray-200" />')).toBe('<div className="border border-divider" />')
|
||||
expect(t('<ul className="divide-y divide-gray-100" />')).toBe('<ul className="divide-y divide-divider" />')
|
||||
})
|
||||
|
||||
it('leaves dark gray borders alone', () => {
|
||||
expect(t('<div className="border-gray-500" />')).toBe('<div className="border-gray-500" />')
|
||||
})
|
||||
|
||||
it('swaps heavy shadows for shadow-lg', () => {
|
||||
expect(t('<div className="shadow-2xl" />')).toBe('<div className="shadow-lg" />')
|
||||
expect(t('<div className="shadow-xl" />')).toBe('<div className="shadow-lg" />')
|
||||
expect(t('<div className="shadow-sm" />')).toBe('<div className="shadow-sm" />')
|
||||
})
|
||||
|
||||
it('handles template literals with conditionals', () => {
|
||||
const src = '<div className={`rounded-lg p-2 ${on ? \'bg-white rounded-md\' : \'bg-gray-50\'}`} />'
|
||||
expect(t(src)).toBe('<div className={`p-2 ${on ? \'bg-surface\' : \'bg-gray-50\'}`} />')
|
||||
})
|
||||
|
||||
it('drops a className that becomes empty', () => {
|
||||
expect(t('<div className="rounded-lg" />')).toBe('<div />')
|
||||
})
|
||||
|
||||
it('does not touch text outside className', () => {
|
||||
const src = '<p>The corners are rounded and bg-white is a word.</p>'
|
||||
expect(t(src)).toBe(src)
|
||||
})
|
||||
|
||||
it('is idempotent', () => {
|
||||
const once = t('<div className="rounded-xl bg-white border-gray-200 shadow-2xl" />')
|
||||
expect(t(once)).toBe(once)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user