UNPKG

@o3r/testing

Version:

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

86 lines 4.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.O3rElement = void 0; /** * Implementation dedicated to angular / TestBed. */ var O3rElement = /** @class */ (function () { function O3rElement(sourceElement) { this.sourceElement = sourceElement instanceof O3rElement ? sourceElement.sourceElement : sourceElement; } Object.defineProperty(O3rElement.prototype, "text", { /** * 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: function () { var element = this.sourceElement.nativeElement; return element ? (element.innerText === undefined ? element.textContent : element.innerText) : undefined; }, enumerable: false, configurable: true }); /** @inheritdoc */ O3rElement.prototype.getText = function () { return Promise.resolve(this.text); }; /** @inheritdoc */ O3rElement.prototype.getPlainText = function () { var innerText = this.text; return Promise.resolve(innerText ? innerText.replace(/\r\n|\r|\n/g, ' ').replace(/\s\s+/g, ' ').trim() : undefined); }; /** @inheritdoc */ O3rElement.prototype.getInnerHTML = function () { return Promise.resolve(this.sourceElement.nativeElement && this.sourceElement.nativeElement.innerHTML); }; /** @inheritdoc */ O3rElement.prototype.click = function () { this.sourceElement.nativeElement.click(); return Promise.resolve(); }; /** @inheritdoc */ O3rElement.prototype.isVisible = function () { return Promise.resolve(this.sourceElement.nativeElement.style.display !== 'none' && this.sourceElement.nativeElement.style.visibility !== 'hidden'); }; /** @inheritdoc */ O3rElement.prototype.getAttribute = function (attributeName) { return Promise.resolve(this.sourceElement.nativeElement && this.sourceElement.nativeElement.getAttribute(attributeName)); }; /** @inheritdoc */ O3rElement.prototype.mouseOver = function () { this.sourceElement.nativeElement.mouseOver(); this.sourceElement.nativeElement.dispatchEvent(new Event('mouseover')); return Promise.resolve(); }; /** @inheritdoc */ O3rElement.prototype.getValue = function () { return Promise.resolve(this.sourceElement.nativeElement && this.sourceElement.nativeElement.value); }; /** @inheritdoc */ O3rElement.prototype.setValue = function (input) { var _this = this; this.sourceElement.triggerEventHandler('focus', { target: this.sourceElement.nativeElement, preventDefault: function () { }, stopPropagation: function () { } }); input.split('').forEach(function (key) { _this.sourceElement.triggerEventHandler('keydown', { target: _this.sourceElement.nativeElement, key: key, preventDefault: function () { }, stopPropagation: function () { } }); _this.sourceElement.triggerEventHandler('keypress', { target: _this.sourceElement.nativeElement, key: key, preventDefault: function () { }, stopPropagation: function () { } }); _this.sourceElement.triggerEventHandler('keyup', { target: _this.sourceElement.nativeElement, key: key, preventDefault: function () { }, stopPropagation: function () { } }); }); this.sourceElement.nativeElement.value = input; this.sourceElement.triggerEventHandler('input', { target: this.sourceElement.nativeElement, preventDefault: function () { }, stopPropagation: function () { } }); this.sourceElement.triggerEventHandler('blur', { target: this.sourceElement.nativeElement, preventDefault: function () { }, stopPropagation: function () { } }); return Promise.resolve(); }; /** @inheritdoc */ O3rElement.prototype.clearValue = function () { this.sourceElement.triggerEventHandler('focus', { target: this.sourceElement.nativeElement, preventDefault: function () { }, stopPropagation: function () { } }); this.sourceElement.nativeElement.value = ''; this.sourceElement.triggerEventHandler('input', { target: this.sourceElement.nativeElement, preventDefault: function () { }, stopPropagation: function () { } }); this.sourceElement.triggerEventHandler('blur', { target: this.sourceElement.nativeElement, preventDefault: function () { }, stopPropagation: function () { } }); return Promise.resolve(); }; return O3rElement; }()); exports.O3rElement = O3rElement; //# sourceMappingURL=element.js.map