@ozen-ui/kit
Version:
React component library
46 lines (45 loc) • 2.11 kB
JavaScript
import { screen } from '@testing-library/react';
import { cnCalendarDays, cnCalendarMoths, cnCalendarYears, } from '../components';
import { cnCalendar } from '../utils';
export var getRoot = function () { return screen.getByTestId('calendar'); };
export var getFromCalendar = function () {
return getRoot().querySelectorAll(".".concat(cnCalendar('MonthContainer')))[0];
};
export var getToCalendar = function () {
return getRoot().querySelectorAll(".".concat(cnCalendar('MonthContainer')))[1];
};
export var getButtonPrevPeriod = function () {
return screen.getByLabelText('prev');
};
export var getButtonNextPeriod = function () {
return screen.getByLabelText('next');
};
export var getDaysGrid = function (root) {
return (root !== null && root !== void 0 ? root : getRoot()).querySelector(".".concat(cnCalendarDays()));
};
export var getMonthsGrid = function (root) {
return (root !== null && root !== void 0 ? root : getRoot()).querySelector(".".concat(cnCalendarMoths()));
};
export var getYearsGrid = function (root) {
return (root !== null && root !== void 0 ? root : getRoot()).querySelector(".".concat(cnCalendarYears()));
};
export var getStep = function (root) {
if (getDaysGrid(root)) {
return 'days';
}
if (getMonthsGrid(root)) {
return 'months';
}
if (getYearsGrid(root)) {
return 'years';
}
throw new Error('Не удалось определить шаг календаря.');
};
export var getGridButton = function (text, root) {
var rootElement = root !== null && root !== void 0 ? root : getRoot();
var button = Array.from(rootElement.querySelectorAll('.CalendarGridItem')).find(function (element) { var _a; return ((_a = element.textContent) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === String(text).toLowerCase(); });
if (!button) {
throw new Error("\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u043D\u0430\u0439\u0442\u0438 \u043A\u043D\u043E\u043F\u043A\u0443 \u0441 \u0442\u0435\u043A\u0441\u0442\u043E\u043C \"".concat(text, "\""));
}
return button;
};