Nychthemeron/packages/library/tests/lib.spec.ts
Matthew L McPeak 4755f9ab6e feat: migrate Select to shadcn-vue compound API
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-11 14:50:36 -04:00

82 lines
2.6 KiB
TypeScript

import { describe, it, expect, vi } from 'vitest'
import type { App } from 'vue'
import {
createNychthemeron,
LoadingIcon,
Dialog,
} from '../src/index'
//eslint-disable-next-line
const callSetup = (component: any, props: Record<string, unknown>) => {
const mergedProps: Record<string, unknown> = {}
if (component.props) {
for (const [key, propDef] of Object.entries(component.props)) {
if (typeof propDef === 'object' && propDef !== null && 'default' in propDef) {
mergedProps[key] = (propDef as { default: unknown }).default
}
}
}
Object.assign(mergedProps, props)
if (component.setup) {
const result = component.setup(mergedProps, { slots: {}, attrs: {} })
if (typeof result === 'function') {
const vnode = result()
return (vnode?.props as Record<string, unknown>) || {}
}
return result
}
return mergedProps
}
describe('createNychthemeron', () => {
it('returns a Vue plugin with install method', () => {
const plugin = createNychthemeron()
expect(typeof plugin.install).toBe('function')
})
it('install registers NychButton and NychLoadingIcon globally', () => {
const plugin = createNychthemeron()
const mockApp = { component: vi.fn() } as unknown as App
plugin.install(mockApp)
expect(mockApp.component).toHaveBeenCalledWith('NychButton', expect.anything())
expect(mockApp.component).toHaveBeenCalledWith('NychLoadingIcon', expect.anything())
})
it('exposes Button and LoadingIcon components', () => {
const { Button: btn, LoadingIcon: icon } = createNychthemeron()
expect(btn).toBeDefined()
expect(icon).toBeDefined()
})
})
describe('LoadingIcon', () => {
it('is a valid Vue component', () => {
expect(LoadingIcon).toBeDefined()
})
})
describe('themed pt components', () => {
const cases = [
{ name: 'Dialog', component: Dialog, base: 'nych-dialog' },
]
it.each(cases)('$name is a valid Vue component', ({ component }) => {
expect(component).toBeDefined()
expect(typeof (component as Record<string, unknown>).setup).toBe('function')
})
it.each(cases)('$name injects its base class onto pt.root', ({ component, base }) => {
const result = callSetup(component, { pt: {} })
expect(result.pt?.root?.class).toContain(base)
})
it.each(cases)('$name does not leak engine internal props', ({ component }) => {
const result = callSetup(component, { pt: {} })
expect(result).not.toHaveProperty('injectedClasses')
expect(result).not.toHaveProperty('injectedStyles')
expect(result).not.toHaveProperty('stylePlug')
})
})