UNPKG

wix-style-react

Version:
62 lines 2.39 kB
import React from 'react'; import { createRendererWithDriver } from '../../test-utils/utils/react'; import { withFocusable } from './Focusable'; const hasFocusState = element => element.className.includes('focus') === true; const hasFocusVisibleState = element => element.className.includes('focus-visible') === true; export class PureChildComponent extends React.PureComponent { constructor(props) { super(props); this.unboundMethod = () => 'unboundMethod'; this.boundMethod = () => this.id; this.id = props.id; this.boundMethod = this.boundMethod.bind(this); } render() { return (React.createElement("div", { onFocus: this.props.focusableOnFocus, onBlur: this.props.focusableOnBlur, "data-hook": this.props['data-hook'], className: this.props.className }, "Hello")); } } PureChildComponent.staticVariable = 'staticVariable'; PureChildComponent.staticMethod = () => 'staticMethod'; const focusableDriverFactory = ({ element, eventTrigger }) => { return { exists: () => !!element, focus: () => !!element && eventTrigger.focus(element), blur: () => !!element && eventTrigger.blur(element), hasFocusState: () => !!element && hasFocusState(element), hasFocusVisibleState: () => !!element && hasFocusVisibleState(element), }; }; const render = createRendererWithDriver(focusableDriverFactory); export const createDriver = Component => { const { driver } = render(Component); const fireMouseDown = () => window.dispatchEvent(new window.Event('mousedown')); const fireMouseUp = () => window.dispatchEvent(new window.Event('mouseup')); const fireKeyDown = () => window.dispatchEvent(new window.Event('keydown')); const fireKeyUp = () => window.dispatchEvent(new window.Event('keyup')); const tabOut = () => { fireKeyDown(); driver.blur(); fireKeyUp(); }; const tabIn = () => { fireKeyDown(); driver.focus(); fireKeyUp(); }; const click = () => { fireMouseDown(); driver.focus(); fireMouseUp(); }; return { ...driver, fireMouseDown, fireKeyDown, fireKeyUp, tabOut, tabIn, click, }; }; export const WithFocusablePureComponent = withFocusable(PureChildComponent); //# sourceMappingURL=Focusable.driver.js.map