import { describe, expect, it } from 'vitest' import { freeIllustrationSource, iconSvg, iconSourceComment, illustrationSvg } from './svg' describe('iconSvg', () => { it('returns the processed outline svg with a11y attributes and the given classes', () => { const svg = iconSvg('chevron-left', { classes: 'icon icon-sm' }) expect(svg).toContain(' { expect(iconSvg('chevron-left')).not.toContain('M0 0h24v24H0z') }) it('defaults to the "icon" class', () => { expect(iconSvg('chevron-left')).toContain('class="icon"') }) it('picks the filled variant when requested', () => { const outline = iconSvg('heart') const filled = iconSvg('heart', { filled: true }) expect(filled).toBeTruthy() expect(filled).not.toBe(outline) }) it('returns undefined for an unknown icon', () => { expect(iconSvg('definitely-not-an-icon')).toBeUndefined() }) }) describe('iconSourceComment', () => { it('links the tabler.io icon page', () => { expect(iconSourceComment('heart')).toBe('') }) }) describe('freeIllustrationSource', () => { it('returns the same svg with and without the ".svg" suffix', () => { expect(freeIllustrationSource('boy-girl.svg')).toBe(freeIllustrationSource('boy-girl')) }) it('returns the auto-dark source of a bundled illustration', () => { expect(freeIllustrationSource('not-found')).toContain(' { expect(() => freeIllustrationSource('no-such-illustration' as never)).toThrow(/Unknown illustration/) }) }) describe('illustrationSvg', () => { const source = '' it('injects classes into the svg tag', () => { expect(illustrationSvg(source, { classes: 'w-100 h-auto' })).toContain(' { const svg = illustrationSvg(source, { height: 128 }) expect(svg).toContain(' { expect(illustrationSvg(source)).toBe(source) }) })