"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const test_1 = require("@playwright/test");
const _8_9_1 = require("../../fixtures/8.9");
const _setup_1 = require("../../test-setup.js");
const AppsPage_1 = require("../../pages/8.9/AppsPage");
const OptimizeCollectionsPage_1 = require("../../pages/8.9/OptimizeCollectionsPage");
const OperateProcessInstancePage_1 = require("../../pages/8.9/OperateProcessInstancePage");
const OptimizeHomePage_1 = require("../../pages/8.9/OptimizeHomePage");
const OptimizeDashboardPage_1 = require("../../pages/8.9/OptimizeDashboardPage");
const sleep_1 = require("../../utils/sleep");
const UtilitiesPage_1 = require("../../pages/8.9/UtilitiesPage");
const users_1 = require("../../utils/users");
const testUser = (0, users_1.getTestUser)('twentyThirdUser');
_8_9_1.test.describe.configure({ mode: 'parallel' });
_8_9_1.test.describe('Optimize User Flow Tests', () => {
    const clusterName = 'Test Cluster';
    _8_9_1.test.beforeEach(async ({ page, loginPage }, testInfo) => {
        await (0, UtilitiesPage_1.loginWithRetry)(page, loginPage, testUser, (testInfo.workerIndex + 1) * 1000);
    });
    _8_9_1.test.afterEach(async ({ page }, testInfo) => {
        await (0, _setup_1.captureScreenshot)(page, testInfo);
        await (0, _setup_1.captureFailureVideo)(page, testInfo);
    });
    (0, _8_9_1.test)('Job Worker User Task User Flow @tasklistV1', async ({ page, homePage, modelerHomePage, appsPage, modelerCreatePage, operateHomePage, operateProcessesPage, operateProcessInstancePage, optimizeCollectionsPage, optimizeReportPage, optimizeHomePage, }) => {
        _8_9_1.test.slow();
        const reportName = await (0, _setup_1.generateRandomStringAsync)(5);
        const processName = 'Optimize Job Worker User Task Diagram' + reportName;
        await _8_9_1.test.step('Navigate to Web Modeler', async () => {
            await (0, test_1.expect)(homePage.camundaComponentsButton).toBeVisible({
                timeout: 120000,
            });
            await appsPage.clickCamundaApps();
            await appsPage.clickModeler();
            await (0, test_1.expect)(modelerHomePage.modelerPageBanner).toBeVisible({
                timeout: 180000,
            });
        });
        await _8_9_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 _8_9_1.test.step('Create BPMN Diagram with User Task and Start Process Instance', async () => {
            await modelerCreatePage.modelJobWorkerDiagram(processName);
            await modelerCreatePage.runProcessInstance(clusterName);
            await (0, test_1.expect)(modelerCreatePage.viewProcessInstanceLink).toBeVisible({
                timeout: 120000,
            });
        });
        await _8_9_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 appsPage.clickCamundaApps();
            await appsPage.clickOperate(clusterName);
            await (0, test_1.expect)(operateHomePage.operateBanner).toBeVisible({
                timeout: 60000,
            });
            await operateHomePage.clickProcessesTab();
            await operateProcessesPage.clickProcessInstanceLink(processName);
            await (0, test_1.expect)(operateProcessInstancePage.activeIcon).toBeVisible({
                timeout: 120000,
            });
            await appsPage.clickCamundaApps();
            await appsPage.clickOptimize(clusterName);
            await (0, sleep_1.sleep)(120000);
            await page.reload();
            await optimizeCollectionsPage.clickCreateNewButtonWithRetry();
            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: 90000,
            });
            await optimizeReportPage.clickTableOption();
            await optimizeReportPage.clickReportName();
            await optimizeReportPage.clearReportName();
            await optimizeReportPage.fillReportName(reportName);
            await optimizeReportPage.clickSaveButton();
            await optimizeHomePage.clickCollectionsLink();
            await (0, test_1.expect)(page.getByText(reportName)).toBeVisible({
                timeout: 60000,
            });
            await optimizeCollectionsPage.clickMostRecentProcessReport(reportName);
            await (0, UtilitiesPage_1.assertLocatorVisibleWithRetry)(page, optimizeReportPage.oneUserTaskInstance, 'One user task count', 30000);
            await appsPage.clickCamundaApps();
            await appsPage.clickModeler();
            await modelerHomePage.clickCrossComponentProjectFolder();
            await modelerHomePage.clickProcessDiagram(processName);
            await modelerCreatePage.runProcessInstance(clusterName);
            await (0, test_1.expect)(modelerCreatePage.viewProcessInstanceLink).toBeVisible({
                timeout: 120000,
            });
            await appsPage.clickCamundaApps();
            await appsPage.clickOperate(clusterName);
            await (0, test_1.expect)(operateHomePage.operateBanner).toBeVisible({
                timeout: 60000,
            });
            await operateHomePage.clickProcessesTab();
            await operateProcessesPage.clickProcessInstanceLink(processName);
            await (0, test_1.expect)(operateProcessInstancePage.diagramSpinner).not.toBeVisible({
                timeout: 60000,
            });
            await (0, test_1.expect)(operateProcessInstancePage.activeIcon).toBeVisible({
                timeout: 60000,
            });
            await appsPage.clickCamundaApps();
            await appsPage.clickOptimize(clusterName);
            await optimizeHomePage.clickCollectionsLink();
            await (0, test_1.expect)(page.getByText(reportName)).toBeVisible();
            await optimizeCollectionsPage.clickMostRecentProcessReport(reportName);
            await (0, UtilitiesPage_1.assertLocatorVisibleWithRetry)(page, optimizeReportPage.twoUserTaskInstance, 'Two user tasks count', 30000);
            await (0, test_1.expect)(optimizeReportPage.oneUserTaskInstance).not.toBeVisible();
        });
    });
    (0, _8_9_1.test)('New Instances Updated Flow @tasklistV1', async ({ page, homePage, modelerHomePage, appsPage, modelerCreatePage, optimizeCollectionsPage, optimizeReportPage, optimizeHomePage, }) => {
        _8_9_1.test.slow();
        const reportName = await (0, _setup_1.generateRandomStringAsync)(5);
        const processName = 'Optimize Job Worker New Instances Updated Flow' + reportName;
        await _8_9_1.test.step('Navigate to Web Modeler', async () => {
            await (0, test_1.expect)(homePage.camundaComponentsButton).toBeVisible({
                timeout: 120000,
            });
            await appsPage.clickCamundaApps();
            await appsPage.clickModeler();
            await (0, test_1.expect)(modelerHomePage.modelerPageBanner).toBeVisible({
                timeout: 180000,
            });
        });
        await _8_9_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 _8_9_1.test.step('Create BPMN Diagram with User Task and Deploy Process', async () => {
            await modelerCreatePage.modelJobWorkerDiagram(processName);
            await modelerCreatePage.deployDiagram(clusterName);
        });
        await _8_9_1.test.step('Create Process Instance Count Report in Optimize, Start A Process Instance in Modeler & Assert the Report Updates', async () => {
            await appsPage.clickCamundaApps();
            await appsPage.clickOptimize(clusterName);
            await (0, sleep_1.sleep)(120000);
            await page.reload();
            await optimizeCollectionsPage.clickCreateNewButtonWithRetry();
            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, test_1.expect)(page.getByText(reportName)).toBeVisible({
                timeout: 20000,
            });
            await optimizeCollectionsPage.clickMostRecentProcessReport(reportName);
            await page.reload();
            await (0, test_1.expect)(page.getByText('Displaying data from 0 instances.')).toBeVisible({ timeout: 90000 });
            await appsPage.clickCamundaApps();
            await appsPage.clickModeler();
            await modelerHomePage.clickCrossComponentProjectFolder();
            await modelerHomePage.clickProcessDiagram(processName);
            await modelerCreatePage.runProcessInstance(clusterName);
            await modelerCreatePage.clickViewProcessInstanceLink();
            const newOperateTab = await page.waitForEvent('popup');
            const newOperateTabAppsPage = new AppsPage_1.AppsPage(newOperateTab);
            const newOperateTabOperateProcessInstancePage = new OperateProcessInstancePage_1.OperateProcessInstancePage(newOperateTab);
            await newOperateTabOperateProcessInstancePage.closePopOverIfVisible();
            await (0, test_1.expect)(newOperateTabOperateProcessInstancePage.diagramSpinner).not.toBeVisible({
                timeout: 60000,
            });
            await (0, test_1.expect)(newOperateTabOperateProcessInstancePage.activeIcon).toBeVisible({ timeout: 60000 });
            await newOperateTabAppsPage.clickCamundaApps();
            await newOperateTabAppsPage.clickOptimize(clusterName);
            const newOptimizeTabOptimizeCollectionsPage = new OptimizeCollectionsPage_1.OptimizeCollectionsPage(newOperateTab);
            const newOptimizeHomePage = new OptimizeHomePage_1.OptimizeHomePage(newOperateTab);
            await (0, sleep_1.sleep)(30000);
            await newOperateTab.reload();
            await newOptimizeHomePage.clickCollectionsLink();
            await (0, test_1.expect)(newOperateTab.getByText(reportName)).toBeVisible();
            await newOptimizeTabOptimizeCollectionsPage.clickMostRecentProcessReport(reportName);
            await (0, test_1.expect)(newOperateTab.getByText('Displaying data from 1 instance.')).toBeVisible({ timeout: 90000 });
        });
    });
    (0, _8_9_1.test)('Process Import Flow @tasklistV1', async ({ page, homePage, modelerHomePage, appsPage, modelerCreatePage, }) => {
        _8_9_1.test.slow();
        const processName = 'Process Import Flow' + (await (0, _setup_1.generateRandomStringAsync)(6));
        await _8_9_1.test.step('Navigate to Web Modeler', async () => {
            await (0, test_1.expect)(homePage.camundaComponentsButton).toBeVisible({
                timeout: 120000,
            });
            await appsPage.clickCamundaApps();
            await appsPage.clickModeler();
            await (0, test_1.expect)(modelerHomePage.modelerPageBanner).toBeVisible({
                timeout: 180000,
            });
        });
        await _8_9_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 _8_9_1.test.step('Create BPMN Diagram with User Task and Deploy Process', async () => {
            await modelerCreatePage.modelJobWorkerDiagram(processName);
            await modelerCreatePage.runProcessInstance(clusterName);
        });
        await _8_9_1.test.step('View Process Instance in Operate and Assert Process has been successfully imported in Optimize', async () => {
            await (0, test_1.expect)(modelerCreatePage.viewProcessInstanceLink).toBeVisible({
                timeout: 120000,
            });
            await modelerCreatePage.clickViewProcessInstanceLink();
            const operateTab = await page.waitForEvent('popup');
            const operateTabAppsPage = new AppsPage_1.AppsPage(operateTab);
            const operateTabOperateProcessInstancePage = new OperateProcessInstancePage_1.OperateProcessInstancePage(operateTab);
            const operateTabOptimizeDashboardPage = new OptimizeDashboardPage_1.OptimizeDashboardPage(operateTab);
            await operateTabOperateProcessInstancePage.closePopOverIfVisible();
            await (0, UtilitiesPage_1.assertLocatorVisibleWithRetry)(operateTab, operateTabOperateProcessInstancePage.activeIcon, 'active icon');
            await (0, test_1.expect)(operateTabOperateProcessInstancePage.activeIcon).toBeVisible({ timeout: 120000 });
            await operateTabAppsPage.clickCamundaApps();
            await operateTabAppsPage.clickOptimize(clusterName);
            const optimizeTabOptimizeHomePage = new OptimizeHomePage_1.OptimizeHomePage(operateTab);
            await optimizeTabOptimizeHomePage.clickDashboardLink();
            await (0, sleep_1.sleep)(90000);
            await operateTabOptimizeDashboardPage.processLinkAssertion(processName, 6);
            await operateTabOptimizeDashboardPage.processOwnerNameAssertion(processName, testUser.username);
        });
    });
});
