From 38a36f4e489513fec4250290b8ce470285cf8038 Mon Sep 17 00:00:00 2001 From: Benjamin Canac Date: Wed, 6 Mar 2024 12:40:41 +0100 Subject: [PATCH] test(Button): add --- src/runtime/components/Button.vue | 16 +-- test/components/Button.spec.ts | 28 ++++ .../__snapshots__/Button.spec.ts.snap | 130 ++++++++++++++++++ 3 files changed, 166 insertions(+), 8 deletions(-) create mode 100644 test/components/Button.spec.ts create mode 100644 test/components/__snapshots__/Button.spec.ts.snap diff --git a/src/runtime/components/Button.vue b/src/runtime/components/Button.vue index fbc51f39..06dd8fc7 100644 --- a/src/runtime/components/Button.vue +++ b/src/runtime/components/Button.vue @@ -39,6 +39,14 @@ const props = defineProps({ type: String as PropType, default: undefined }, + color: { + type: String as PropType, + default: undefined + }, + size: { + type: String as PropType, + default: undefined + }, icon: { type: String as PropType, default: undefined @@ -87,14 +95,6 @@ const props = defineProps({ type: Boolean as PropType, default: false }, - color: { - type: String as PropType, - default: undefined - }, - size: { - type: String as PropType, - default: undefined - }, class: { type: String as PropType, default: undefined diff --git a/test/components/Button.spec.ts b/test/components/Button.spec.ts new file mode 100644 index 00000000..660509aa --- /dev/null +++ b/test/components/Button.spec.ts @@ -0,0 +1,28 @@ +import { describe, it, expect } from 'vitest' +import { UButton } from '#components' +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 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' } }], + ['with loading', { props: { loading: true } }], + ['with loadingIcon', { props: { loading: true, loadingIcon: 'i-heroicons-sparkles' } }], + ['with disabled', { props: { label: 'Button', disabled: true } }], + ['with padded', { props: { label: 'Button', padded: false } }], + ['with block', { props: { label: 'Button', block: true } }], + ['with square', { props: { label: 'Button', square: true } }], + ['with truncate', { props: { label: 'Button', truncate: true } }], + ['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) + expect(html).toMatchSnapshot() + }) +}) diff --git a/test/components/__snapshots__/Button.spec.ts.snap b/test/components/__snapshots__/Button.spec.ts.snap new file mode 100644 index 00000000..0b5244db --- /dev/null +++ b/test/components/__snapshots__/Button.spec.ts.snap @@ -0,0 +1,130 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`Button > renders with block correctly 1`] = ` +"" +`; + +exports[`Button > renders with color correctly 1`] = ` +"" +`; + +exports[`Button > renders with default slot correctly 1`] = ` +"" +`; + +exports[`Button > renders with disabled correctly 1`] = ` +"" +`; + +exports[`Button > renders with icon correctly 1`] = ` +"" +`; + +exports[`Button > renders with label correctly 1`] = ` +"" +`; + +exports[`Button > renders with leading slot correctly 1`] = ` +"" +`; + +exports[`Button > renders with leadingIcon correctly 1`] = ` +"" +`; + +exports[`Button > renders with loading correctly 1`] = ` +"" +`; + +exports[`Button > renders with loadingIcon correctly 1`] = ` +"" +`; + +exports[`Button > renders with padded correctly 1`] = ` +"" +`; + +exports[`Button > renders with size correctly 1`] = ` +"" +`; + +exports[`Button > renders with square correctly 1`] = ` +"" +`; + +exports[`Button > renders with trailing slot correctly 1`] = ` +"" +`; + +exports[`Button > renders with trailingIcon correctly 1`] = ` +"" +`; + +exports[`Button > renders with truncate correctly 1`] = ` +"" +`; + +exports[`Button > renders with variant correctly 1`] = ` +"" +`;