UNPKG

@applitools/eyes-playwright

Version:
69 lines (68 loc) 2.84 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.EyesResultsBatchLinkUI = void 0; const urlManager_js_1 = require("../data/urlManager.js"); const log_js_1 = __importDefault(require("../core/log.js")); const logger = (0, log_js_1.default)(); class EyesResultsBatchLinkUI { constructor() { this._linkCreated = false; } createLinkToBatch(testResults) { if (!(0, urlManager_js_1.isListMode)()) { this.removeLinkToBatch(); return; } const existingLink = document.getElementsByClassName('eyes-batch-link')[0]; if (existingLink) { return; } const firstChip = document.getElementsByClassName('chip')[0]; if (!firstChip) { logger.warn('No chip element found, cannot create link'); return; } // Collect all distinct batch URLs const batchesMap = new Map(); Object.values(testResults.eyesTestResult).forEach(testResult => { testResult === null || testResult === void 0 ? void 0 : testResult.eyesResults.forEach(result => { var _a; if ((_a = result.appUrls) === null || _a === void 0 ? void 0 : _a.batch) { batchesMap.set(result.batchName, result.appUrls.batch); } }); }); if (batchesMap.size === 0) { logger.warn('No Eyes results with batch URL found'); return; } const linkContainer = document.createElement('div'); linkContainer.classList.add('eyes-batch-link'); // Create a link for each distinct batch Array.from(batchesMap).forEach((batchEntry, index) => { const link = document.createElement('a'); const batchName = batchEntry[0] !== '' ? ` - ${batchEntry[0]}` : batchesMap.size > 1 ? ` (Batch ${index + 1})` : ''; link.target = '_blank'; link.href = batchEntry[1]; link.textContent = batchesMap.size > 1 ? `Results in Eyes Dashboard${batchName}` : `Results in Eyes Dashboard${batchName}`; linkContainer.appendChild(link); }); firstChip.parentNode.insertBefore(linkContainer, firstChip); this._linkCreated = true; } removeLinkToBatch() { const link = document.getElementsByClassName('eyes-batch-link')[0]; if (link) { link.remove(); this._linkCreated = false; } } isLinkDisplayed() { return this._linkCreated && document.getElementsByClassName('eyes-batch-link')[0] !== undefined; } } exports.EyesResultsBatchLinkUI = EyesResultsBatchLinkUI;