From b78e47581bafe77a8857375cf64aa22f74550b1a 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, 5 Apr 2022 17:45:32 +0300 Subject: [PATCH] Create SpeedDial.spec.js --- src/components/speeddial/SpeedDial.spec.js | 97 ++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 src/components/speeddial/SpeedDial.spec.js diff --git a/src/components/speeddial/SpeedDial.spec.js b/src/components/speeddial/SpeedDial.spec.js new file mode 100644 index 000000000..1d028a6d9 --- /dev/null +++ b/src/components/speeddial/SpeedDial.spec.js @@ -0,0 +1,97 @@ +import { mount } from '@vue/test-utils'; +import SpeedDial from './SpeedDial.vue'; + +describe('SpeedDial.vue', () => { + let wrapper; + + beforeEach(() => { + wrapper = mount(SpeedDial, { + props: { + model: [ + { + label: 'Add', + icon: 'pi pi-pencil' + }, + { + label: 'Update', + icon: 'pi pi-refresh' + }, + { + label: 'Delete', + icon: 'pi pi-trash' + }, + { + label: 'Upload', + icon: 'pi pi-upload', + command: () => { + window.location.hash = "/fileupload" + } + }, + { + label: 'Vue Website', + icon: 'pi pi-external-link', + command: () => { + window.location.href = 'https://vuejs.org/' + } + } + ], + direction: 'down' + } + }); + }); + + it('should exist', () => { + expect(wrapper.find('.p-speeddial.p-component').exists()).toBe(true); + expect(wrapper.find('.p-speeddial').classes()).toContain('p-speeddial-direction-down'); + expect(wrapper.findAll('li.p-speeddial-item').length).toEqual(5); + }); + + it('should show the list', async () => { + await wrapper.vm.onClick({}); + + expect(wrapper.emitted()['click'][0]).toEqual([{}]); + expect(wrapper.emitted()['show'][0]).toEqual([]); + expect(wrapper.find('.p-speeddial').classes()).toContain('p-speeddial-opened'); + expect(wrapper.findAll('li.p-speeddial-item')[0].attributes().style).toBe('transition-delay: 0ms;'); + }); + + it('should hide the list', async () => { + await wrapper.setProps({ visible: true }); + + await wrapper.vm.onClick({}); + + expect(wrapper.find('.p-speeddial').classes()).not.toContain('p-speeddial-opened'); + expect(wrapper.findAll('li.p-speeddial-item')[wrapper.findAll('li.p-speeddial-item').length - 1].attributes().style).toBe('transition-delay: 0ms;'); + }); + + it('should have radius and type', async () => { + await wrapper.setProps({ radius: 80, direction: 'left', type: 'semi-circle' }); + + expect(wrapper.find('.p-speeddial').classes()).toContain('p-speeddial-semi-circle'); + expect(wrapper.find('.p-speeddial').classes()).toContain('p-speeddial-direction-left'); + }); + + it('should transition delay', async () => { + await wrapper.setProps({ transitionDelay: 80 }); + + expect(wrapper.findAll('li.p-speeddial-item')[wrapper.findAll('li.p-speeddial-item').length - 2].attributes().style).toBe('transition-delay: 80ms;'); + }); + + it('should have show and hide icons', async () => { + await wrapper.setProps({ showIcon: 'pi pi-bars', hideIcon: 'pi pi-times' }); + + const button = wrapper.find('.p-speeddial-button'); + + expect(button.find('span').classes()).toContain('pi-bars'); + + await wrapper.vm.onClick({}); + + expect(button.find('span').classes()).toContain('pi-times'); + }); + + it('should have mask', async () => { + await wrapper.setProps({ mask: true }); + + expect(wrapper.find('.p-speeddial-mask').exists()).toBe(true); + }); +}); \ No newline at end of file