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 3.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.O3rSliderElement = void 0; var tslib_1 = require("tslib"); var platform_browser_1 = require("@angular/platform-browser"); var element_1 = require("../element"); /** * Implementation dedicated to angular / TestBed. */ var O3rSliderElement = /** @class */ (function (_super) { tslib_1.__extends(O3rSliderElement, _super); function O3rSliderElement(sourceElement, trackSelector, thumbSelector) { var _this = _super.call(this, sourceElement) || this; _this.trackSelector = trackSelector; _this.thumbSelector = thumbSelector; return _this; } O3rSliderElement.prototype.getInputElement = function () { try { var subElement = this.sourceElement.query(platform_browser_1.By.css('input[type="range"]')); return subElement || this.sourceElement; } catch (_a) { return this.sourceElement; } }; O3rSliderElement.prototype.getTrackElement = function () { if (!this.trackSelector) { return this.sourceElement; } try { var subElement = this.sourceElement.query(platform_browser_1.By.css(this.trackSelector)); return subElement || this.sourceElement; } catch (_a) { return this.sourceElement; } }; O3rSliderElement.prototype.getThumbElement = function () { if (!this.thumbSelector) { return this.sourceElement; } try { var subElement = this.sourceElement.query(platform_browser_1.By.css(this.thumbSelector)); return subElement || this.sourceElement; } catch (_a) { return this.sourceElement; } }; /** * Set the value in an input. * inspired from https://github.com/angular/components/blob/main/src/material/slider/slider.spec.ts#L1838 * @param value */ O3rSliderElement.prototype.setValue = function (value) { var trackNativeElement = this.getTrackElement().nativeElement; var thumbNativeElement = this.getThumbElement().nativeElement; var inputNativeElement = this.getInputElement().nativeElement; var thumbBoundingBox = thumbNativeElement.getBoundingClientRect(); var startX = thumbBoundingBox.x + thumbBoundingBox.width / 2; var startY = thumbBoundingBox.y + thumbBoundingBox.height / 2; var max = +(inputNativeElement.max === '' ? '100' : inputNativeElement.max); var min = +(inputNativeElement.min === '' ? '0' : inputNativeElement.min); var sanitizeValue = Math.max(min, Math.min(+value, max)); var percent = (sanitizeValue - min) / (max - min); var _a = trackNativeElement.getBoundingClientRect(), top = _a.top, left = _a.left, width = _a.width, height = _a.height; var endX = width * percent + left; var endY = top + height / 2; thumbNativeElement.dispatchEvent(new MouseEvent('mousedown', { clientX: startX, clientY: startY })); trackNativeElement.focus(); trackNativeElement.dispatchEvent(new MouseEvent('mousemove', { clientX: endX, clientY: endY })); inputNativeElement.value = "".concat(sanitizeValue); inputNativeElement.dispatchEvent(new Event('input')); trackNativeElement.dispatchEvent(new MouseEvent('mouseup', { clientX: endX, clientY: endY })); inputNativeElement.dispatchEvent(new Event('change')); return Promise.resolve(); }; /** @inheritdoc */ O3rSliderElement.prototype.getValue = function () { return (new element_1.O3rElement(this.getInputElement())).getValue(); }; return O3rSliderElement; }(element_1.O3rElement)); exports.O3rSliderElement = O3rSliderElement; //# sourceMappingURL=slider-element.js.map