From 75f9d05852bb315cf71d1808fd292f9f6f2ba4ed 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, 10 Mar 2022 13:08:29 +0300 Subject: [PATCH] Calendar test added --- src/components/calendar/Calendar.spec.js | 45 ++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/components/calendar/Calendar.spec.js diff --git a/src/components/calendar/Calendar.spec.js b/src/components/calendar/Calendar.spec.js new file mode 100644 index 000000000..d1e1b325a --- /dev/null +++ b/src/components/calendar/Calendar.spec.js @@ -0,0 +1,45 @@ +import { mount } from '@vue/test-utils'; +import PrimeVue from '@/components/config/PrimeVue'; +import Calendar from './Calendar.vue'; + +describe('Calendar.vue', () => { + let wrapper; + + beforeEach(() => { + wrapper = mount(Calendar, { + global: { + plugins: [PrimeVue], + stubs: { + teleport: true + } + }, + props: { + modelValue: new Date() + } + }); + }); + it('should exist', async() => { + expect(wrapper.find('.p-calendar.p-component').exists()).toBe(true); + expect(wrapper.find('.p-inputtext').exists()).toBe(true); + + let input = wrapper.find('.p-inputtext'); + + await input.trigger('focus'); + + expect(wrapper.find('.p-datepicker.p-component').exists()).toBe(true); + expect(wrapper.find('.p-datepicker-today').exists()).toBe(true); + expect(wrapper.find('.p-highlight').exists()).toBe(true); + expect(wrapper.find('.p-highlight').text()).toEqual(new Date().getDate().toString()); + }); + + it('should select a date', async () => { + await wrapper.setProps({ inline: true }); + + const event = {day: 8, month: 2, year: 2022, today: false, selectable: true}; + + const onDateSelect = jest.spyOn(wrapper.vm, 'onDateSelect'); + + await wrapper.vm.onDateSelect({currentTarget: {focus: () => {}}}, event); + expect(onDateSelect).toHaveBeenCalled() + }); +}); \ No newline at end of file