From 130967049f2cb7a684ae309b1ad183cdc4215a85 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: Mon, 13 Jun 2022 13:01:20 +0300 Subject: [PATCH] Create ToggleButton.spec.js --- .../togglebutton/ToggleButton.spec.js | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/components/togglebutton/ToggleButton.spec.js diff --git a/src/components/togglebutton/ToggleButton.spec.js b/src/components/togglebutton/ToggleButton.spec.js new file mode 100644 index 000000000..b2033ef9e --- /dev/null +++ b/src/components/togglebutton/ToggleButton.spec.js @@ -0,0 +1,54 @@ +import { mount } from '@vue/test-utils'; +import ToggleButton from './ToggleButton.vue'; + +describe('ToggleButton', () => { + let wrapper; + + beforeEach(() => { + wrapper = mount(ToggleButton, { + props: { + modelValue: false, + onIcon: 'pi pi-check', + offIcon: 'pi pi-times' + } + }); + }); + + it('is ToggleButton exist', () => { + expect(wrapper.find('.p-togglebutton.p-component').exists()).toBe(true); + expect(wrapper.find('span.pi-times.p-button-icon').exists()).toBe(true); + }); + + it('should have onIcon', async () => { + await wrapper.setProps({ modelValue: true }); + + expect(wrapper.find('span.pi-check').exists()).toBe(true); + }); + + it('should click works', async () => { + await wrapper.vm.onClick({}); + + expect(wrapper.emitted()['update:modelValue'][0]).toEqual([true]); + + await wrapper.setProps({ modelValue: true }); + await wrapper.vm.onClick({}); + + expect(wrapper.emitted()['update:modelValue'][1]).toEqual([false]); + }); + + it('should be customized', async () => { + await wrapper.setProps({ + modelValue: true, + onLabel: 'I confirm', + offLabel: 'I reject', + style: 'width: 10em' + }); + + expect(wrapper.find('.p-button-label').text()).toBe('I confirm'); + expect(wrapper.attributes().style).toContain('width: 10em'); + + await wrapper.setProps({ modelValue: false }); + + expect(wrapper.find('.p-button-label').text()).toBe('I reject'); + }); +}); \ No newline at end of file