123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
- import { renderComponent } from '#tests/support/components/index.ts'
- import { getByIconName } from '#tests/support/components/iconQueries.ts'
- import CommonButtonGroup from '../CommonButtonGroup.vue'
- import type { CommonButtonItem } from '../types.ts'
- const onActionClick = vi.fn()
- const items: CommonButtonItem[] = [
- {
- label: 'Button 1',
- variant: 'primary',
- icon: 'logo-flat',
- onActionClick,
- },
- {
- label: 'Button 2',
- variant: 'secondary',
- },
- {
- label: 'Button 3',
- variant: 'tertiary',
- },
- {
- label: 'Button 4',
- variant: 'submit',
- type: 'submit',
- },
- {
- label: 'Button 5',
- variant: 'danger',
- size: 'large',
- },
- ]
- describe('CommonButtonGroup.vue', () => {
- it('renders buttons with correct classes, types, ...', async () => {
- const view = renderComponent(CommonButtonGroup, {
- props: {
- items,
- },
- })
- const buttons = view.getAllByRole('button')
- expect(buttons).toHaveLength(5)
- const primaryButton = buttons[0]
- expect(primaryButton).toHaveAttribute('type', 'button')
- expect(primaryButton).toHaveClasses(['btn-primary', 'bg-blue-800'])
- expect(getByIconName(primaryButton, 'logo-flat')).toBeInTheDocument()
- await view.events.click(primaryButton)
- expect(onActionClick).toHaveBeenCalledOnce()
- const submitButton = buttons[3]
- expect(submitButton).toHaveAttribute('type', 'submit')
- const dangerButton = buttons[4]
- expect(dangerButton).toHaveClasses(['btn-error', 'text-red-500'])
- })
- })
|