2025-07-19 03:05:42 +02:00
|
|
|
import { mount } from '@vue/test-utils'
|
|
|
|
import VButton from '@/components/button/VButton.vue'
|
|
|
|
import {test, expect, describe} from 'vitest'
|
|
|
|
|
|
|
|
describe('VButton', () => {
|
|
|
|
test('Displays button label', () => {
|
|
|
|
const wrapper = mount(VButton, {
|
|
|
|
props: {
|
|
|
|
label: 'button label',
|
|
|
|
title: 'button'
|
|
|
|
}
|
|
|
|
})
|
2025-07-19 03:18:08 +02:00
|
|
|
// Check that the props label has gone through
|
|
|
|
expect(wrapper.props('label')).toBe('button label')
|
|
|
|
// Checks that the rendering contains the expected value
|
2025-07-19 03:05:42 +02:00
|
|
|
expect(wrapper.text()).toContain('button label')
|
2025-07-19 14:24:54 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Displays only icon button when iconOnly props is set', () => {
|
|
|
|
const wrapper = mount(VButton, {
|
|
|
|
props: {
|
|
|
|
icon: 'ri-settings-4-line',
|
|
|
|
iconOnly: true,
|
|
|
|
label: 'label',
|
|
|
|
title: 'button'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
const button = wrapper.find('button')
|
|
|
|
// check the rendering doesn't contain any button label
|
|
|
|
expect(button.text()).toBe('')
|
|
|
|
// Check the icon is present
|
|
|
|
const icon = button.find('.p-button-icon')
|
|
|
|
expect(icon.exists()).toBe(true)
|
|
|
|
expect(icon.classes()).toContain('ri-settings-4-line')
|
|
|
|
// check that the aria-label attribute is correctly defined
|
|
|
|
expect(button.attributes('aria-label')).toBe('label')
|
2025-07-19 03:05:42 +02:00
|
|
|
})
|
|
|
|
})
|