"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const test_1 = require("@playwright/test");
const SM_8_8_1 = require("../../fixtures/SM-8.8");
const _setup_1 = require("../../test-setup.js");
const sleep_1 = require("../../utils/sleep");
const UtilitiesPage_1 = require("../../pages/SM-8.8/UtilitiesPage");
const UtilitiesPage_2 = require("../../pages/SM-8.8/UtilitiesPage");
if (process.env.IS_OPTIMIZE !== 'false') {
    SM_8_8_1.test.describe.configure({ mode: 'parallel' });
    SM_8_8_1.test.describe('Optimize User Flow Tests @tasklistV1', () => {
        SM_8_8_1.test.beforeEach(async ({ navigationPage }, testInfo) => {
            await navigationPage.goToModeler((testInfo.workerIndex + 1) * 1000);
        });
        SM_8_8_1.test.afterEach(async ({ page }, testInfo) => {
            await (0, _setup_1.captureScreenshot)(page, testInfo);
            await (0, _setup_1.captureFailureVideo)(page, testInfo);
        });
        (0, SM_8_8_1.test)('Process Import Flow', async ({ page, operateHomePage, modelerHomePage, navigationPage, modelerCreatePage, operateProcessesPage, operateProcessInstancePage, optimizeHomePage, optimizeDashboardPage, }) => {
            SM_8_8_1.test.slow();
            const processName = 'Optimize_Job_Worker_User_Task_Flow' +
                (await (0, _setup_1.generateRandomStringAsync)(3));
            await SM_8_8_1.test.step('Open Cross Component Test Project and Create a BPMN Diagram Template', async () => {
                await modelerHomePage.clickCrossComponentProjectFolder();
                await modelerHomePage.clickDiagramTypeDropdown();
                await modelerHomePage.clickBpmnTemplateOption();
            });
            await SM_8_8_1.test.step('Create BPMN Diagram with User Task and Start Process Instance', async () => {
                await modelerCreatePage.modelJobWorkerDiagram(processName);
                await modelerCreatePage.runProcessInstance();
                await (0, sleep_1.sleep)(60000);
            });
            await SM_8_8_1.test.step('View Process Instance in Operate and Assert Process has been successfully imported in Optimize', async () => {
                await navigationPage.goToOperate();
                await operateHomePage.clickProcessesTab();
                await operateProcessesPage.clickProcessInstanceLink(processName);
                await operateProcessInstancePage.activeIconAssertion();
                await navigationPage.goToOptimize();
                await optimizeHomePage.clickDashboardLink();
                await (0, sleep_1.sleep)(60000);
                await page.reload();
                await optimizeDashboardPage.clickFilterTable();
                await optimizeDashboardPage.fillFilterTable(processName);
                await optimizeDashboardPage.processAssertion(processName);
            });
        });
        (0, SM_8_8_1.test)('Job Worker User Task User Flow', async ({ page, modelerHomePage, navigationPage, modelerCreatePage, operateHomePage, operateProcessesPage, operateProcessInstancePage, optimizeHomePage, optimizeCollectionsPage, optimizeReportPage, }) => {
            SM_8_8_1.test.slow();
            const reportName = await (0, _setup_1.generateRandomStringAsync)(5);
            const processName = 'Optimize_Job_Worker_User_Task_Diagram' + reportName;
            await SM_8_8_1.test.step('Open Cross Component Test Project and Create a BPMN Diagram Template', async () => {
                await modelerHomePage.clickCrossComponentProjectFolder();
                await modelerHomePage.clickDiagramTypeDropdown();
                await modelerHomePage.clickBpmnTemplateOption();
            });
            await SM_8_8_1.test.step('Create BPMN Diagram with User Task and Start Process Instance', async () => {
                await modelerCreatePage.modelJobWorkerDiagram(processName);
                await modelerCreatePage.runProcessInstance();
                await (0, sleep_1.sleep)(60000);
            });
            await SM_8_8_1.test.step('View Process Instance in Operate, Create User Task Report in Optimize, Start Another Process Instance in Modeler & Assert the Report Updates', async () => {
                await navigationPage.goToOperate();
                await (0, sleep_1.sleep)(60000);
                await page.reload();
                await operateHomePage.clickProcessesTab();
                await operateProcessesPage.clickProcessInstanceLink(processName);
                await operateProcessInstancePage.activeIconAssertion();
                await navigationPage.goToOptimize();
                await page.reload();
                await optimizeHomePage.clickCollectionsLink();
                await optimizeCollectionsPage.clickCreateNewButton();
                await optimizeCollectionsPage.clickReportOption();
                await optimizeReportPage.clickProcessSelectionButton();
                await optimizeReportPage.clickUserTaskProcess(processName);
                await (0, test_1.expect)(optimizeReportPage.versionSelection).toBeVisible({
                    timeout: 30000,
                });
                await optimizeReportPage.clickVersionSelection();
                await optimizeReportPage.clickAlwaysDisplayLatestSelection();
                await optimizeReportPage.clickBlankReportButton();
                await optimizeReportPage.clickCreateReportLink();
                await optimizeReportPage.clickSelectDropdown();
                await optimizeReportPage.clickUserTaskOption();
                await optimizeReportPage.clickHeatMapButton();
                await (0, test_1.expect)(optimizeReportPage.tableOption).toBeVisible({
                    timeout: 30000,
                });
                await optimizeReportPage.clickTableOption();
                await optimizeReportPage.clickReportName();
                await optimizeReportPage.clearReportName();
                await optimizeReportPage.fillReportName(reportName);
                await optimizeReportPage.clickSaveButton();
                await optimizeHomePage.clickCollectionsLink();
                await (0, UtilitiesPage_2.assertPageTextWithRetry)(page, reportName, false, 30000);
                await optimizeCollectionsPage.clickMostRecentProcessReport(reportName);
                await (0, UtilitiesPage_1.assertLocatorVisibleWithRetry)(page, optimizeReportPage.oneUserTaskInstance, 'One user task count', 90000);
                await navigationPage.goToModeler();
                await modelerHomePage.clickCrossComponentProjectFolder();
                await modelerHomePage.clickProcessDiagram(processName);
                await modelerCreatePage.runProcessInstance();
                await (0, sleep_1.sleep)(10000);
                await navigationPage.goToOperate();
                await (0, sleep_1.sleep)(20000);
                await page.reload();
                await operateHomePage.clickProcessesTab();
                await operateProcessesPage.clickProcessInstanceLink(processName);
                await operateProcessInstancePage.activeIconAssertion();
                await navigationPage.goToOptimize();
                await (0, sleep_1.sleep)(60000);
                await optimizeHomePage.clickCollectionsLink();
                await (0, UtilitiesPage_2.assertPageTextWithRetry)(page, reportName, false, 30000);
                await optimizeCollectionsPage.clickMostRecentProcessReport(reportName);
                await (0, UtilitiesPage_1.assertLocatorVisibleWithRetry)(page, optimizeReportPage.twoUserTaskInstance, 'Two user tasks count', 90000);
                await (0, test_1.expect)(optimizeReportPage.oneUserTaskInstance).not.toBeVisible();
            });
        });
        (0, SM_8_8_1.test)('New Instances Updated Flow', async ({ page, modelerHomePage, navigationPage, modelerCreatePage, operateHomePage, operateProcessesPage, operateProcessInstancePage, optimizeHomePage, optimizeCollectionsPage, optimizeReportPage, }) => {
            SM_8_8_1.test.slow();
            const reportName = await (0, _setup_1.generateRandomStringAsync)(5);
            const processName = 'Optimize_Job_Worker_User_Task_Flow_Updated' +
                (await (0, _setup_1.generateRandomStringAsync)(3));
            await SM_8_8_1.test.step('Open Cross Component Test Project and Create a BPMN Diagram Template', async () => {
                await modelerHomePage.clickCrossComponentProjectFolder();
                await modelerHomePage.clickDiagramTypeDropdown();
                await modelerHomePage.clickBpmnTemplateOption();
            });
            await SM_8_8_1.test.step('Create BPMN Diagram with User Task and Start Process Instance', async () => {
                await modelerCreatePage.modelJobWorkerDiagram(processName);
                await modelerCreatePage.deployProcessInstance();
                await (0, sleep_1.sleep)(60000);
            });
            await SM_8_8_1.test.step('Create Process Instance Count Report in Optimize, Start A Process Instance in Modeler & Assert the Report Updates', async () => {
                await navigationPage.goToOptimize();
                await (0, sleep_1.sleep)(120000);
                await page.reload();
                await optimizeHomePage.clickCollectionsLink();
                await optimizeCollectionsPage.clickCreateNewButton();
                await optimizeCollectionsPage.clickReportOption();
                await optimizeReportPage.clickProcessSelectionButton();
                await optimizeReportPage.clickUserTaskProcess(processName);
                await (0, test_1.expect)(optimizeReportPage.versionSelection).toBeVisible({
                    timeout: 30000,
                });
                await optimizeReportPage.clickVersionSelection();
                await optimizeReportPage.clickAlwaysDisplayLatestSelection();
                await optimizeReportPage.clickBlankReportButton();
                await optimizeReportPage.clickCreateReportLink();
                await optimizeReportPage.clickSelectDropdown();
                await optimizeReportPage.clickUserTaskOption();
                await optimizeReportPage.clickHeatMapButton();
                await (0, test_1.expect)(optimizeReportPage.tableOption).toBeVisible({
                    timeout: 30000,
                });
                await optimizeReportPage.clickTableOption();
                await optimizeReportPage.clickReportName();
                await optimizeReportPage.clearReportName();
                await optimizeReportPage.fillReportName(reportName);
                await optimizeReportPage.clickSaveButton();
                await optimizeHomePage.clickCollectionsLink();
                await (0, UtilitiesPage_2.assertPageTextWithRetry)(page, reportName, false, 30000);
                await optimizeCollectionsPage.clickMostRecentProcessReport(reportName);
                await (0, UtilitiesPage_2.assertPageTextWithRetry)(page, 'Displaying data from 0 instances.', false, 30000);
                await navigationPage.goToModeler();
                await modelerHomePage.clickCrossComponentProjectFolder();
                await modelerHomePage.clickProcessDiagram(processName);
                await modelerCreatePage.runProcessInstance();
                await (0, sleep_1.sleep)(20000);
                await navigationPage.goToOperate();
                await operateHomePage.clickProcessesTab();
                await operateProcessesPage.clickProcessInstanceLink(processName);
                await (0, test_1.expect)(operateProcessInstancePage.activeIcon).toBeVisible({
                    timeout: 1200000,
                });
                await navigationPage.goToOptimize();
                await (0, sleep_1.sleep)(30000);
                await page.reload();
                await optimizeHomePage.clickCollectionsLink();
                await (0, UtilitiesPage_2.assertPageTextWithRetry)(page, reportName, false, 30000);
                await optimizeCollectionsPage.clickMostRecentProcessReport(reportName);
                await (0, UtilitiesPage_2.assertPageTextWithRetry)(page, 'Displaying data from 1 instance.', false, 30000);
            });
        });
    });
}
