ant-design-vue/components/date-picker/__tests__/utils.js

61 lines
1.6 KiB
JavaScript
Raw Normal View History

2019-01-12 03:33:27 +00:00
export function $$(className) {
return document.body.querySelectorAll(className);
2018-06-09 05:14:14 +00:00
}
2019-01-12 03:33:27 +00:00
export function hasSelected(wrapper, date) {
return document.body
.querySelector(`[title="${date.format('LL')}"][role="gridcell"]`)
.getAttribute('class')
.split(' ')
.includes('ant-calendar-selected-day');
2018-06-09 05:14:14 +00:00
}
2019-01-12 03:33:27 +00:00
export function openPanel(wrapper) {
wrapper.find('.ant-calendar-picker-input').trigger('click');
2018-06-09 05:14:14 +00:00
}
2019-01-12 03:33:27 +00:00
export function clearInput(wrapper) {
wrapper.find('.ant-calendar-picker-clear').trigger('click');
2018-06-09 05:14:14 +00:00
}
2019-01-12 03:33:27 +00:00
export function nextYear() {
$$('.ant-calendar-next-year-btn')[0].click();
2018-06-09 05:14:14 +00:00
}
2019-01-12 03:33:27 +00:00
export function nextMonth() {
$$('.ant-calendar-next-month-btn')[0].click();
2018-06-09 05:14:14 +00:00
}
2019-01-12 03:33:27 +00:00
export function selectDateFromBody(date, index) {
let calendar = document.body;
2018-06-09 05:14:14 +00:00
if (index !== undefined) {
2019-01-12 03:33:27 +00:00
calendar = document.body.querySelectorAll('.ant-calendar-range-part')[index];
2018-06-09 05:14:14 +00:00
}
2019-01-12 03:33:27 +00:00
calendar.querySelector(`[title="${date.format('LL')}"][role="gridcell"]`).click();
2018-06-09 05:14:14 +00:00
}
2021-08-26 14:29:46 +00:00
export function openPicker(wrapper, index = 0) {
wrapper.findAll('input')[index].trigger('mousedown');
wrapper.findAll('input')[index].trigger('focus');
}
export function closePicker(wrapper, index = 0) {
wrapper.findAll('input')[index].trigger('blur');
}
export function selectCell(wrapper, text, index = 0) {
let matchCell;
$$('table')
[index].querySelectorAll('td')
.forEach(td => {
if (td.textContent === String(text) && td.className.includes('-in-view')) {
matchCell = td;
td.click('click');
}
});
if (!matchCell) {
throw new Error('Cell not match in picker panel.');
}
return matchCell;
}