import ReactTestUtils from 'react-dom/test-utils';
import { ReactBase } from './ReactBase';
import { act } from './actCompat';
import { isElementFocused } from '.';
/** Receives a unidriver of container that wraps a DraftJS input
 * and returns the input content element */
export const getContent = base => base.$('.public-DraftEditor-content');
/** Receives a unidriver of container (base) that wraps a DraftJS input,
 * and a `value` to add to the input
 * adds the value to the current input value */
export const enterRichTextValue = async (base, value) => {
    const contentElement = getContent(base);
    const nativeElement = await contentElement.getNative();
    if (contentElement.type === 'react') {
        await act(async () => {
            ReactTestUtils.Simulate.beforeInput(nativeElement, { data: value });
        });
    }
    else if (contentElement.type === 'puppeteer') {
        await contentElement.enterValue(value, { shouldClear: false });
    }
    else {
        throw new Error('unsupported adapter');
    }
};
export const focusRichEditor = async (base) => {
    switch (base.type) {
        case 'react':
            return ReactBase(getContent(base)).focus();
        case 'puppeteer':
            const { element } = await getContent(base).getNative();
            return element.focus();
        default:
            throw new Error('unsupported adapter');
    }
};
export const blurRichEditor = async (base) => {
    switch (base.type) {
        case 'react':
            return ReactBase(getContent(base)).blur();
        case 'puppeteer':
            const { element } = await getContent(base).getNative();
            return element.blur();
        default:
            throw new Error('unsupported adapter');
    }
};
export const isRichEditorFocused = async (base) => {
    return isElementFocused(getContent(base));
};
//# sourceMappingURL=DraftJS.js.map