From 9616fdb88cd20b938a3f8649e6c67d0d7751802f 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 13:58:41 +0300 Subject: [PATCH] rating tests added --- src/components/rating/Rating.spec.js | 45 ++++++++++++++++++++++++++++ src/components/rating/Rating.vue | 2 +- 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 src/components/rating/Rating.spec.js diff --git a/src/components/rating/Rating.spec.js b/src/components/rating/Rating.spec.js new file mode 100644 index 000000000..d2b8a4586 --- /dev/null +++ b/src/components/rating/Rating.spec.js @@ -0,0 +1,45 @@ +import { mount } from '@vue/test-utils'; +import Rating from './Rating.vue'; + +describe('Rating.vue', () => { + let wrapper; + + beforeEach(() => { + wrapper = mount(Rating); + }); + + it('should exist', () => { + expect(wrapper.find('.p-rating').exists()).toBe(true); + expect(wrapper.find('.p-rating-icon').exists()).toBe(true); + }); + + it('should update model', async () => { + await wrapper.vm.updateModel({}, 5); + + expect(wrapper.emitted()['update:modelValue'][0]).toEqual([5]); + expect(wrapper.emitted()['change'][0]).toEqual([{originalEvent: {}, value: 5}]); + }); + + it('should click', async () => { + await wrapper.vm.onStarClick({}, 1); + + expect(wrapper.emitted()['update:modelValue'][0]).toEqual([1]); + + await wrapper.setProps({ modelValue: 1 }); + + expect(wrapper.findAll('.p-rating-icon')[1].classes()).toContain('pi-star-fill'); + expect(wrapper.findAll('.p-rating-icon')[2].classes()).not.toContain('pi-star-fill'); + }); + + it('should cancel', async () => { + await wrapper.vm.onCancelClick({}); + + expect(wrapper.emitted()['update:modelValue'][0]).toEqual([null]); + }); + + it('should not cancel', async () => { + await wrapper.setProps({ cancel: false }); + + expect(wrapper.find('.p-rating-cancel').exists()).toBe(false); + }); +}); \ No newline at end of file diff --git a/src/components/rating/Rating.vue b/src/components/rating/Rating.vue index 3abbd4d60..37c754164 100755 --- a/src/components/rating/Rating.vue +++ b/src/components/rating/Rating.vue @@ -38,7 +38,7 @@ export default { this.updateModel(event, value); } }, - onCancelClick() { + onCancelClick(event) { if (!this.readonly && !this.disabled) { this.updateModel(event, null); }