UNPKG

askui

Version:

Reliable, automated end-to-end-testing that depends on what is shown on your screen instead of the technology you are running on

60 lines (59 loc) 3.14 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.CustomElement = void 0; const yup_1 = require("yup"); const base_64_image_1 = require("../../utils/base_64_image/base-64-image"); class CustomElement { constructor(customImage, name, threshold, stopThreshold, rotationDegreePerStep, imageCompareFormat, mask) { this.customImage = customImage; this.name = name; this.threshold = threshold; this.stopThreshold = stopThreshold; this.rotationDegreePerStep = rotationDegreePerStep; this.imageCompareFormat = imageCompareFormat; this.mask = mask; } static fromJsonListWithImagePathOrImage() { return __awaiter(this, arguments, void 0, function* (ceJson = []) { return Promise.all(ceJson.map((customElement) => CustomElement.fromJsonWithImagePathOrImage(customElement))); }); } static fromJsonWithImagePathOrImage(ceJson) { return __awaiter(this, void 0, void 0, function* () { const customImage = (yield base_64_image_1.Base64Image.fromPathOrString(ceJson.customImage)).toString(); const customElement = CustomElement.fromJson(Object.assign(Object.assign({}, ceJson), { customImage })); customElement.validate(); return customElement; }); } static fromJson(ceJson) { return new CustomElement(ceJson.customImage, ceJson.name, ceJson.threshold, ceJson.stopThreshold, ceJson.rotationDegreePerStep, ceJson.imageCompareFormat, ceJson.mask); } validate() { try { CustomElement.schema.validateSync(this, { abortEarly: false, strict: true }); } catch (e) { // ValidationError throw new yup_1.ValidationError(e.errors.join(', ')); } } asString() { return `name:${this.name}-customImage:${this.customImage}-threshold:${this.threshold}-stopThreshold:${this.stopThreshold}-rotationDegreePerStep:${this.rotationDegreePerStep}-imageCompareFormat:${this.imageCompareFormat}-mask:${this.mask}`; } } exports.CustomElement = CustomElement; CustomElement.schema = (0, yup_1.object)({ mask: (0, yup_1.array)().optional().min(3, 'mask must contain at least 3 points'), rotationDegreePerStep: (0, yup_1.number)().optional().min(0).lessThan(360), stopThreshold: (0, yup_1.number)().optional().min(0).max(1), threshold: (0, yup_1.number)().optional().min(0).max(1), });