Files
summercms/admin/tests/app/icons.test.ts
Jakub Zych a00dafaf65 fix(admin): map Winter icon-* names onto lucide for plugin navigation
Ported plugins send Winter icon-* class names on nav and settings; the SPA
never loads Font Awesome, so unknown names rendered as empty squares. Map
BM Studies, Quizzes, icon-pencil, and a closed Winter backend alias table
onto named @lucide/vue 1.17.0 exports, keep Square for unknown names, and
rebuild the embedded boardwalk dist.
2026-10-05 19:28:35 +02:00

80 lines
2.5 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import {
Archive,
Book,
Bookmark,
Calendar,
CircleQuestionMark,
Clock,
Copy,
Disc3,
FileText,
Flag,
GraduationCap,
House,
Leaf,
LifeBuoy,
List,
Mail,
Network,
Pencil,
Settings,
Square,
Tags,
WandSparkles,
} from '@lucide/vue'
import { fallbackIcon, iconFor, icons, winterIcons } from '../../src/app/icons'
describe('iconFor', () => {
it('resolves lucide names', () => {
expect(iconFor('disc-3')).toBe(Disc3)
expect(iconFor('tags')).toBe(Tags)
expect(iconFor(' tags ')).toBe(Tags)
expect(iconFor('book')).toBe(Book)
expect(iconFor(' graduation-cap ')).toBe(GraduationCap)
})
it('resolves Winter icon aliases', () => {
expect(iconFor('icon-archive')).toBe(Archive)
expect(iconFor('icon-cog')).toBe(Settings)
expect(iconFor('icon-graduation-cap')).toBe(GraduationCap)
expect(iconFor('icon-book')).toBe(Book)
expect(iconFor('icon-bookmark')).toBe(Bookmark)
expect(iconFor('icon-calendar')).toBe(Calendar)
expect(iconFor('icon-clock-o')).toBe(Clock)
expect(iconFor('icon-flag')).toBe(Flag)
expect(iconFor('icon-file-text-o')).toBe(FileText)
expect(iconFor('icon-tags')).toBe(Tags)
expect(iconFor('icon-pencil')).toBe(Pencil)
expect(iconFor('icon-question-circle')).toBe(CircleQuestionMark)
expect(iconFor('icon-list')).toBe(List)
expect(iconFor('icon-home')).toBe(House)
expect(iconFor('icon-magic')).toBe(WandSparkles)
expect(iconFor('icon-life-ring')).toBe(LifeBuoy)
expect(iconFor('icon-sitemap')).toBe(Network)
expect(iconFor('icon-envelope-o')).toBe(Mail)
expect(iconFor('icon-copy')).toBe(Copy)
expect(iconFor('icon-leaf')).toBe(Leaf)
expect(iconFor('icon-cogs')).toBe(Settings)
expect(iconFor('icon-edit')).toBe(Pencil)
})
it('falls back to the neutral square for unknown, empty or missing names', () => {
expect(fallbackIcon).toBe(Square)
expect(iconFor('unknown-icon-name')).toBe(Square)
expect(iconFor('icon-unknown')).toBe(Square)
expect(iconFor('')).toBe(Square)
expect(iconFor(null)).toBe(Square)
expect(iconFor(undefined)).toBe(Square)
expect(iconFor('constructor')).toBe(Square)
expect(iconFor('toString')).toBe(Square)
expect(iconFor('__proto__')).toBe(Square)
})
it('maps every Winter alias onto a registered lucide icon', () => {
for (const [alias, name] of Object.entries(winterIcons)) {
expect(icons[name], alias).toBeDefined()
}
})
})