import { describe, test, expect } from 'vitest'
import { mount } from '@vue/test-utils'
import VAccordion from '../src/components/accordion/VAccordion.vue'
import VAccordionChild from '../src/components/accordion/VAccordionChild.vue'
describe('VAccordion', () => {
const factory = () =>
mount(VAccordion, {
props: {
value: '0',
},
slots: {
default: `
Un titre d'accordéon 1
Contenu 1
Un titre d'accordéon 2
Contenu 2
Un titre d'accordéon 3
Contenu 3
`,
},
global: {
components: {
VAccordionChild,
},
},
})
test('renders three accordion panels', () => {
const wrapper = factory()
const panels = wrapper.findAll('.p-accordionpanel')
expect(panels).toHaveLength(3)
})
test('activates the first panel by default', () => {
const wrapper = factory()
const firstPanel = wrapper.findAll('.p-accordionpanel')[0]
expect(firstPanel.classes()).toContain('p-accordionpanel-active')
expect(firstPanel.attributes('data-p-active')).toBe('true')
})
test('disables the second panel', () => {
const wrapper = factory()
const secondPanel = wrapper.findAll('.p-accordionpanel')[1]
expect(secondPanel.classes()).toContain('p-disabled')
expect(secondPanel.attributes('data-p-disabled')).toBe('true')
expect(secondPanel.find('button').attributes('disabled')).toBeDefined()
})
})