"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const test_1 = require("@playwright/test");
const _8_6_1 = require("../../fixtures/8.6");
const _setup_1 = require("../../test-setup.js");
const TaskPanelPage_1 = require("../../pages/8.6/TaskPanelPage");
const TaskDetailsPage_1 = require("../../pages/8.6/TaskDetailsPage");
const OperateHomePage_1 = require("../../pages/8.6/OperateHomePage");
const AppsPage_1 = require("../../pages/8.6/AppsPage");
const OperateProcessesPage_1 = require("../../pages/8.6/OperateProcessesPage");
const OperateProcessInstancePage_1 = require("../../pages/8.6/OperateProcessInstancePage");
const OptimizeHomePage_1 = require("../../pages/8.6/OptimizeHomePage");
const OptimizeCollectionsPage_1 = require("../../pages/8.6/OptimizeCollectionsPage");
const OptimizeReportPage_1 = require("../../pages/8.6/OptimizeReportPage");
const UtilitiesPage_1 = require("../../pages/8.6/UtilitiesPage");
const expectLocatorWithRetry_1 = require("../../utils/assertionHelpers/expectLocatorWithRetry");
const users_1 = require("../../utils/users");
const testUser = (0, users_1.getTestUser)('thirteenthUser');
_8_6_1.test.describe.configure({ mode: 'parallel' });
_8_6_1.test.describe('Smoke Tests', () => {
    const clusterName = 'Test Cluster';
    // Use fixed names for upgrade testing validation, random names for regular testing
    const useFixedNames = process.env.UPGRADE_BASELINE === 'true';
    _8_6_1.test.beforeEach(async ({ page, loginPage }, testInfo) => {
        await (0, UtilitiesPage_1.loginWithRetry)(page, loginPage, testUser, (testInfo.workerIndex + 1) * 1000);
    });
    _8_6_1.test.afterEach(async ({ page }, testInfo) => {
        await (0, _setup_1.captureScreenshot)(page, testInfo);
        await (0, _setup_1.captureFailureVideo)(page, testInfo);
    });
    (0, _8_6_1.test)('Most Common Flow User Flow With All Apps', async ({ page, homePage, modelerHomePage, appsPage, modelerCreatePage, formJsPage, }) => {
        _8_6_1.test.slow();
        const randomString = useFixedNames
            ? 'UpgradeTest'
            : await (0, _setup_1.generateRandomStringAsync)(3);
        const formName = 'New form' + randomString;
        const processName = 'Zeebe_User_Task_Process' + randomString;
        const userTaskName = 'zeebeUserTaskWithForm' + randomString;
        const reportName = useFixedNames
            ? 'UpgradeTestReport'
            : await (0, _setup_1.generateRandomStringAsync)(5);
        await _8_6_1.test.step('Navigate to Web Modeler', async () => {
            await (0, test_1.expect)(homePage.camundaComponentsButton).toBeVisible({
                timeout: 30000,
            });
            await appsPage.clickCamundaApps();
            await appsPage.clickModeler();
            await (0, test_1.expect)(modelerHomePage.modelerPageBanner).toBeVisible({
                timeout: 60000,
            });
        });
        await _8_6_1.test.step('Create Form To Be Linked For Zeebe User Task', async () => {
            await modelerHomePage.clickCrossComponentProjectFolder();
            await modelerHomePage.createForm(formName);
            await formJsPage.deployForm(clusterName);
        });
        await _8_6_1.test.step('Add A BPMN Template To The Project', async () => {
            await modelerHomePage.clickProjectBreadcrumb();
            await modelerHomePage.clickDiagramTypeDropdown();
            await modelerHomePage.clickBpmnTemplateOption();
        });
        await _8_6_1.test.step('Create BPMN Diagram with Two Zeebe User Tasks and Start Process Instance', async () => {
            await (0, test_1.expect)(modelerCreatePage.generalPanel).toBeVisible({
                timeout: 60000,
            });
            await modelerCreatePage.enterDiagramName(processName);
            await modelerCreatePage.assertDiagramNameSet(processName);
            await modelerCreatePage.addParallelUserTasks(2, userTaskName);
            await modelerCreatePage.clickAppendElementButton();
            await modelerCreatePage.clickAppendEndEventButton('parallelGateway');
            await modelerCreatePage.clickUserTask(`${userTaskName}2`);
            await modelerCreatePage.clickEmbedFormButton();
            await modelerCreatePage.clickForm(formName);
            await modelerCreatePage.clickEmbedButton();
            await modelerCreatePage.assertFormEmbedded();
            await modelerCreatePage.runProcessInstance(clusterName);
        });
        await _8_6_1.test.step('View Process Instance in Operate, complete User Task in Tasklist & assert process complete in Operate and Assert Process has been successfully imported in Optimize', async () => {
            await (0, test_1.expect)(modelerCreatePage.viewProcessInstanceLink).toBeVisible({
                timeout: 60000,
            });
            await modelerCreatePage.clickViewProcessInstanceLink();
            const operateTab = await page.waitForEvent('popup', { timeout: 30000 });
            const operateTabHomePage = new OperateHomePage_1.OperateHomePage(operateTab);
            const operateTabProcessesPage = new OperateProcessesPage_1.OperateProcessesPage(operateTab);
            const operateTabProcessInstancePage = new OperateProcessInstancePage_1.OperateProcessInstancePage(operateTab);
            const operateTabAppsPage = new AppsPage_1.AppsPage(operateTab);
            const operateTabTaskPanelPage = new TaskPanelPage_1.TaskPanelPage(operateTab);
            const operateTabTaskDetailsPage = new TaskDetailsPage_1.TaskDetailsPage(operateTab);
            await (0, test_1.expect)(operateTabProcessInstancePage.activeIcon).toBeVisible({
                timeout: 180000,
            });
            await operateTabAppsPage.clickCamundaApps();
            await operateTabAppsPage.clickTasklist(clusterName);
            await (0, UtilitiesPage_1.completeTaskWithRetry)(operateTabTaskPanelPage, operateTabTaskDetailsPage, `${userTaskName}1`, 'Medium');
            await (0, UtilitiesPage_1.completeTaskWithRetry)(operateTabTaskPanelPage, operateTabTaskDetailsPage, `${userTaskName}2`, 'Medium');
            await operateTabTaskPanelPage.filterBy('Completed');
            await operateTabTaskPanelPage.openTask(`${userTaskName}1`);
            await (0, test_1.expect)(operateTabTaskDetailsPage.detailsInfo.getByText(`${userTaskName}1`)).toBeVisible({ timeout: 30000 });
            await operateTabTaskPanelPage.openTask(`${userTaskName}2`);
            await (0, test_1.expect)(operateTabTaskDetailsPage.detailsInfo.getByText(`${userTaskName}2`)).toBeVisible({ timeout: 30000 });
            await operateTabAppsPage.clickCamundaApps();
            await operateTabAppsPage.clickOperate(clusterName);
            await operateTabHomePage.clickProcessesTab();
            await (0, test_1.expect)(operateTabProcessesPage.processCompletedCheckbox).toBeVisible({ timeout: 15000 });
            await operateTab.reload();
            await operateTabProcessesPage.clickProcessCompletedCheckbox();
            await operateTabProcessesPage.clickProcessInstanceLink(processName);
            await (0, UtilitiesPage_1.assertLocatorVisibleWithRetry)(operateTabProcessInstancePage, operateTabProcessInstancePage.completedIcon, 'completed icon in Operate', 60000);
            await operateTabAppsPage.clickCamundaApps();
            await operateTabAppsPage.clickOptimize(clusterName);
            const optimizeTabOptimizeCollectionsPage = new OptimizeCollectionsPage_1.OptimizeCollectionsPage(operateTab);
            const optimizeTabOptimizeReportPage = new OptimizeReportPage_1.OptimizeReportPage(operateTab);
            const optimizeTabOptimizeHomePage = new OptimizeHomePage_1.OptimizeHomePage(operateTab);
            await (0, expectLocatorWithRetry_1.expectLocatorWithRetry)(operateTab, operateTab.getByRole('link', { name: processName }));
            await optimizeTabOptimizeHomePage.clickCollectionsLink();
            await optimizeTabOptimizeCollectionsPage.clickCreateNewButton();
            await optimizeTabOptimizeCollectionsPage.clickReportOption();
            await optimizeTabOptimizeReportPage.clickProcessSelectionButton();
            await optimizeTabOptimizeReportPage.clickUserTaskProcess(processName);
            await (0, test_1.expect)(optimizeTabOptimizeReportPage.versionSelection).toBeVisible({
                timeout: 15000,
            });
            await optimizeTabOptimizeReportPage.clickVersionSelection();
            await optimizeTabOptimizeReportPage.clickAlwaysDisplayLatestSelection();
            await optimizeTabOptimizeReportPage.clickBlankReportButton();
            await optimizeTabOptimizeReportPage.clickCreateReportLink();
            await optimizeTabOptimizeReportPage.clickSelectDropdown();
            await optimizeTabOptimizeReportPage.clickUserTaskOption();
            await optimizeTabOptimizeReportPage.clickHeatMapButton();
            await (0, test_1.expect)(optimizeTabOptimizeReportPage.tableOption).toBeVisible({
                timeout: 15000,
            });
            await optimizeTabOptimizeReportPage.clickTableOption();
            await optimizeTabOptimizeReportPage.clickReportName();
            await optimizeTabOptimizeReportPage.clearReportName();
            await optimizeTabOptimizeReportPage.fillReportName(reportName);
            await optimizeTabOptimizeReportPage.clickSaveButton();
            await optimizeTabOptimizeHomePage.clickCollectionsLink();
            await (0, test_1.expect)(operateTab.getByText(reportName)).toBeVisible({
                timeout: 30000,
            });
            await optimizeTabOptimizeCollectionsPage.clickMostRecentProcessReport(reportName);
            await optimizeTabOptimizeReportPage.waitUntilLocatorIsVisible(optimizeTabOptimizeReportPage.oneUserTaskInstance.first(), operateTab);
            await (0, test_1.expect)(optimizeTabOptimizeReportPage.oneUserTaskInstance).toHaveCount(2, { timeout: 120000 });
        });
    });
    (0, _8_6_1.test)('Most Common REST Connector User Flow', async ({ page, modelerHomePage, appsPage, modelerCreatePage, connectorSettingsPage, operateHomePage, operateProcessesPage, operateProcessInstancePage, }) => {
        _8_6_1.test.slow();
        const randomString = await (0, _setup_1.generateRandomStringAsync)(3);
        const processName = 'REST_Connector_Basic_Auth_Process' + randomString;
        await _8_6_1.test.step('Navigate to Web Modeler', async () => {
            await appsPage.clickCamundaApps();
            await appsPage.clickModeler();
            await (0, test_1.expect)(modelerHomePage.modelerPageBanner).toBeVisible({
                timeout: 30000,
            });
        });
        await _8_6_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_6_1.test.step('Create BPMN Diagram with REST Connector with Basic Auth and Start Process Instance', async () => {
            await (0, UtilitiesPage_1.modelRestConnector)(modelerCreatePage, connectorSettingsPage, processName, 'https://camunda.proxy.beeceptor.com/pre-prod/basic-auth-test', 'basic', '{message:response.body.message}', 'result', { username: 'username', password: 'password' });
            await modelerCreatePage.runProcessInstance(clusterName);
        });
        await _8_6_1.test.step('View Process Instance in Operate, assert it completes and assert result expression', async () => {
            await appsPage.clickCamundaApps();
            await appsPage.clickOperate(clusterName);
            await operateHomePage.clickProcessesTab();
            await operateProcessesPage.clickProcessCompletedCheckbox();
            await operateProcessesPage.clickProcessInstanceLink(processName);
            await (0, expectLocatorWithRetry_1.expectLocatorWithRetry)(page, operateProcessInstancePage.completedIcon, { totalTimeout: 60000, maxRetries: 5 });
            await (0, test_1.expect)(operateProcessInstancePage.variablesList).toBeVisible({
                timeout: 15000,
            });
            await (0, test_1.expect)(operateProcessInstancePage.connectorResultVariableName('message')).toBeVisible({
                timeout: 15000,
            });
            await (0, test_1.expect)(operateProcessInstancePage
                .connectorResultVariableName('message')
                .getByText('"Message from Mock!"')).toBeVisible({
                timeout: 15000,
            });
        });
    });
});
