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 1/4] 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 From fdcc8bc36a94e8bf22d7a847f3edf573d3edf19c 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:18:23 +0300 Subject: [PATCH 2/4] portal added --- jest.config.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/jest.config.js b/jest.config.js index 35fb25a03..7ef8a012a 100644 --- a/jest.config.js +++ b/jest.config.js @@ -25,7 +25,8 @@ module.exports = { "^primevue/toasteventbus(.*)$": "/src/components/toasteventbus/ToastEventBus.js", "^primevue/overlayeventbus(.*)$": "/src/components/overlayeventbus/OverlayEventBus.js", "^primevue/terminalservice(.*)$": "/src/components/terminalservice/TerminalService.js", - "^primevue/virtualscroller(.*)$": "/src/components/virtualscroller/VirtualScroller.vue" + "^primevue/virtualscroller(.*)$": "/src/components/virtualscroller/VirtualScroller.vue", + "^primevue/portal(.*)$": "/src/components/portal/Portal.vue" }, testMatch: [ "**/src/components/**/*.spec.{j,t}s?(x)" From 65a1feec6599647c51d6d9eda124bcc6ca34be5f 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:18:26 +0300 Subject: [PATCH 3/4] Create TriStateCheckbox.spec.js --- .../tristatecheckbox/TriStateCheckbox.spec.js | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/components/tristatecheckbox/TriStateCheckbox.spec.js diff --git a/src/components/tristatecheckbox/TriStateCheckbox.spec.js b/src/components/tristatecheckbox/TriStateCheckbox.spec.js new file mode 100644 index 000000000..2dbb20295 --- /dev/null +++ b/src/components/tristatecheckbox/TriStateCheckbox.spec.js @@ -0,0 +1,47 @@ +import { mount } from '@vue/test-utils'; +import TriStateCheckbox from './TriStateCheckbox.vue'; + +describe('TriStateCheckbox.vue', () => { + let wrapper; + + beforeEach(() => { + wrapper = mount(TriStateCheckbox, { + props: { + modelValue: null + } + }); + }); + + it('is TriStateCheckbox exist', () => { + expect(wrapper.find('.p-checkbox.p-component').exists()).toBe(true); + }); + + it('is state changed', 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]); + + await wrapper.setProps({modelValue: false}); + await wrapper.vm.onClick({}); + + expect(wrapper.emitted()['update:modelValue'][2]).toEqual([null]); + }); + + it('is icon chenaged', async () => { + expect(wrapper.find('.p-checkbox-icon').classes()).not.toContain('pi-check'); + expect(wrapper.find('.p-checkbox-icon').classes()).not.toContain('pi-times'); + + await wrapper.setProps({modelValue: true}); + + expect(wrapper.find('.p-checkbox-icon').classes()).toContain('pi-check'); + + await wrapper.setProps({modelValue: false}); + + expect(wrapper.find('.p-checkbox-icon').classes()).toContain('pi-times'); + }); +}); \ No newline at end of file From 28f0db78df7044ffcbeed4401204554d6d5468c9 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, 14 Jun 2022 10:03:24 +0300 Subject: [PATCH 4/4] Create InputNumber.spec.js --- .../inputnumber/InputNumber.spec.js | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 src/components/inputnumber/InputNumber.spec.js diff --git a/src/components/inputnumber/InputNumber.spec.js b/src/components/inputnumber/InputNumber.spec.js new file mode 100644 index 000000000..9d735de65 --- /dev/null +++ b/src/components/inputnumber/InputNumber.spec.js @@ -0,0 +1,95 @@ +import { mount } from '@vue/test-utils'; +import InputNumber from './InputNumber.vue'; + +describe('InputNumber.vue', () => { + let wrapper; + + beforeEach(() => { + wrapper = mount(InputNumber, { + props: { + modelValue: 1 + } + }); + }); + + it('is exist', () => { + expect(wrapper.find('.p-inputnumber.p-component').exists()).toBe(true); + expect(wrapper.find('input.p-inputnumber-input').exists()).toBe(true); + }); + + it('is keydown called when down and up keys pressed', async () => { + await wrapper.vm.onInputKeyDown({which: 38, target: { value: 1 }, preventDefault: () => {}}); + + expect(wrapper.emitted()['update:modelValue'][0]).toEqual([2]); + + await wrapper.vm.onInputKeyDown({which: 40, target: { value: 2 }, preventDefault: () => {}}) + + expect(wrapper.emitted()['update:modelValue'][1]).toEqual([1]); + }); + + it('is keydown called when tab key pressed', async () => { + await wrapper.vm.onInputKeyDown({which: 9, target: { value: '12' }, preventDefault: () => {}}); + + expect(wrapper.emitted()['update:modelValue'][0]).toEqual([12]); + expect(wrapper.find('input.p-inputnumber-input').attributes()['aria-valuenow']).toBe('12'); + }); + + it('is keydown called when enter key pressed', async () => { + await wrapper.vm.onInputKeyDown({which: 13, target: { value: '12' }, preventDefault: () => {}}); + + expect(wrapper.emitted()['update:modelValue'][0]).toEqual([12]); + expect(wrapper.find('input.p-inputnumber-input').attributes()['aria-valuenow']).toBe('12'); + }); + + it('is keypress called when pressed a number', async () => { + wrapper.find('input.p-inputnumber-input').element.setSelectionRange(2,2); + + await wrapper.vm.onInputKeyPress({which: 49, preventDefault: () => {}}); + + expect(wrapper.emitted().input[0][0].value).toBe(11); + }); + + it('is keypress called when pressed minus', async () => { + wrapper.find('input.p-inputnumber-input').element.setSelectionRange(0,0); + + await wrapper.vm.onInputKeyPress({keyCode: 45, preventDefault: () => {}}); + + expect(wrapper.emitted().input[0][0].value).toBe(-1); + }); + + it('should have min boundary', async () => { + await wrapper.setProps({ modelValue: 95, min: 95}); + + await wrapper.vm.onInputKeyDown({which: 40, target: { value: 96 }, preventDefault: () => {}}); + + expect(wrapper.emitted()['update:modelValue'][0]).toEqual([95]); + + await wrapper.vm.onInputKeyDown({which: 40, target: { value: 95 }, preventDefault: () => {}}); + + expect(wrapper.emitted()['update:modelValue'][1]).toEqual([95]); + }); + + it('should have max boundary', async () => { + await wrapper.setProps({ modelValue: 99, max: 100}); + + await wrapper.vm.onInputKeyDown({which: 38, target: { value: 99 }, preventDefault: () => {}}); + + expect(wrapper.emitted()['update:modelValue'][0]).toEqual([100]); + + await wrapper.vm.onInputKeyDown({which: 38, target: { value: 100 }, preventDefault: () => {}}); + + expect(wrapper.emitted()['update:modelValue'][1]).toEqual([100]); + }); + + it('should have currency', async () => { + await wrapper.setProps({ modelValue: 12345, mode: 'currency', currency: 'USD', locale: 'en-US'}); + + expect(wrapper.find('input.p-inputnumber-input').element._value).toBe('$12,345.00'); + }); + + it('should have prefix', async () => { + await wrapper.setProps({ modelValue: 20, prefix: '%' }); + + expect(wrapper.find('input.p-inputnumber-input').element._value).toBe('%20'); + }); +}); \ No newline at end of file