primevue-mirror/components/lib/datepicker/DatePicker.spec.js

57 lines
1.9 KiB
JavaScript
Raw Normal View History

2022-09-06 12:03:37 +00:00
import { mount } from '@vue/test-utils';
2022-12-08 11:04:25 +00:00
import PrimeVue from 'primevue/config';
2024-04-18 14:13:33 +00:00
import DatePicker from './DatePicker.vue';
2022-09-06 12:03:37 +00:00
2024-04-18 14:13:33 +00:00
describe('DatePicker.vue', () => {
2022-09-06 12:03:37 +00:00
let wrapper;
beforeEach(() => {
2024-04-18 14:13:33 +00:00
wrapper = mount(DatePicker, {
2022-09-06 12:03:37 +00:00
global: {
plugins: [PrimeVue],
stubs: {
teleport: true
}
},
props: {
modelValue: new Date()
}
});
});
2022-12-08 11:04:25 +00:00
2022-09-14 11:26:01 +00:00
it('should exist', async () => {
2024-04-18 14:13:33 +00:00
expect(wrapper.find('.p-datepicker.p-component').exists()).toBe(true);
2022-09-06 12:03:37 +00:00
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 });
2022-09-14 11:26:01 +00:00
const event = { day: 8, month: 2, year: 2022, today: false, selectable: true };
2022-09-06 12:03:37 +00:00
2022-12-08 14:13:16 +00:00
const onDateSelect = vi.spyOn(wrapper.vm, 'onDateSelect');
2022-09-06 12:03:37 +00:00
2022-09-14 11:26:01 +00:00
await wrapper.vm.onDateSelect({ currentTarget: { focus: () => {} } }, event);
expect(onDateSelect).toHaveBeenCalled();
2022-09-06 12:03:37 +00:00
});
2022-12-08 11:04:25 +00:00
2022-09-06 12:03:37 +00:00
it('should calculate the correct view date when in range mode', async () => {
const dateOne = new Date();
const dateTwo = new Date();
2022-09-14 11:26:01 +00:00
dateTwo.setFullYear(dateOne.getFullYear(), dateOne.getMonth(), dateOne.getDate() + 1);
await wrapper.setProps({ selectionMode: 'range', showTime: true, modelValue: [dateOne, dateTwo] });
expect(wrapper.vm.viewDate).toEqual(dateTwo);
2022-09-06 12:03:37 +00:00
});
});