UNPKG

@o3r/testing

Version:

The module provides testing (e2e, unit test) utilities to help you build your own E2E pipeline integrating visual testing.

80 lines 3.95 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.O3rElement = void 0; /** * Implementation dedicated to angular / TestBed. */ class O3rElement { constructor(sourceElement) { this.sourceElement = sourceElement instanceof O3rElement ? sourceElement.sourceElement : sourceElement; } /** * Returns the text content of the DOM node. * Prioritizes .innerText, but fallbacks on .textContent in case the former is undefined in order * to support JSDOM. * @protected */ get text() { const element = this.sourceElement.nativeElement; return element ? (element.innerText === undefined ? element.textContent : element.innerText) : undefined; } /** @inheritdoc */ getText() { return Promise.resolve(this.text); } /** @inheritdoc */ getPlainText() { const innerText = this.text; return Promise.resolve(innerText ? innerText.replace(/\r\n|\r|\n/g, ' ').replace(/\s\s+/g, ' ').trim() : undefined); } /** @inheritdoc */ getInnerHTML() { return Promise.resolve(this.sourceElement.nativeElement && this.sourceElement.nativeElement.innerHTML); } /** @inheritdoc */ click() { this.sourceElement.nativeElement.click(); return Promise.resolve(); } /** @inheritdoc */ isVisible() { return Promise.resolve(this.sourceElement.nativeElement.style.display !== 'none' && this.sourceElement.nativeElement.style.visibility !== 'hidden'); } /** @inheritdoc */ getAttribute(attributeName) { return Promise.resolve(this.sourceElement.nativeElement && this.sourceElement.nativeElement.getAttribute(attributeName)); } /** @inheritdoc */ mouseOver() { this.sourceElement.nativeElement.mouseOver(); this.sourceElement.nativeElement.dispatchEvent(new Event('mouseover')); return Promise.resolve(); } /** @inheritdoc */ getValue() { return Promise.resolve(this.sourceElement.nativeElement && this.sourceElement.nativeElement.value); } /** @inheritdoc */ setValue(input) { this.sourceElement.triggerEventHandler('focus', { target: this.sourceElement.nativeElement, preventDefault: () => { }, stopPropagation: () => { } }); input.split('').forEach((key) => { this.sourceElement.triggerEventHandler('keydown', { target: this.sourceElement.nativeElement, key, preventDefault: () => { }, stopPropagation: () => { } }); this.sourceElement.triggerEventHandler('keypress', { target: this.sourceElement.nativeElement, key, preventDefault: () => { }, stopPropagation: () => { } }); this.sourceElement.triggerEventHandler('keyup', { target: this.sourceElement.nativeElement, key, preventDefault: () => { }, stopPropagation: () => { } }); }); this.sourceElement.nativeElement.value = input; this.sourceElement.triggerEventHandler('input', { target: this.sourceElement.nativeElement, preventDefault: () => { }, stopPropagation: () => { } }); this.sourceElement.triggerEventHandler('blur', { target: this.sourceElement.nativeElement, preventDefault: () => { }, stopPropagation: () => { } }); return Promise.resolve(); } /** @inheritdoc */ clearValue() { this.sourceElement.triggerEventHandler('focus', { target: this.sourceElement.nativeElement, preventDefault: () => { }, stopPropagation: () => { } }); this.sourceElement.nativeElement.value = ''; this.sourceElement.triggerEventHandler('input', { target: this.sourceElement.nativeElement, preventDefault: () => { }, stopPropagation: () => { } }); this.sourceElement.triggerEventHandler('blur', { target: this.sourceElement.nativeElement, preventDefault: () => { }, stopPropagation: () => { } }); return Promise.resolve(); } } exports.O3rElement = O3rElement; //# sourceMappingURL=element.js.map