"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const test_1 = require("@playwright/test");
const _8_10_1 = require("../../fixtures/8.10");
const _setup_1 = require("../../test-setup.js");
const TaskPanelPage_1 = require("../../pages/8.10/TaskPanelPage");
const TaskDetailsPage_1 = require("../../pages/8.10/TaskDetailsPage");
const OperateHomePage_1 = require("../../pages/8.10/OperateHomePage");
const AppsPage_1 = require("../../pages/8.10/AppsPage");
const OperateProcessesPage_1 = require("../../pages/8.10/OperateProcessesPage");
const OperateProcessInstancePage_1 = require("../../pages/8.10/OperateProcessInstancePage");
const UtilitiesPage_1 = require("../../pages/8.10/UtilitiesPage");
const OptimizeHomePage_1 = require("../../pages/8.10/OptimizeHomePage");
const OptimizeCollectionsPage_1 = require("../../pages/8.10/OptimizeCollectionsPage");
const OptimizeReportPage_1 = require("../../pages/8.10/OptimizeReportPage");
const users_1 = require("../../utils/users");
const sleep_1 = require("../../utils/sleep");
const constants_1 = require("../../utils/constants");
const testUser = (0, users_1.getTestUser)('thirteenthUser');
const CLUSTER_NAME = 'Test Cluster';
_8_10_1.test.describe.configure({ mode: 'parallel' });
_8_10_1.test.describe('Smoke Tests', () => {
    _8_10_1.test.beforeEach(async ({ page, loginPage }, testInfo) => {
        await (0, UtilitiesPage_1.loginWithRetry)(page, loginPage, testUser, (testInfo.workerIndex + 1) * 1000);
    });
    _8_10_1.test.afterEach(async ({ page }, testInfo) => {
        await (0, _setup_1.captureScreenshot)(page, testInfo);
        await (0, _setup_1.captureFailureVideo)(page, testInfo);
    });
    (0, _8_10_1.test)('Most Common Flow User Flow With All Apps', async ({ page, homePage, modelerHomePage, appsPage, modelerCreatePage, formJsPage, }) => {
        _8_10_1.test.slow();
        const randomString = await (0, _setup_1.generateRandomStringAsync)(3);
        const formName = 'New form' + randomString;
        const processName = 'Zeebe_User_Task_Process' + randomString;
        const userTaskName = 'zeebeUserTaskWithForm' + randomString;
        const reportName = await (0, _setup_1.generateRandomStringAsync)(5);
        let appTab;
        await _8_10_1.test.step('Navigate to Web Modeler', async () => {
            await (0, test_1.expect)(homePage.camundaComponentsButton).toBeVisible({
                timeout: constants_1.TIMEOUT.medium,
            });
            await appsPage.clickCamundaApps();
            await appsPage.clickModeler();
            await (0, test_1.expect)(modelerHomePage.modelerPageBanner).toBeVisible({
                timeout: constants_1.TIMEOUT.navigation,
            });
        });
        await _8_10_1.test.step('Create form to be linked for Zeebe user task', async () => {
            await modelerHomePage.clickCrossComponentProjectFolder();
            await modelerHomePage.clickDiagramTypeDropdown();
            await modelerHomePage.clickFormOption();
            await modelerHomePage.enterFormName(formName);
            await modelerHomePage.assertFormBreadcrumbVisible(formName);
            await formJsPage.deployForm(CLUSTER_NAME);
            // Wait for the form to propagate to the cluster before it can be embedded
            await (0, sleep_1.sleep)(5000);
        });
        await _8_10_1.test.step('Add a BPMN template to the project', async () => {
            await modelerHomePage.clickProjectBreadcrumb();
            await modelerHomePage.clickDiagramTypeDropdown();
            await modelerHomePage.clickBpmnTemplateOption();
        });
        await _8_10_1.test.step('Create BPMN diagram with two Zeebe user tasks', async () => {
            await (0, test_1.expect)(modelerCreatePage.generalPanel).toBeVisible({
                timeout: constants_1.TIMEOUT.navigation,
            });
            await modelerCreatePage.enterDiagramName(processName);
            await modelerCreatePage.assertDiagramNameSet(processName);
            // Wait for the diagram name change to auto-save before interacting with the canvas
            await (0, sleep_1.sleep)(10000);
            await modelerCreatePage.clickCanvas();
            await modelerCreatePage.clickGeneralPropertiesPanel();
            await modelerCreatePage.clickNameInput();
            await modelerCreatePage.fillNamedInput(processName);
            await modelerCreatePage.clickIdInput();
            await modelerCreatePage.fillIdInput(processName);
            await modelerCreatePage.clickStartEventElement();
            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 _8_10_1.test.step('Deploy and start process instance', async () => {
            await modelerCreatePage.runProcessInstance(CLUSTER_NAME);
            await (0, test_1.expect)(modelerCreatePage.viewProcessInstanceLink).toBeVisible({
                timeout: constants_1.TIMEOUT.navigation,
            });
        });
        await _8_10_1.test.step('Open process instance in Operate and verify it is active', async () => {
            await modelerCreatePage.clickViewProcessInstanceLink();
            appTab = await page.waitForEvent('popup', { timeout: constants_1.TIMEOUT.navigation });
            const appTabProcessInstancePage = new OperateProcessInstancePage_1.OperateProcessInstancePage(appTab);
            await (0, test_1.expect)(appTabProcessInstancePage.activeIcon).toBeVisible({
                timeout: constants_1.TIMEOUT.processActive,
            });
            await appTabProcessInstancePage.closePopOverIfVisible();
        });
        await _8_10_1.test.step('Navigate to Tasklist and complete both user tasks', async () => {
            const appTabAppsPage = new AppsPage_1.AppsPage(appTab);
            const appTabTaskPanelPage = new TaskPanelPage_1.TaskPanelPage(appTab);
            const appTabTaskDetailsPage = new TaskDetailsPage_1.TaskDetailsPage(appTab);
            await appTabAppsPage.clickCamundaApps();
            await appTabAppsPage.clickTasklist(CLUSTER_NAME);
            await (0, UtilitiesPage_1.completeTaskWithRetry)(appTabTaskPanelPage, appTabTaskDetailsPage, `${userTaskName}1`, 'Medium');
            await (0, UtilitiesPage_1.completeTaskWithRetry)(appTabTaskPanelPage, appTabTaskDetailsPage, `${userTaskName}2`, 'Medium');
            await appTabTaskPanelPage.filterBy('Completed');
            await appTabTaskPanelPage.openTask(`${userTaskName}1`);
            await (0, test_1.expect)(appTabTaskDetailsPage.detailsInfo.getByText(`${userTaskName}1`)).toBeVisible({ timeout: constants_1.TIMEOUT.medium });
            await appTabTaskPanelPage.openTask(`${userTaskName}2`);
            await (0, test_1.expect)(appTabTaskDetailsPage.detailsInfo.getByText(`${userTaskName}2`)).toBeVisible({ timeout: constants_1.TIMEOUT.medium });
        });
        await _8_10_1.test.step('Assert process completion in Operate', async () => {
            const appTabAppsPage = new AppsPage_1.AppsPage(appTab);
            const appTabHomePage = new OperateHomePage_1.OperateHomePage(appTab);
            const appTabProcessesPage = new OperateProcessesPage_1.OperateProcessesPage(appTab);
            const appTabProcessInstancePage = new OperateProcessInstancePage_1.OperateProcessInstancePage(appTab);
            await appTabAppsPage.clickCamundaApps();
            await appTabAppsPage.clickOperate(CLUSTER_NAME);
            await appTabHomePage.clickProcessesTab();
            await (0, test_1.expect)(appTabProcessesPage.processCompletedCheckbox).toBeVisible({
                timeout: constants_1.TIMEOUT.short,
            });
            await appTabProcessesPage.clickProcessCompletedCheckbox();
            await appTabProcessesPage.clickProcessInstanceLink(processName);
            await (0, UtilitiesPage_1.assertLocatorVisibleWithRetry)(appTabProcessInstancePage, appTabProcessInstancePage.completedIcon, 'completed icon in Operate', constants_1.TIMEOUT.processComplete);
        });
        await _8_10_1.test.step('Assert process imported in Optimize and create user task report', async () => {
            const appTabAppsPage = new AppsPage_1.AppsPage(appTab);
            const optimizeHomePage = new OptimizeHomePage_1.OptimizeHomePage(appTab);
            const optimizeCollectionsPage = new OptimizeCollectionsPage_1.OptimizeCollectionsPage(appTab);
            const optimizeReportPage = new OptimizeReportPage_1.OptimizeReportPage(appTab);
            await appTabAppsPage.clickCamundaApps();
            await appTabAppsPage.clickOptimize(CLUSTER_NAME);
            await (0, UtilitiesPage_1.assertLocatorVisibleWithRetry)(appTab, appTab.getByRole('link', { name: processName }), `process ${processName} in Optimize`, constants_1.TIMEOUT.optimizeImport);
            await optimizeHomePage.clickCollectionsLink();
            await optimizeCollectionsPage.clickCreateNewButtonWithRetry();
            await optimizeCollectionsPage.clickReportOption();
            await optimizeReportPage.clickProcessSelectionButton();
            await optimizeReportPage.clickUserTaskProcess(processName);
            await (0, test_1.expect)(optimizeReportPage.versionSelection).toBeVisible({
                timeout: constants_1.TIMEOUT.short,
            });
            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: constants_1.TIMEOUT.short,
            });
            await optimizeReportPage.clickTableOption();
            await optimizeReportPage.clickReportName();
            await optimizeReportPage.clearReportName();
            await optimizeReportPage.fillReportName(reportName);
            await optimizeReportPage.clickSaveButton();
            await optimizeHomePage.clickCollectionsLink();
            await (0, test_1.expect)(appTab.getByText(reportName)).toBeVisible({
                timeout: constants_1.TIMEOUT.medium,
            });
            await optimizeCollectionsPage.clickMostRecentProcessReport(reportName);
            await optimizeReportPage.waitUntilLocatorIsVisible(optimizeReportPage.oneUserTaskInstance.first(), appTab);
            await (0, test_1.expect)(optimizeReportPage.oneUserTaskInstance).toHaveCount(2, {
                timeout: constants_1.TIMEOUT.navigation,
            });
        });
    });
    (0, _8_10_1.test)('Most Common REST Connector User Flow', async ({ page, homePage, modelerHomePage, appsPage, modelerCreatePage, connectorSettingsPage, }) => {
        _8_10_1.test.slow();
        const randomString = await (0, _setup_1.generateRandomStringAsync)(3);
        const processName = 'REST_Connector_Basic_Auth_Process' + randomString;
        await _8_10_1.test.step('Navigate to Web Modeler', async () => {
            await (0, test_1.expect)(homePage.camundaComponentsButton).toBeVisible({
                timeout: constants_1.TIMEOUT.medium,
            });
            await appsPage.clickCamundaApps();
            await appsPage.clickModeler();
            await (0, test_1.expect)(modelerHomePage.modelerPageBanner).toBeVisible({
                timeout: constants_1.TIMEOUT.navigation,
            });
        });
        await _8_10_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_10_1.test.step('Create BPMN diagram with REST Connector using Basic Auth', 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 _8_10_1.test.step('Deploy and start process instance', async () => {
            await modelerCreatePage.runProcessInstance(CLUSTER_NAME);
            await (0, test_1.expect)(modelerCreatePage.viewProcessInstanceLink).toBeVisible({
                timeout: constants_1.TIMEOUT.navigation,
            });
        });
        await _8_10_1.test.step('Assert process completes in Operate and verify connector result', async () => {
            await modelerCreatePage.clickViewProcessInstanceLink();
            const operateTab = await page.waitForEvent('popup', {
                timeout: constants_1.TIMEOUT.navigation,
            });
            const operateProcessInstancePage = new OperateProcessInstancePage_1.OperateProcessInstancePage(operateTab);
            await operateProcessInstancePage.closePopOverIfVisible();
            await (0, UtilitiesPage_1.assertLocatorVisibleWithRetry)(operateProcessInstancePage, operateProcessInstancePage.completedIcon, 'completed icon in Operate', constants_1.TIMEOUT.processComplete);
            await (0, UtilitiesPage_1.assertLocatorVisibleWithRetry)(operateTab, operateProcessInstancePage.variablesList, 'variable list in Operate', constants_1.TIMEOUT.navigation);
            await (0, test_1.expect)(operateProcessInstancePage.connectorResultVariableName('message')).toBeVisible({ timeout: constants_1.TIMEOUT.navigation });
            await (0, test_1.expect)(operateProcessInstancePage
                .connectorResultVariableName('message')
                .getByText('"Message from Mock!"')).toBeVisible({ timeout: constants_1.TIMEOUT.navigation });
        });
    });
});
