From 1cabeff5f0ce82f0e3885989d74bec4bd2bec023 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tu=C4=9F=C3=A7e=20K=C3=BC=C3=A7=C3=BCko=C4=9Flu?= Date: Tue, 22 Mar 2022 14:46:33 +0300 Subject: [PATCH] Create SelectButton.spec.js --- .../selectbutton/SelectButton.spec.js | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/components/selectbutton/SelectButton.spec.js diff --git a/src/components/selectbutton/SelectButton.spec.js b/src/components/selectbutton/SelectButton.spec.js new file mode 100644 index 000000000..4a5387a0b --- /dev/null +++ b/src/components/selectbutton/SelectButton.spec.js @@ -0,0 +1,56 @@ +import { mount } from '@vue/test-utils'; +import SelectButton from './SelectButton.vue'; + +describe('SelectButton.vue', () => { + let wrapper; + + beforeEach(() => { + wrapper = mount(SelectButton, { + props: { + modelValue: null, + options: ['Off', 'On'] + } + }); + }); + + it('should exist', () => { + expect(wrapper.find('.p-selectbutton.p-component').exists()).toBe(true); + expect(wrapper.findAll('.p-button.p-component').length).toBe(2); + }); + + it('should option select', async () => { + await wrapper.vm.onOptionSelect({}, wrapper.vm.options[0]); + + expect(wrapper.emitted()['update:modelValue'][0]).toEqual(['Off']); + + await wrapper.setProps({ modelValue: wrapper.vm.options[0] }); + + expect(wrapper.findAll('.p-button.p-component')[0].attributes()['aria-pressed']).toBe('true'); + expect(wrapper.findAll('.p-button.p-component')[0].classes()).toContain('p-highlight'); + }); +}); + +describe('multiple select', () => { + let wrapper; + + beforeEach(() => { + wrapper = mount(SelectButton, { + props: { + modelValue: null, + options: [ + {name: 'Option 1', value: 1}, + {name: 'Option 2', value: 2}, + {name: 'Option 3', value: 3} + ], + optionLabel: 'name', + multiple: true + } + }); + }); + + it('should select', async () => { + await wrapper.setProps({ modelValue: wrapper.vm.options }); + + expect(wrapper.findAll('.p-highlight').length).toBe(3); + }); +}); \ No newline at end of file