"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.assertReportWithRefreshes = exports.createReportForProcess = void 0;
const test_1 = require("@playwright/test");
const UtlitiesPage_1 = require("../SM-8.6/UtlitiesPage");
const UtlitiesPage_2 = require("../SM-8.6/UtlitiesPage");
const createReportForProcess = async (optimizeCollectionsPage, optimizeReportPage, processName) => {
    let retries = 1000; // big number as this can struggle when many processes are running at once
    while (retries > 0) {
        try {
            await optimizeCollectionsPage.clickCreateNewButton();
            await optimizeCollectionsPage.clickReportOption();
            await optimizeReportPage.clickProcessSelectionButton();
            await optimizeReportPage.waitUntilUserTaskProcessIsVisible(processName);
            break;
        }
        catch (error) {
            await optimizeReportPage.clickCancelButton();
        }
        retries--;
        (0, test_1.expect)(retries).toBeGreaterThan(0);
    }
};
exports.createReportForProcess = createReportForProcess;
const assertReportWithRefreshes = async (page, optimizeHomePage, optimizeCollectionsPage, optimizeReportPage, reportName, locator, text) => {
    let retries = 1000; // big number as this can struggle when many processes are running at once
    while (retries > 0) {
        try {
            await optimizeHomePage.clickCollectionsLink();
            await (0, UtlitiesPage_1.assertPageTextWithRetry)(page, reportName, false);
            await optimizeCollectionsPage.clickMostRecentProcessReport(reportName);
            await (0, UtlitiesPage_2.assertLocatorVisibleWithRetry)(page, locator, text, 0);
            break;
        }
        catch (error) {
            // nothing to do. Just loop back to the collections
        }
        retries--;
        (0, test_1.expect)(retries).toBeGreaterThan(0);
    }
};
exports.assertReportWithRefreshes = assertReportWithRefreshes;
