@elastic/eui
Version:
Elastic UI Component Library
63 lines (59 loc) • 2.3 kB
JavaScript
import _defineProperty from "@babel/runtime/helpers/defineProperty";
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
/// <reference types="cypress" />
/// <reference types="cypress-real-events" />
/// <reference types="../../../cypress/support" />
import React from 'react';
import { jsx as ___EmotionJSX } from "@emotion/react";
export var testRepositionOnScroll = function testRepositionOnScroll(_ref) {
var shouldReposition = _ref.shouldReposition,
propValue = _ref.propValue,
componentDefaultValue = _ref.componentDefaultValue,
componentName = _ref.componentName,
triggerSelector = _ref.triggerSelector,
panelSelector = _ref.panelSelector,
renderComponent = _ref.renderComponent;
var repositionProps = {
repositionOnScroll: typeof propValue === 'boolean' ? propValue : undefined
};
var providerProps = typeof componentDefaultValue === 'boolean' ? {
providerProps: {
componentDefaults: _defineProperty({}, componentName, {
repositionOnScroll: componentDefaultValue
})
}
} : undefined;
cy.mount(___EmotionJSX(React.Fragment, null, ___EmotionJSX("div", {
style: {
height: '200vh'
}
}), ___EmotionJSX("div", {
style: {
position: 'fixed',
bottom: '16px',
right: '16px'
}
}, renderComponent(repositionProps))), providerProps);
cy.get(triggerSelector).click();
// Wait for positioning to finish
cy.get(panelSelector).as('panel').should('exist').waitForPositionToSettle();
cy.get('@panel').then(function ($panel) {
var initialRect = $panel[0].getBoundingClientRect();
cy.scrollTo(0, 500);
// Wait for re-positioning to finish
cy.get('@panel').waitForPositionToSettle().then(function ($repositionedPanel) {
var finalRect = $repositionedPanel[0].getBoundingClientRect();
if (shouldReposition) {
expect(finalRect.top).to.equal(initialRect.top);
} else {
expect(finalRect.top).to.not.equal(initialRect.top);
}
});
});
};