123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
- import { renderComponent } from '#tests/support/components/index.ts'
- import CommonButton from '../CommonButton.vue'
- describe('CommonButton.vue', () => {
- it('renders with default prop values', async () => {
- const view = renderComponent(CommonButton)
- const button = view.getByRole('button')
- expect(button).toHaveAttribute('type', 'button')
- expect(button).toHaveClasses(['-:inline-flex', 'bg-transparent', 'btn-sm'])
- })
- it('renders default slot as the button label', async () => {
- const view = renderComponent(CommonButton, {
- slots: {
- default: 'Button',
- },
- })
- expect(view.getByRole('button', { name: 'Button' })).toBeInTheDocument()
- })
- it('supports type prop', async () => {
- const view = renderComponent(CommonButton, {
- props: {
- type: 'submit',
- },
- })
- expect(view.getByRole('button')).toHaveAttribute('type', 'submit')
- })
- it('supports form prop', async () => {
- const view = renderComponent(CommonButton, {
- props: {
- form: 'foobar',
- },
- })
- expect(view.getByRole('button')).toHaveAttribute('form', 'foobar')
- })
- it('supports disabled prop', async () => {
- const view = renderComponent(CommonButton, {
- props: {
- disabled: true,
- },
- })
- expect(view.getByRole('button')).toBeDisabled()
- })
- it('supports block prop', async () => {
- const view = renderComponent(CommonButton, {
- props: {
- block: true,
- },
- })
- expect(view.getByRole('button')).toHaveClasses(['w-full'])
- })
- it.each([
- {
- variant: 'primary',
- classes: ['bg-blue-800'],
- },
- {
- variant: 'secondary',
- classes: ['bg-transparent'],
- },
- {
- variant: 'tertiary',
- classes: ['bg-green-200'],
- },
- {
- variant: 'submit',
- classes: ['bg-yellow-300'],
- },
- {
- variant: 'danger',
- classes: ['bg-pink-100'],
- },
- {
- variant: 'remove',
- classes: ['bg-red-400'],
- },
- {
- variant: 'subtle',
- classes: ['bg-blue-600'],
- },
- {
- variant: 'neutral',
- classes: ['bg-transparent'],
- },
- ])('supports $variant variant', async ({ variant, classes }) => {
- const view = renderComponent(CommonButton, {
- props: {
- variant,
- },
- })
- expect(view.getByRole('button')).toHaveClasses(classes)
- })
- it('supports prefix/suffix icon props', async () => {
- const view = renderComponent(CommonButton, {
- props: {
- prefixIcon: 'logo',
- suffixIcon: 'logo',
- },
- })
- expect(view.getAllByIconName('logo').length).toBe(2)
- })
- it('supports icon prop', async () => {
- const view = renderComponent(CommonButton, {
- props: {
- icon: 'logo',
- },
- slots: {
- default: 'foobar',
- },
- })
- expect(view.getByIconName('logo')).toBeInTheDocument()
- expect(
- view.queryByRole('button', { name: 'foobar' }),
- ).not.toBeInTheDocument()
- })
- })
|