From 9b5019c6025270405927b697858f27d3eeb42ecf Mon Sep 17 00:00:00 2001 From: Paul Valerie GOMA Date: Mon, 21 Jul 2025 09:58:47 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20test:=20Added=20VButtonGroup=20test?= =?UTF-8?q?=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/VButtonGroup.spec.ts | 46 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 test/VButtonGroup.spec.ts diff --git a/test/VButtonGroup.spec.ts b/test/VButtonGroup.spec.ts new file mode 100644 index 0000000..68918b4 --- /dev/null +++ b/test/VButtonGroup.spec.ts @@ -0,0 +1,46 @@ +import { mount } from "@vue/test-utils"; +import VButtonGroup from '../src/components/button/VButtonGroup.vue'; +import {test, expect, describe, vi} from 'vitest'; + +const buttons = [ + {title: 'button 1', label: 'label 1', onClick: vi.fn()}, + {title: 'button 2', label: 'label 2', onClick: vi.fn()} +] + +describe('VButtonGroup', () => { + test('Displays all buttons passed as props', () => { + const wrapper = mount(VButtonGroup, { + props: { + buttons, + title: 'button group', + } + }) + const buttonElements = wrapper.findAll('button') + expect(buttonElements).toHaveLength(2) + expect(buttonElements[0].text()).toContain('label 1') + expect(buttonElements[1].text()).toContain('label 2') + }) + + test('applies the inline class when inlineLayoutWhen is “always”', () => { + const wrapper = mount(VButtonGroup, { + props: { + buttons, + title: 'button group', + inlineLayoutWhen: 'always', + } + }) + expect(wrapper.classes()).toContain('btns-group--inline') + }) + + test('clicked button', async () => { + const onClick = vi.fn() + const wrapper = mount(VButtonGroup, { + props: { + buttons: [{title: 'button 1', label: 'label 1', onClick}], + title: 'button group', + } + }) + await wrapper.find('button').trigger('click') + expect(onClick).toHaveBeenCalled() + }) +})