mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-26 18:00:43 +01:00
remove old files
This commit is contained in:
@@ -1,131 +0,0 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { defu } from 'defu'
|
||||
import { join } from 'pathe'
|
||||
import { loadNuxt } from '@nuxt/kit'
|
||||
import type { NuxtConfig } from '@nuxt/schema'
|
||||
import type * as tailwindcss from 'tailwindcss'
|
||||
type TWConfig = tailwindcss.Config;
|
||||
import type resolveConfig from 'tailwindcss/resolveConfig'
|
||||
|
||||
async function getTailwindCSSConfig (overrides: Partial<NuxtConfig> = {}) {
|
||||
let tailwindConfig: ReturnType<typeof resolveConfig<TWConfig>>
|
||||
const nuxt = await loadNuxt({
|
||||
ready: true,
|
||||
cwd: join(process.cwd(), 'fixtures', 'empty'),
|
||||
dev: false,
|
||||
overrides: defu(overrides, {
|
||||
ssr: false,
|
||||
modules: ['../../src/module'],
|
||||
hooks: {
|
||||
'tailwindcss:resolvedConfig' (config) {
|
||||
tailwindConfig = config
|
||||
}
|
||||
}
|
||||
} satisfies NuxtConfig) as NuxtConfig
|
||||
})
|
||||
const nuxtOptions = structuredClone({
|
||||
plugins: nuxt.options.plugins.map(p => typeof p !== 'string' && ({ src: p.src, mode: p.mode })),
|
||||
_requiredModules: nuxt.options._requiredModules,
|
||||
appConfig: nuxt.options.appConfig
|
||||
})
|
||||
await nuxt.close()
|
||||
|
||||
return {
|
||||
nuxtOptions,
|
||||
tailwindConfig
|
||||
}
|
||||
}
|
||||
|
||||
describe('nuxt', () => {
|
||||
it('should add plugins and modules to nuxt', async () => {
|
||||
const { nuxtOptions } = await getTailwindCSSConfig()
|
||||
expect(nuxtOptions.plugins).toContainEqual(
|
||||
expect.objectContaining({
|
||||
src: expect.stringContaining('plugins/colors'),
|
||||
mode: 'all'
|
||||
})
|
||||
)
|
||||
expect(nuxtOptions._requiredModules).toMatchObject({
|
||||
'@nuxtjs/color-mode': true,
|
||||
'@nuxtjs/tailwindcss': true
|
||||
})
|
||||
// default values in appConfig
|
||||
expect(nuxtOptions.appConfig.ui).toMatchObject({
|
||||
primary: 'green',
|
||||
gray: 'cool'
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('tailwindcss config', () => {
|
||||
it.each([
|
||||
/* format:
|
||||
name,
|
||||
tailwindcss config, safelistColors,
|
||||
expected safelistPatterns (add "!" before a pattern to negate it)
|
||||
*/
|
||||
[
|
||||
'default safelist',
|
||||
{}, [],
|
||||
['bg-(primary)-50', 'bg-(red)-500'] // these both should be in the safelist
|
||||
],
|
||||
[
|
||||
'safelisting single new color',
|
||||
{}, ['myColor'],
|
||||
'bg-(myColor|primary)-50'
|
||||
],
|
||||
[
|
||||
'reducing amount of theme colors',
|
||||
{ theme: { colors: { plainBlue: '#00F' } } }, ['plainBlue'],
|
||||
['bg-(plainBlue|primary)-50', '!', /orange/] // the word "orange" should _not_ be found in any safelist pattern
|
||||
]
|
||||
])('%s', async (_description, tailwindcss, safelistColors, safelistPatterns) => {
|
||||
const { tailwindConfig } = await getTailwindCSSConfig({
|
||||
ui: {
|
||||
safelistColors
|
||||
},
|
||||
tailwindcss: {
|
||||
config: tailwindcss
|
||||
}
|
||||
})
|
||||
expect.extend({
|
||||
toBeRegExp: (received, expected) => {
|
||||
if (typeof expected === 'string' || expected instanceof String) {
|
||||
return {
|
||||
message: () => `expected ${received} to be exact regex ${expected}`,
|
||||
pass: received.toString() === RegExp(expected as string).toString()
|
||||
}
|
||||
} else if (expected instanceof RegExp) {
|
||||
return {
|
||||
message: () => `expected ${received} to be a regex like ${expected.toString()}`,
|
||||
pass: received.toString().match(expected)
|
||||
}
|
||||
}
|
||||
return {
|
||||
message: () => `expected ${received} to be a regex`,
|
||||
pass: false
|
||||
}
|
||||
}
|
||||
})
|
||||
safelistPatterns = safelistPatterns instanceof Array ? safelistPatterns : [safelistPatterns]
|
||||
|
||||
let negate = false
|
||||
for (const safelistPattern of safelistPatterns) {
|
||||
if (safelistPattern === '!') {
|
||||
// negate next!
|
||||
negate = true
|
||||
continue
|
||||
}
|
||||
if (negate) {
|
||||
expect(tailwindConfig.safelist).not.toContainEqual({
|
||||
pattern: expect.toBeRegExp(safelistPattern)
|
||||
})
|
||||
} else {
|
||||
expect(tailwindConfig.safelist).toContainEqual({
|
||||
pattern: expect.toBeRegExp(safelistPattern)
|
||||
})
|
||||
}
|
||||
negate = false
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -1,19 +0,0 @@
|
||||
import { mountSuspended } from '@nuxt/test-utils/runtime'
|
||||
import path from 'path'
|
||||
|
||||
export default async function (nameOrHtml: string, options: any, component: any) {
|
||||
let html: string
|
||||
const name = path.parse(component.__file).name
|
||||
if (options === undefined) {
|
||||
const app = {
|
||||
template: nameOrHtml,
|
||||
components: { [`U${name}`]: component }
|
||||
}
|
||||
const result = await mountSuspended(app)
|
||||
html = result.html()
|
||||
} else {
|
||||
const cResult = await mountSuspended(component, options)
|
||||
html = cResult.html()
|
||||
}
|
||||
return html
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { UButton } from '#components'
|
||||
import type { TypeOf } from 'zod'
|
||||
import ComponentRender from '../component-render'
|
||||
|
||||
describe('Button', () => {
|
||||
it.each([
|
||||
[ 'basic case', { } ],
|
||||
[ 'leading icon', { props: { leading: true, icon: 'heroicons-check' } } ],
|
||||
[ 'black solid', { props: { color: 'black', variant: 'solid' } } ],
|
||||
[ 'rounded full', { props: { ui: { rounded: 'rounded-full' } } } ],
|
||||
[ '<UButton icon="i-heroicons-pencil-square" size="sm" color="primary" square variant="solid" />' ]
|
||||
// @ts-ignore
|
||||
])('renders %s correctly', async (nameOrHtml: string, options: TypeOf<typeof Button.props>) => {
|
||||
if (options !== undefined) {
|
||||
options.slots = options.slots || { default: () => 'label' }
|
||||
options.slots.default = options.slots.default || (() => 'label')
|
||||
}
|
||||
const html = await ComponentRender(nameOrHtml, options, UButton)
|
||||
expect(html).toMatchSnapshot()
|
||||
})
|
||||
})
|
||||
@@ -1,35 +0,0 @@
|
||||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
||||
|
||||
exports[`Button > renders <UButton icon="i-heroicons-pencil-square" size="sm" color="primary" square variant="solid" /> correctly 1`] = `
|
||||
"<button type="button" class="focus:outline-none disabled:cursor-not-allowed disabled:opacity-75 flex-shrink-0 font-medium rounded-md text-sm gap-x-1.5 p-1.5 shadow-sm text-white dark:text-gray-900 bg-primary-500 hover:bg-primary-600 disabled:bg-primary-500 dark:bg-primary-400 dark:hover:bg-primary-500 dark:disabled:bg-primary-400 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-500 dark:focus-visible:outline-primary-400 inline-flex items-center"><span class="i-heroicons-pencil-square flex-shrink-0 h-5 w-5" aria-hidden="true"></span>
|
||||
<!--v-if-->
|
||||
<!--v-if-->
|
||||
</button>"
|
||||
`;
|
||||
|
||||
exports[`Button > renders basic case correctly 1`] = `
|
||||
"<button type="button" class="focus:outline-none disabled:cursor-not-allowed disabled:opacity-75 flex-shrink-0 font-medium rounded-md text-sm gap-x-1.5 px-2.5 py-1.5 shadow-sm text-white dark:text-gray-900 bg-primary-500 hover:bg-primary-600 disabled:bg-primary-500 dark:bg-primary-400 dark:hover:bg-primary-500 dark:disabled:bg-primary-400 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-500 dark:focus-visible:outline-primary-400 inline-flex items-center">
|
||||
<!--v-if-->label
|
||||
<!--v-if-->
|
||||
</button>"
|
||||
`;
|
||||
|
||||
exports[`Button > renders black solid correctly 1`] = `
|
||||
"<button type="button" class="focus:outline-none focus-visible:outline-0 disabled:cursor-not-allowed disabled:opacity-75 flex-shrink-0 font-medium rounded-md text-sm gap-x-1.5 px-2.5 py-1.5 shadow-sm text-white dark:text-gray-900 bg-gray-900 hover:bg-gray-800 disabled:bg-gray-900 dark:bg-white dark:hover:bg-gray-100 dark:disabled:bg-white focus-visible:ring-inset focus-visible:ring-2 focus-visible:ring-primary-500 dark:focus-visible:ring-primary-400 inline-flex items-center">
|
||||
<!--v-if-->label
|
||||
<!--v-if-->
|
||||
</button>"
|
||||
`;
|
||||
|
||||
exports[`Button > renders leading icon correctly 1`] = `
|
||||
"<button type="button" class="focus:outline-none disabled:cursor-not-allowed disabled:opacity-75 flex-shrink-0 font-medium rounded-md text-sm gap-x-1.5 px-2.5 py-1.5 shadow-sm text-white dark:text-gray-900 bg-primary-500 hover:bg-primary-600 disabled:bg-primary-500 dark:bg-primary-400 dark:hover:bg-primary-500 dark:disabled:bg-primary-400 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-500 dark:focus-visible:outline-primary-400 inline-flex items-center"><span class="heroicons-check flex-shrink-0 h-5 w-5" aria-hidden="true"></span>label
|
||||
<!--v-if-->
|
||||
</button>"
|
||||
`;
|
||||
|
||||
exports[`Button > renders rounded full correctly 1`] = `
|
||||
"<button type="button" class="focus:outline-none disabled:cursor-not-allowed disabled:opacity-75 flex-shrink-0 font-medium rounded-full text-sm gap-x-1.5 px-2.5 py-1.5 shadow-sm text-white dark:text-gray-900 bg-primary-500 hover:bg-primary-600 disabled:bg-primary-500 dark:bg-primary-400 dark:hover:bg-primary-500 dark:disabled:bg-primary-400 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-500 dark:focus-visible:outline-primary-400 inline-flex items-center">
|
||||
<!--v-if-->label
|
||||
<!--v-if-->
|
||||
</button>"
|
||||
`;
|
||||
@@ -1,14 +0,0 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { USkeleton } from '#components'
|
||||
import type { TypeOf } from 'zod'
|
||||
import ComponentRender from '../component-render'
|
||||
|
||||
describe('Skeleton', () => {
|
||||
it.each([
|
||||
[ 'basic case', { } ],
|
||||
[ '<USkeleton class="h-12 w-12" :ui="{ rounded: \'rounded-full\' }" />' ]
|
||||
])('renders %s correctly', async (nameOrHtml: string, options?: TypeOf<typeof USkeleton.props>) => {
|
||||
const html = await ComponentRender(nameOrHtml, options, USkeleton)
|
||||
expect(html).toMatchSnapshot()
|
||||
})
|
||||
})
|
||||
@@ -1,5 +0,0 @@
|
||||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
||||
|
||||
exports[`Skeleton > renders <USkeleton class="h-12 w-12" :ui="{ rounded: 'rounded-full' }" /> correctly 1`] = `"<div class="animate-pulse bg-gray-100 dark:bg-gray-800 rounded-full h-12 w-12"></div>"`;
|
||||
|
||||
exports[`Skeleton > renders basic case correctly 1`] = `"<div class="animate-pulse bg-gray-100 dark:bg-gray-800 rounded-md"></div>"`;
|
||||
11
test/vitest.d.ts
vendored
11
test/vitest.d.ts
vendored
@@ -1,11 +0,0 @@
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
import type { Assertion, AsymmetricMatchersContaining } from 'vitest'
|
||||
|
||||
interface CustomMatchers<R = unknown> {
|
||||
toBeRegExp(expected: string | RegExp): R
|
||||
}
|
||||
|
||||
declare module 'vitest' {
|
||||
interface Assertion<T = any> extends CustomMatchers<T> {}
|
||||
interface AsymmetricMatchersContaining extends CustomMatchers {}
|
||||
}
|
||||
Reference in New Issue
Block a user