diff --git a/.playground/pages/composant/selectCheckbox.vue b/.playground/pages/composant/selectCheckbox.vue new file mode 100644 index 0000000..cc1df30 --- /dev/null +++ b/.playground/pages/composant/selectCheckbox.vue @@ -0,0 +1,168 @@ + + + diff --git a/CHANGELOG.md b/CHANGELOG.md index 546484e..142fb02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,11 +7,13 @@ Liste des évolutions de la librairie Malio layer UI ### Added * [#333] Création d'un composant text -* [#364] Création d'un composant button radio * [#337] Création d'un composant select +* [#362] Création d'un composant checkbox * [#363] Création d'un composant amount -* [#363] Création d'un composant checkbox - +* [#364] Création d'un composant button radio +* [#365] Création d'un composant number +* [#366] Création d'un composant select checkbox +* [#407] Création d'un composant time ### Changed ### Fixed diff --git a/app/components/malio/SelectCheckbox.test.ts b/app/components/malio/SelectCheckbox.test.ts new file mode 100644 index 0000000..0092f16 --- /dev/null +++ b/app/components/malio/SelectCheckbox.test.ts @@ -0,0 +1,95 @@ +import {describe, expect, it} from 'vitest' +import {mount} from '@vue/test-utils' +import type {DefineComponent} from 'vue' +import SelectCheckbox from './SelectCheckbox.vue' + +type Option = { + label: string + value: string | number +} + +type SelectCheckboxProps = { + modelValue: Array + options?: Option[] + emptyOptionLabel?: string + label?: string + hint?: string + error?: string + success?: string + minWidth?: string + maxWidth?: string + textField?: string + textValue?: string + textLabel?: string + rounded?: string + displayTag?: boolean + disabled?: boolean +} + +const SelectCheckboxForTest = SelectCheckbox as DefineComponent + +const options: Option[] = [ + {label: 'France', value: 'fr'}, + {label: 'Belgique', value: 'be'}, + {label: 'Canada', value: 'ca'}, +] + +describe('MalioSelectCheckbox', () => { + it('renders checkbox inputs for options', async () => { + const wrapper = mount(SelectCheckboxForTest, { + props: {modelValue: [], options}, + }) + + await wrapper.get('button').trigger('click') + + const checkboxes = wrapper.findAll('input[type="checkbox"]') + expect(checkboxes).toHaveLength(options.length) + }) + + it('emits an array with the toggled option value', async () => { + const wrapper = mount(SelectCheckboxForTest, { + props: {modelValue: ['fr'], options}, + }) + + await wrapper.get('button').trigger('click') + const checkboxInputs = wrapper.findAll('input[type="checkbox"]') + await checkboxInputs[1].setValue(true) + + expect(wrapper.emitted('update:modelValue')?.[0]).toEqual([['fr', 'be']]) + }) + + it('shows the selected count over the total count in the trigger', () => { + const wrapper = mount(SelectCheckboxForTest, { + props: {modelValue: ['fr', 'ca'], options}, + }) + + expect(wrapper.text()).toContain('2/3') + }) + + it('shows 0 over the total count when nothing is selected', () => { + const wrapper = mount(SelectCheckboxForTest, { + props: {modelValue: [], options}, + }) + + expect(wrapper.text()).toContain('0/3') + }) + + it('hides the summary when displayTag is enabled and options are selected', () => { + const wrapper = mount(SelectCheckboxForTest, { + props: {modelValue: ['fr', 'ca'], options, displayTag: true}, + }) + + expect(wrapper.text()).not.toContain('2/3') + expect(wrapper.text()).toContain('France') + expect(wrapper.text()).toContain('Canada') + }) + + it('hides the summary when displayTag is enabled and nothing is selected', () => { + const wrapper = mount(SelectCheckboxForTest, { + props: {modelValue: [], options, displayTag: true, emptyOptionLabel: 'Aucune selection'}, + }) + + expect(wrapper.text()).not.toContain('0/3') + expect(wrapper.text()).toContain('Aucune selection') + }) +}) diff --git a/app/components/malio/SelectCheckbox.vue b/app/components/malio/SelectCheckbox.vue new file mode 100644 index 0000000..7778882 --- /dev/null +++ b/app/components/malio/SelectCheckbox.vue @@ -0,0 +1,378 @@ + + + + +