From a9c3a94e0fd1d04eecf7eb65319d8d401dc3ec24 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: Thu, 17 Mar 2022 17:14:49 +0300 Subject: [PATCH] Create Knob.spec.js --- src/components/knob/Knob.spec.js | 47 ++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/components/knob/Knob.spec.js diff --git a/src/components/knob/Knob.spec.js b/src/components/knob/Knob.spec.js new file mode 100644 index 000000000..f99622b1f --- /dev/null +++ b/src/components/knob/Knob.spec.js @@ -0,0 +1,47 @@ +import { mount } from '@vue/test-utils'; +import Knob from './Knob.vue'; + +describe('Knob.vue', () => { + let wrapper; + + beforeEach(() => { + wrapper = mount(Knob, { + props: { + modelValue: 20 + } + }); + }); + + it('should exist', () => { + expect(wrapper.find('.p-knob.p-component').exists()).toBe(true); + expect(wrapper.find('.p-knob-text').text()).toBe('20'); + }); + + it('should change with click event', async () => { + const event = { offsetX: 100, offsetY: 100 }; + + await wrapper.vm.onClick(event); + + expect(wrapper.emitted()['update:modelValue'][0]).toEqual([95]); + }); + + it('should min - max work', async () => { + await wrapper.setProps({ min: -50, max: 50 }); + + const event = { offsetX: 100, offsetY: 100 }; + + await wrapper.vm.onClick(event); + + expect(wrapper.emitted()['update:modelValue'][0]).toEqual([45]); + }); + + it('should step work', async () => { + await wrapper.setProps({ step: 10 }); + + const event = { offsetX: 18, offsetY: 30 }; + + await wrapper.vm.onClick(event); + + expect(wrapper.emitted()['update:modelValue'][0]).toEqual([30]); + }); +}); \ No newline at end of file