mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-14 20:19:34 +01:00
test: update
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { UButton } from '#components'
|
||||
import ComponentRender from './component-render'
|
||||
import Button, { type ButtonProps } from '../../src/runtime/components/Button.vue'
|
||||
import ComponentRender from '../component-render'
|
||||
|
||||
describe('Button', () => {
|
||||
it.each([
|
||||
['with label', { props: { label: 'Button' } }],
|
||||
['with size', { props: { label: 'Button', size: 'lg' } }],
|
||||
['with color', { props: { label: 'Button', color: 'red' } }],
|
||||
['with variant', { props: { label: 'Button', variant: 'outline' } }],
|
||||
['with size', { props: { label: 'Button', size: 'lg' as const } }],
|
||||
['with color', { props: { label: 'Button', color: 'red' as const } }],
|
||||
// ['with variant', { props: { label: 'Button', variant: 'outline' } }],
|
||||
['with icon', { props: { icon: 'i-heroicons-academic-cap' } }],
|
||||
['with trailingIcon', { props: { trailing: true, trailingIcon: 'i-heroicons-arrow-right' } }],
|
||||
['with leadingIcon', { props: { leading: true, leadingIcon: 'i-heroicons-arrow-left' } }],
|
||||
@@ -21,8 +21,8 @@ describe('Button', () => {
|
||||
['with default slot', { slots: { default: () => 'Default slot' } }],
|
||||
['with leading slot', { slots: { leading: () => 'Leading slot' } }],
|
||||
['with trailing slot', { slots: { trailing: () => 'Trailing slot' } }]
|
||||
])('renders %s correctly', async (nameOrHtml: string, options: typeof UButton.props) => {
|
||||
const html = await ComponentRender(nameOrHtml, options, UButton)
|
||||
])('renders %s correctly', async (nameOrHtml: string, options: { props?: ButtonProps, slots?: any }) => {
|
||||
const html = await ComponentRender(nameOrHtml, options, Button)
|
||||
expect(html).toMatchSnapshot()
|
||||
})
|
||||
})
|
||||
|
||||
17
test/components/Link.spec.ts
Normal file
17
test/components/Link.spec.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import Link, { type LinkProps } from '../../src/runtime/components/Link.vue'
|
||||
import ComponentRender from '../component-render'
|
||||
|
||||
describe('Link', () => {
|
||||
it.each([
|
||||
['with as', { props: { as: 'div' } }],
|
||||
['with to', { props: { to: '/' } }],
|
||||
['with type', { props: { type: 'submit' } }],
|
||||
['with disabled', { props: { disabled: true } }],
|
||||
['with activeClass', { props: { active: true, to: '/', activeClass: 'text-sm' } }],
|
||||
['with inactiveClass', { props: { active: false, to: '/', inactiveClass: 'text-gray-300' } }]
|
||||
])('renders %s correctly', async (nameOrHtml: string, options: { props: LinkProps }) => {
|
||||
const html = await ComponentRender(nameOrHtml, options, Link)
|
||||
expect(html).toMatchSnapshot()
|
||||
})
|
||||
})
|
||||
@@ -1,35 +1,35 @@
|
||||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
||||
|
||||
exports[`Button > renders with block correctly 1`] = `
|
||||
"<button type="button" class="rounded-md font-medium inline-flex items-center focus:outline-none focus-visible:outline-0 disabled:cursor-not-allowed disabled:opacity-75 flex-shrink-0 bg-blue-500 hover:bg-blue-700 px-3 py-2 text-sm gap-x-2 w-full justify-center">
|
||||
"<button type="button" class="rounded-md font-medium inline-flex items-center focus:outline-none focus-visible:outline-0 disabled:cursor-not-allowed disabled:opacity-75 flex-shrink-0 bg-blue-500 hover:bg-blue-700 px-2.5 py-1.5 text-sm gap-x-1.5 w-full justify-center">
|
||||
<!--v-if--><span class="">Button</span>
|
||||
<!--v-if-->
|
||||
</button>"
|
||||
`;
|
||||
|
||||
exports[`Button > renders with color correctly 1`] = `
|
||||
"<button type="button" class="rounded-md font-medium inline-flex items-center focus:outline-none focus-visible:outline-0 disabled:cursor-not-allowed disabled:opacity-75 flex-shrink-0 bg-red-500 hover:bg-red-700 px-3 py-2 text-sm gap-x-2">
|
||||
"<button type="button" class="rounded-md font-medium inline-flex items-center focus:outline-none focus-visible:outline-0 disabled:cursor-not-allowed disabled:opacity-75 flex-shrink-0 bg-red-500 hover:bg-red-700 px-2.5 py-1.5 text-sm gap-x-1.5">
|
||||
<!--v-if--><span class="">Button</span>
|
||||
<!--v-if-->
|
||||
</button>"
|
||||
`;
|
||||
|
||||
exports[`Button > renders with default slot correctly 1`] = `
|
||||
"<button type="button" class="rounded-md font-medium inline-flex items-center focus:outline-none focus-visible:outline-0 disabled:cursor-not-allowed disabled:opacity-75 flex-shrink-0 bg-blue-500 hover:bg-blue-700 px-3 py-2 text-sm gap-x-2">
|
||||
"<button type="button" class="rounded-md font-medium inline-flex items-center focus:outline-none focus-visible:outline-0 disabled:cursor-not-allowed disabled:opacity-75 flex-shrink-0 bg-blue-500 hover:bg-blue-700 px-2.5 py-1.5 text-sm gap-x-1.5">
|
||||
<!--v-if--><span class="">Default slot</span>
|
||||
<!--v-if-->
|
||||
</button>"
|
||||
`;
|
||||
|
||||
exports[`Button > renders with disabled correctly 1`] = `
|
||||
"<button type="button" disabled="" class="rounded-md font-medium inline-flex items-center focus:outline-none focus-visible:outline-0 disabled:cursor-not-allowed disabled:opacity-75 flex-shrink-0 bg-blue-500 hover:bg-blue-700 px-3 py-2 text-sm gap-x-2">
|
||||
"<button type="button" disabled="" class="rounded-md font-medium inline-flex items-center focus:outline-none focus-visible:outline-0 disabled:cursor-not-allowed disabled:opacity-75 flex-shrink-0 bg-blue-500 hover:bg-blue-700 px-2.5 py-1.5 text-sm gap-x-1.5">
|
||||
<!--v-if--><span class="">Button</span>
|
||||
<!--v-if-->
|
||||
</button>"
|
||||
`;
|
||||
|
||||
exports[`Button > renders with icon correctly 1`] = `
|
||||
"<button type="button" class="rounded-md font-medium inline-flex items-center focus:outline-none focus-visible:outline-0 disabled:cursor-not-allowed disabled:opacity-75 flex-shrink-0 bg-blue-500 hover:bg-blue-700 text-sm gap-x-2 p-2"><svg data-v-66d85e84="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="icon flex-shrink-0 h-5 w-5" width="1em" height="1em" viewBox="0 0 24 24">
|
||||
"<button type="button" class="rounded-md font-medium inline-flex items-center focus:outline-none focus-visible:outline-0 disabled:cursor-not-allowed disabled:opacity-75 flex-shrink-0 bg-blue-500 hover:bg-blue-700 text-sm gap-x-1.5 p-1"><svg data-v-2f2f464d="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="icon flex-shrink-0 h-5 w-5" width="1em" height="1em" viewBox="0 0 24 24">
|
||||
<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M4.26 10.147a60.438 60.438 0 0 0-.491 6.347A48.62 48.62 0 0 1 12 20.904a48.62 48.62 0 0 1 8.232-4.41a60.46 60.46 0 0 0-.491-6.347m-15.482 0a50.636 50.636 0 0 0-2.658-.813A59.906 59.906 0 0 1 12 3.493a59.903 59.903 0 0 1 10.399 5.84a51.39 51.39 0 0 0-2.658.814m-15.482 0A50.717 50.717 0 0 1 12 13.489a50.702 50.702 0 0 1 7.74-3.342M6.75 15a.75.75 0 1 0 0-1.5a.75.75 0 0 0 0 1.5m0 0v-3.675A55.378 55.378 0 0 1 12 8.443m-7.007 11.55A5.981 5.981 0 0 0 6.75 15.75v-1.5"></path>
|
||||
</svg>
|
||||
<!--v-if-->
|
||||
@@ -38,21 +38,21 @@ exports[`Button > renders with icon correctly 1`] = `
|
||||
`;
|
||||
|
||||
exports[`Button > renders with label correctly 1`] = `
|
||||
"<button type="button" class="rounded-md font-medium inline-flex items-center focus:outline-none focus-visible:outline-0 disabled:cursor-not-allowed disabled:opacity-75 flex-shrink-0 bg-blue-500 hover:bg-blue-700 px-3 py-2 text-sm gap-x-2">
|
||||
"<button type="button" class="rounded-md font-medium inline-flex items-center focus:outline-none focus-visible:outline-0 disabled:cursor-not-allowed disabled:opacity-75 flex-shrink-0 bg-blue-500 hover:bg-blue-700 px-2.5 py-1.5 text-sm gap-x-1.5">
|
||||
<!--v-if--><span class="">Button</span>
|
||||
<!--v-if-->
|
||||
</button>"
|
||||
`;
|
||||
|
||||
exports[`Button > renders with leading slot correctly 1`] = `
|
||||
"<button type="button" class="rounded-md font-medium inline-flex items-center focus:outline-none focus-visible:outline-0 disabled:cursor-not-allowed disabled:opacity-75 flex-shrink-0 bg-blue-500 hover:bg-blue-700 text-sm gap-x-2 p-2">Leading slot
|
||||
"<button type="button" class="rounded-md font-medium inline-flex items-center focus:outline-none focus-visible:outline-0 disabled:cursor-not-allowed disabled:opacity-75 flex-shrink-0 bg-blue-500 hover:bg-blue-700 text-sm gap-x-1.5 p-1">Leading slot
|
||||
<!--v-if-->
|
||||
<!--v-if-->
|
||||
</button>"
|
||||
`;
|
||||
|
||||
exports[`Button > renders with leadingIcon correctly 1`] = `
|
||||
"<button type="button" class="rounded-md font-medium inline-flex items-center focus:outline-none focus-visible:outline-0 disabled:cursor-not-allowed disabled:opacity-75 flex-shrink-0 bg-blue-500 hover:bg-blue-700 text-sm gap-x-2 p-2"><svg data-v-66d85e84="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="icon flex-shrink-0 h-5 w-5" width="1em" height="1em" viewBox="0 0 24 24">
|
||||
"<button type="button" class="rounded-md font-medium inline-flex items-center focus:outline-none focus-visible:outline-0 disabled:cursor-not-allowed disabled:opacity-75 flex-shrink-0 bg-blue-500 hover:bg-blue-700 text-sm gap-x-1.5 p-1"><svg data-v-2f2f464d="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="icon flex-shrink-0 h-5 w-5" width="1em" height="1em" viewBox="0 0 24 24">
|
||||
<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M10.5 19.5L3 12m0 0l7.5-7.5M3 12h18"></path>
|
||||
</svg>
|
||||
<!--v-if-->
|
||||
@@ -61,7 +61,7 @@ exports[`Button > renders with leadingIcon correctly 1`] = `
|
||||
`;
|
||||
|
||||
exports[`Button > renders with loading correctly 1`] = `
|
||||
"<button type="button" disabled="" class="rounded-md font-medium inline-flex items-center focus:outline-none focus-visible:outline-0 disabled:cursor-not-allowed disabled:opacity-75 flex-shrink-0 bg-blue-500 hover:bg-blue-700 text-sm gap-x-2 p-2"><svg data-v-66d85e84="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="icon flex-shrink-0 h-5 w-5 animate-spin" width="1em" height="1em" viewBox="0 0 20 20">
|
||||
"<button type="button" disabled="" class="rounded-md font-medium inline-flex items-center focus:outline-none focus-visible:outline-0 disabled:cursor-not-allowed disabled:opacity-75 flex-shrink-0 bg-blue-500 hover:bg-blue-700 text-sm gap-x-1.5 p-1"><svg data-v-2f2f464d="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="icon flex-shrink-0 h-5 w-5 animate-spin" width="1em" height="1em" viewBox="0 0 20 20">
|
||||
<path fill="currentColor" fill-rule="evenodd" d="M15.312 11.424a5.5 5.5 0 0 1-9.201 2.466l-.312-.311h2.433a.75.75 0 0 0 0-1.5H3.989a.75.75 0 0 0-.75.75v4.242a.75.75 0 0 0 1.5 0v-2.43l.31.31a7 7 0 0 0 11.712-3.138a.75.75 0 0 0-1.449-.39m1.23-3.723a.75.75 0 0 0 .219-.53V2.929a.75.75 0 0 0-1.5 0V5.36l-.31-.31A7 7 0 0 0 3.239 8.188a.75.75 0 1 0 1.448.389A5.5 5.5 0 0 1 13.89 6.11l.311.31h-2.432a.75.75 0 0 0 0 1.5h4.243a.75.75 0 0 0 .53-.219" clip-rule="evenodd"></path>
|
||||
</svg>
|
||||
<!--v-if-->
|
||||
@@ -70,7 +70,7 @@ exports[`Button > renders with loading correctly 1`] = `
|
||||
`;
|
||||
|
||||
exports[`Button > renders with loadingIcon correctly 1`] = `
|
||||
"<button type="button" disabled="" class="rounded-md font-medium inline-flex items-center focus:outline-none focus-visible:outline-0 disabled:cursor-not-allowed disabled:opacity-75 flex-shrink-0 bg-blue-500 hover:bg-blue-700 text-sm gap-x-2 p-2"><svg data-v-66d85e84="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="icon flex-shrink-0 h-5 w-5 animate-spin" width="1em" height="1em" viewBox="0 0 24 24">
|
||||
"<button type="button" disabled="" class="rounded-md font-medium inline-flex items-center focus:outline-none focus-visible:outline-0 disabled:cursor-not-allowed disabled:opacity-75 flex-shrink-0 bg-blue-500 hover:bg-blue-700 text-sm gap-x-1.5 p-1"><svg data-v-2f2f464d="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="icon flex-shrink-0 h-5 w-5 animate-spin" width="1em" height="1em" viewBox="0 0 24 24">
|
||||
<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M9.813 15.904L9 18.75l-.813-2.846a4.5 4.5 0 0 0-3.09-3.09L2.25 12l2.846-.813a4.5 4.5 0 0 0 3.09-3.09L9 5.25l.813 2.846a4.5 4.5 0 0 0 3.09 3.09L15.75 12l-2.846.813a4.5 4.5 0 0 0-3.09 3.09m8.445-7.188L18 9.75l-.259-1.035a3.375 3.375 0 0 0-2.455-2.456L14.25 6l1.036-.259a3.375 3.375 0 0 0 2.455-2.456L18 2.25l.259 1.035a3.375 3.375 0 0 0 2.456 2.456L21.75 6l-1.035.259a3.375 3.375 0 0 0-2.456 2.456m-1.365 11.852L16.5 21.75l-.394-1.183a2.25 2.25 0 0 0-1.423-1.423L13.5 18.75l1.183-.394a2.25 2.25 0 0 0 1.423-1.423l.394-1.183l.394 1.183a2.25 2.25 0 0 0 1.423 1.423l1.183.394l-1.183.394a2.25 2.25 0 0 0-1.423 1.423"></path>
|
||||
</svg>
|
||||
<!--v-if-->
|
||||
@@ -79,7 +79,7 @@ exports[`Button > renders with loadingIcon correctly 1`] = `
|
||||
`;
|
||||
|
||||
exports[`Button > renders with padded correctly 1`] = `
|
||||
"<button type="button" class="rounded-md font-medium inline-flex items-center focus:outline-none focus-visible:outline-0 disabled:cursor-not-allowed disabled:opacity-75 flex-shrink-0 bg-blue-500 hover:bg-blue-700 px-3.5 py-2.5 text-sm gap-x-2.5">
|
||||
"<button type="button" class="rounded-md font-medium inline-flex items-center focus:outline-none focus-visible:outline-0 disabled:cursor-not-allowed disabled:opacity-75 flex-shrink-0 bg-blue-500 hover:bg-blue-700 px-2.5 py-1.5 text-sm gap-x-1.5">
|
||||
<!--v-if--><span class="">Button</span>
|
||||
<!--v-if-->
|
||||
</button>"
|
||||
@@ -93,37 +93,37 @@ exports[`Button > renders with size correctly 1`] = `
|
||||
`;
|
||||
|
||||
exports[`Button > renders with square correctly 1`] = `
|
||||
"<button type="button" class="rounded-md font-medium inline-flex items-center focus:outline-none focus-visible:outline-0 disabled:cursor-not-allowed disabled:opacity-75 flex-shrink-0 bg-blue-500 hover:bg-blue-700 text-sm gap-x-2 p-2">
|
||||
"<button type="button" class="rounded-md font-medium inline-flex items-center focus:outline-none focus-visible:outline-0 disabled:cursor-not-allowed disabled:opacity-75 flex-shrink-0 bg-blue-500 hover:bg-blue-700 text-sm gap-x-1.5 p-1">
|
||||
<!--v-if--><span class="">Button</span>
|
||||
<!--v-if-->
|
||||
</button>"
|
||||
`;
|
||||
|
||||
exports[`Button > renders with trailing slot correctly 1`] = `
|
||||
"<button type="button" class="rounded-md font-medium inline-flex items-center focus:outline-none focus-visible:outline-0 disabled:cursor-not-allowed disabled:opacity-75 flex-shrink-0 bg-blue-500 hover:bg-blue-700 text-sm gap-x-2 p-2">
|
||||
"<button type="button" class="rounded-md font-medium inline-flex items-center focus:outline-none focus-visible:outline-0 disabled:cursor-not-allowed disabled:opacity-75 flex-shrink-0 bg-blue-500 hover:bg-blue-700 text-sm gap-x-1.5 p-1">
|
||||
<!--v-if-->
|
||||
<!--v-if-->Trailing slot
|
||||
</button>"
|
||||
`;
|
||||
|
||||
exports[`Button > renders with trailingIcon correctly 1`] = `
|
||||
"<button type="button" class="rounded-md font-medium inline-flex items-center focus:outline-none focus-visible:outline-0 disabled:cursor-not-allowed disabled:opacity-75 flex-shrink-0 bg-blue-500 hover:bg-blue-700 text-sm gap-x-2 p-2">
|
||||
"<button type="button" class="rounded-md font-medium inline-flex items-center focus:outline-none focus-visible:outline-0 disabled:cursor-not-allowed disabled:opacity-75 flex-shrink-0 bg-blue-500 hover:bg-blue-700 text-sm gap-x-1.5 p-1">
|
||||
<!--v-if-->
|
||||
<!--v-if--><svg data-v-66d85e84="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="icon flex-shrink-0 h-5 w-5" width="1em" height="1em" viewBox="0 0 24 24">
|
||||
<!--v-if--><svg data-v-2f2f464d="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="icon flex-shrink-0 h-5 w-5" width="1em" height="1em" viewBox="0 0 24 24">
|
||||
<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M13.5 4.5L21 12m0 0l-7.5 7.5M21 12H3"></path>
|
||||
</svg>
|
||||
</button>"
|
||||
`;
|
||||
|
||||
exports[`Button > renders with truncate correctly 1`] = `
|
||||
"<button type="button" class="rounded-md font-medium inline-flex items-center focus:outline-none focus-visible:outline-0 disabled:cursor-not-allowed disabled:opacity-75 flex-shrink-0 bg-blue-500 hover:bg-blue-700 px-3 py-2 text-sm gap-x-2">
|
||||
"<button type="button" class="rounded-md font-medium inline-flex items-center focus:outline-none focus-visible:outline-0 disabled:cursor-not-allowed disabled:opacity-75 flex-shrink-0 bg-blue-500 hover:bg-blue-700 px-2.5 py-1.5 text-sm gap-x-1.5">
|
||||
<!--v-if--><span class="truncate">Button</span>
|
||||
<!--v-if-->
|
||||
</button>"
|
||||
`;
|
||||
|
||||
exports[`Button > renders with variant correctly 1`] = `
|
||||
"<button type="button" class="rounded-md font-medium inline-flex items-center focus:outline-none focus-visible:outline-0 disabled:cursor-not-allowed disabled:opacity-75 flex-shrink-0 bg-blue-500 hover:bg-blue-700 px-3 py-2 text-sm gap-x-2">
|
||||
"<button type="button" class="rounded-md font-medium inline-flex items-center focus:outline-none focus-visible:outline-0 disabled:cursor-not-allowed disabled:opacity-75 flex-shrink-0 bg-blue-500 hover:bg-blue-700 px-2.5 py-1.5 text-sm gap-x-1.5">
|
||||
<!--v-if--><span class="">Button</span>
|
||||
<!--v-if-->
|
||||
</button>"
|
||||
|
||||
13
test/components/__snapshots__/Link.spec.ts.snap
Normal file
13
test/components/__snapshots__/Link.spec.ts.snap
Normal file
@@ -0,0 +1,13 @@
|
||||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
||||
|
||||
exports[`Link > renders with activeClass correctly 1`] = `"<a href="/" class="text-sm"></a>"`;
|
||||
|
||||
exports[`Link > renders with as correctly 1`] = `"<div type="button" disabled="false"></div>"`;
|
||||
|
||||
exports[`Link > renders with disabled correctly 1`] = `"<button type="button" disabled=""></button>"`;
|
||||
|
||||
exports[`Link > renders with inactiveClass correctly 1`] = `"<a href="/" class="text-gray-300"></a>"`;
|
||||
|
||||
exports[`Link > renders with to correctly 1`] = `"<a href="/"></a>"`;
|
||||
|
||||
exports[`Link > renders with type correctly 1`] = `"<button type="submit"></button>"`;
|
||||
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user