UNPKG

e2ed

Version:

E2E testing framework over Playwright

46 lines (45 loc) 1.93 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.scroll = void 0; const step_1 = require("../step"); const selectors_1 = require("../utils/selectors"); /** * Scrolls the document (or element) to the specified absolute position. */ exports.scroll = ((...args) => { const printedArgs = [...args]; if (args[0] instanceof selectors_1.Selector) { printedArgs.shift(); } const selector = args[0] instanceof selectors_1.Selector ? args[0] : selectors_1.Selector.create({ cssString: 'html', parameterAttributePrefix: 'data-test-', testIdAttribute: 'data-testid', testIdSeparator: '-', }); return (0, step_1.step)('Scroll the document (or element) to the specified position', async () => { await selector.getPlaywrightLocator().evaluate((el, clientArgs) => { const centerX = Math.floor(el.scrollWidth / 2 - el.clientWidth / 2); const centerY = Math.floor(el.scrollHeight / 2 - el.clientHeight / 2); const positions = { bottom: [centerX, el.scrollHeight], bottomLeft: [0, el.scrollHeight], bottomRight: [el.scrollWidth, el.scrollHeight], center: [centerX, centerY], left: [0, centerY], right: [el.scrollWidth, centerY], top: [centerX, 0], topLeft: [0, 0], topRight: [el.scrollWidth, 0], }; const position = positions[clientArgs[0]]; const [x, y] = position ?? clientArgs; // eslint-disable-next-line no-param-reassign el.scrollLeft = x; // eslint-disable-next-line no-param-reassign el.scrollTop = y; }, printedArgs); }, { payload: { args: printedArgs, selector }, type: 5 /* LogEventType.InternalAction */ }); });