"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 OperateHomePage_1 = require("../../pages/8.6/OperateHomePage");
const AppsPage_1 = require("../../pages/8.6/AppsPage");
const OperateProcessInstancePage_1 = require("../../pages/8.6/OperateProcessInstancePage");
const UtilitiesPage_1 = require("../../pages/8.6/UtilitiesPage");
const sleep_1 = require("../../utils/sleep");
const LoginPage_1 = require("../../pages/8.6/LoginPage");
const resetSession_1 = require("../../utils/resetSession");
const users_1 = require("../../utils/users");
const testUser = (0, users_1.getTestUser)('nineteenthUser');
_8_6_1.test.describe.configure({ mode: 'parallel' });
_8_6_1.test.describe('HTO User Flow Tests', () => {
    const clusterName = 'Test Cluster';
    _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, homePage, appsPage, consoleOrganizationsPage }, testInfo) => {
        await (0, _setup_1.captureScreenshot)(page, testInfo);
        await (0, _setup_1.captureFailureVideo)(page, testInfo);
        if (testInfo.title.includes('Candidate Group')) {
            await (0, UtilitiesPage_1.deleteAllUserGroups)(homePage, consoleOrganizationsPage, appsPage);
        }
    });
    (0, _8_6_1.test)('Job Worker User Task Most Common Flow', async ({ page, homePage, modelerHomePage, appsPage, modelerCreatePage, operateHomePage, operateProcessesPage, operateProcessInstancePage, taskPanelPage, taskDetailsPage, }) => {
        _8_6_1.test.slow();
        const processName = 'User_Task_Process' + (await (0, _setup_1.generateRandomStringAsync)(3));
        await _8_6_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_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 User Task and Start Process Instance', async () => {
            await modelerCreatePage.modelJobWorkerDiagram(processName);
            await modelerCreatePage.runProcessInstance(clusterName);
            await (0, test_1.expect)(modelerCreatePage.viewProcessInstanceLink).toBeVisible({
                timeout: 20000,
            });
        });
        await _8_6_1.test.step('View Process Instance in Operate, complete User Task in Tasklist & assert process complete in Operate', async () => {
            await appsPage.clickCamundaApps();
            await appsPage.clickOperate(clusterName);
            await (0, test_1.expect)(operateHomePage.operateBanner).toBeVisible();
            await operateHomePage.clickProcessesTab();
            await operateProcessesPage.clickProcessInstanceLink(processName);
            await (0, test_1.expect)(operateProcessInstancePage.activeIcon).toBeVisible({
                timeout: 60000,
            });
            await appsPage.clickCamundaApps();
            await appsPage.clickTasklist(clusterName);
            await (0, test_1.expect)(taskPanelPage.taskListPageBanner).toBeVisible({
                timeout: 20000,
            });
            await taskPanelPage.openTask(processName);
            await taskDetailsPage.clickAssignToMeButton();
            await taskDetailsPage.clickCompleteTaskButton();
            await (0, test_1.expect)(page.getByText('Task completed')).toBeVisible({
                timeout: 20000,
            });
            await appsPage.clickCamundaApps();
            await appsPage.clickOperate(clusterName);
            await (0, test_1.expect)(operateHomePage.operateBanner).toBeVisible();
            await operateHomePage.clickProcessesTab();
            await operateProcessesPage.clickProcessCompletedCheckbox();
            await operateProcessesPage.clickProcessInstanceLink(processName);
            await (0, UtilitiesPage_1.assertLocatorVisibleWithRetry)(page, operateProcessInstancePage.completedIcon, 'completed icon');
        });
    });
    (0, _8_6_1.test)('User Task Editing Variables Flow', async ({ page, homePage, modelerHomePage, appsPage, modelerCreatePage, }) => {
        _8_6_1.test.slow();
        const processName = 'User_Task_Editing_Variables' + (await (0, _setup_1.generateRandomStringAsync)(3));
        await _8_6_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: 120000,
            });
        });
        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 User Task and Start Process Instance', async () => {
            await modelerCreatePage.modelJobWorkerDiagram(processName);
            await modelerCreatePage.runProcessInstance(clusterName, '{"testVariable":"testValue"}');
        });
        await _8_6_1.test.step('View Process Instance in Operate, Edit the Variable & Assert the Variable is Updated in Tasklist', async () => {
            await (0, test_1.expect)(modelerCreatePage.viewProcessInstanceLink).toBeVisible({
                timeout: 120000,
            });
            await modelerCreatePage.clickViewProcessInstanceLink();
            const operateTab = await page.waitForEvent('popup');
            const operateTabHomePage = new OperateHomePage_1.OperateHomePage(operateTab);
            const operateTabAppsPage = new AppsPage_1.AppsPage(operateTab);
            const operateTabProcessInstancePage = new OperateProcessInstancePage_1.OperateProcessInstancePage(operateTab);
            const operateTabTaskPanelPage = new TaskPanelPage_1.TaskPanelPage(operateTab);
            await (0, test_1.expect)(operateTabProcessInstancePage.activeIcon).toBeVisible({
                timeout: 1200000,
            });
            await (0, test_1.expect)(operateTab.getByText('"testValue"')).toBeVisible({
                timeout: 90000,
            });
            await (0, test_1.expect)(operateTab.getByText('testVariable', { exact: true })).toBeVisible();
            await operateTabHomePage.clickEditVariableButton('testVariable');
            await operateTabHomePage.clickVariableValueInput();
            await operateTabHomePage.clearVariableValueInput();
            await operateTabHomePage.fillVariableValueInput('"updatedValue"');
            await operateTabHomePage.clickSaveVariableButton();
            await (0, test_1.expect)(operateTabHomePage.editVariableSpinner).not.toBeVisible({
                timeout: 120000,
            });
            await (0, test_1.expect)(operateTab.getByText('"testValue"')).not.toBeVisible({
                timeout: 60000,
            });
            await (0, test_1.expect)(operateTab.getByText('"updatedValue"')).toBeVisible();
            await operateTabAppsPage.clickCamundaApps();
            await operateTabAppsPage.clickTasklist(clusterName);
            await operateTabTaskPanelPage.openTask(processName);
            await (0, test_1.expect)(operateTab.getByText('testVariable')).toBeVisible({
                timeout: 60000,
            });
            await (0, test_1.expect)(operateTab.getByText('"updatedValue"')).toBeVisible();
            await (0, test_1.expect)(operateTab.getByText('"testValue"')).not.toBeVisible();
        });
    });
    (0, _8_6_1.test)('RBA Off User Flow', async ({ page, homePage, modelerHomePage, appsPage, modelerCreatePage, clusterPage, clusterDetailsPage, taskPanelPage, taskProcessesPage, }) => {
        _8_6_1.test.slow();
        const randomString = await (0, _setup_1.generateRandomStringAsync)(3);
        const processName = 'User_Task_Process_RBA_OFF_' + randomString + '_';
        await _8_6_1.test.step('Navigate to Console', async () => {
            await (0, UtilitiesPage_1.disableRBA)(clusterName, homePage, clusterPage, clusterDetailsPage, appsPage);
        });
        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: 120000,
            });
        });
        await _8_6_1.test.step('Navigate to Cross Component Test Project', async () => {
            await modelerHomePage.clickCrossComponentProjectFolder();
        });
        await _8_6_1.test.step('Create Two BPMN Diagrams with User Task and Start Process Instance', async () => {
            await (0, UtilitiesPage_1.runMultipleProcesses)(clusterName, page, modelerHomePage, modelerCreatePage, {
                processName: processName,
                numberOfProcesses: 2,
            });
        });
        await _8_6_1.test.step('Navigate to Tasklist and Make Sure that the Two Deployed Processes Are Accessible', async () => {
            await appsPage.clickCamundaApps();
            await appsPage.clickTasklist(clusterName);
            await (0, test_1.expect)(taskPanelPage.taskListPageBanner).toBeVisible({
                timeout: 120000,
            });
            await taskPanelPage.clickProcessesTab();
            await taskProcessesPage.clickpopupContinueButton();
            await (0, test_1.expect)(page.getByText(`${processName}1`).last()).toBeVisible({
                timeout: 120000,
            });
            await (0, test_1.expect)(page.getByText(`${processName}2`).last()).toBeVisible({
                timeout: 120000,
            });
        });
    });
    (0, _8_6_1.test)('Zeebe User Task With Priority', async ({ page, homePage, modelerHomePage, appsPage, modelerCreatePage, taskPanelPage, taskDetailsPage, operateHomePage, operateProcessesPage, operateProcessInstancePage, }) => {
        const randomName = await (0, _setup_1.generateRandomStringAsync)(3);
        const processName = 'Zeebe_User_Task_Process_With_Priority' + randomName;
        const taskName = 'priorityTest' + randomName;
        await _8_6_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: 120000,
            });
        });
        await _8_6_1.test.step('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 multiple Zeebe User Tasks with Priority and Start Process Instance', async () => {
            await (0, test_1.expect)(modelerCreatePage.generalPanel).toBeVisible({
                timeout: 120000,
            });
            await modelerCreatePage.enterDiagramName(processName);
            await (0, sleep_1.sleep)(10000);
            await modelerCreatePage.addParallelUserTasks(4, taskName);
            await modelerCreatePage.clickAppendElementButton();
            await modelerCreatePage.clickAppendEndEventButton('parallelGateway');
            await modelerCreatePage.setPriority(taskName, 1, 4);
            await modelerCreatePage.runProcessInstance(clusterName);
        });
        await _8_6_1.test.step('Complete User Task in Tasklist & assert process complete in Operate', async () => {
            await (0, test_1.expect)(modelerCreatePage.viewProcessInstanceLink).toBeVisible({
                timeout: 120000,
            });
            await appsPage.clickCamundaApps();
            await appsPage.clickTasklist(clusterName);
            await (0, test_1.expect)(page.getByText(processName).first()).toBeVisible({
                timeout: 60000,
            });
            await (0, UtilitiesPage_1.completeTaskWithRetry)(taskPanelPage, taskDetailsPage, `${taskName}4`, 'critical');
            await (0, UtilitiesPage_1.completeTaskWithRetry)(taskPanelPage, taskDetailsPage, `${taskName}3`, 'high');
            await (0, UtilitiesPage_1.completeTaskWithRetry)(taskPanelPage, taskDetailsPage, `${taskName}2`, 'medium');
            await (0, UtilitiesPage_1.completeTaskWithRetry)(taskPanelPage, taskDetailsPage, `${taskName}1`, 'low');
            await taskPanelPage.filterBy('Completed');
            await (0, test_1.expect)(page.getByText(processName).first()).toBeVisible({
                timeout: 60000,
            });
            await (0, test_1.expect)(page.getByText(processName)).toHaveCount(4);
            await taskPanelPage.openTask(`${taskName}4`);
            await (0, test_1.expect)(taskDetailsPage.detailsInfo.getByText(processName)).toBeVisible({ timeout: 60000 });
            await (0, test_1.expect)(taskDetailsPage.detailsPanel.getByText('critical')).toBeVisible();
        });
        await appsPage.clickCamundaApps();
        await appsPage.clickOperate(clusterName);
        await operateHomePage.clickProcessesTab();
        await operateProcessesPage.clickProcessCompletedCheckbox();
        await operateProcessesPage.clickProcessInstanceLink(processName);
        await operateProcessInstancePage.assertProcessCompleteStatusWithRetry(40000);
    });
    (0, _8_6_1.test)('User Task Restrictions Enabled Flow - Candidate Group', async ({ page, homePage, modelerHomePage, appsPage, modelerCreatePage, browser, taskPanelPage, consoleOrganizationsPage, }) => {
        _8_6_1.test.slow();
        const randomName = await (0, _setup_1.generateRandomStringAsync)(3);
        const processName = 'User_Task_Process_Candidate_Group' + randomName;
        await _8_6_1.test.step('Delete All Groups If Exist', async () => {
            await homePage.clickOrganization();
            await consoleOrganizationsPage.clickGroupsTab();
            await consoleOrganizationsPage.deleteAllGroups();
        });
        await _8_6_1.test.step('Create Two User Groups', async () => {
            await consoleOrganizationsPage.clickCreateGroupButton();
            await consoleOrganizationsPage.fillGroupNameInput('Single User');
            await consoleOrganizationsPage.clickCreateGroupSubButton();
            await (0, test_1.expect)(consoleOrganizationsPage.createGroupDialoge).not.toBeVisible({
                timeout: 60000,
            });
            await consoleOrganizationsPage.clickCreateGroupButton();
            await consoleOrganizationsPage.fillGroupNameInput('Multiple Users');
            await consoleOrganizationsPage.clickCreateGroupSubButton();
            await (0, test_1.expect)(consoleOrganizationsPage.createGroupDialoge).not.toBeVisible({
                timeout: 60000,
            });
        });
        await _8_6_1.test.step('Assign Users to the Created Groups in Identity', async () => {
            await consoleOrganizationsPage.clickUserGroup('Single User');
            await consoleOrganizationsPage.clickAssignMembers();
            await consoleOrganizationsPage.fillAssignMembers([testUser.username]);
            await consoleOrganizationsPage.clickAssignSubButton();
            await consoleOrganizationsPage.clickOrganizationManagementLink();
            await consoleOrganizationsPage.clickGroupsTab();
            await consoleOrganizationsPage.clickUserGroup('Multiple Users');
            await consoleOrganizationsPage.clickAssignMembers();
            await consoleOrganizationsPage.fillAssignMembers([
                process.env.C8_USERNAME_TEST,
                process.env.C8_USERNAME_TEST_2,
            ]);
            await consoleOrganizationsPage.clickAssignSubButton();
        });
        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: 120000,
            });
        });
        await _8_6_1.test.step('Create HTO User Flow BPMN Diagram in Cross Component Test Project', async () => {
            await modelerHomePage.clickCrossComponentProjectFolder();
            await modelerHomePage.clickDiagramTypeDropdown();
            await modelerHomePage.clickBpmnTemplateOption();
        });
        await _8_6_1.test.step('Create BPMN Diagram with Multiple User Tasks', async () => {
            await (0, test_1.expect)(modelerCreatePage.generalPanel).toBeVisible({
                timeout: 200000,
            });
            await modelerCreatePage.enterDiagramName(processName);
            await (0, sleep_1.sleep)(10000);
            await modelerCreatePage.addParallelUserTasks(2, 'candidateGroupTask' + randomName);
            await modelerCreatePage.clickAppendElementButton();
            await modelerCreatePage.clickAppendEndEventButton('parallelGateway');
        });
        await _8_6_1.test.step('Assign User tasks to Candidate Groups and Start Process Instance', async () => {
            await modelerCreatePage.selectUserTask('candidateGroupTask' + randomName + '1');
            await modelerCreatePage.expandAssignmentSection();
            await modelerCreatePage.clickCandidateGroupsInput();
            await modelerCreatePage.fillCandidateGroupsInput('Single User');
            await modelerCreatePage.clickAssigneeInput();
            await modelerCreatePage.fillAssigneeInput(process.env.C8_USERNAME_TEST);
            await modelerCreatePage.clickCanvas();
            await modelerCreatePage.selectUserTask('candidateGroupTask' + randomName + '2');
            await modelerCreatePage.expandAssignmentSection();
            await modelerCreatePage.clickCandidateGroupsInput();
            await modelerCreatePage.fillCandidateGroupsInput('Multiple Users');
            await modelerCreatePage.runProcessInstance(clusterName);
        });
        await _8_6_1.test.step('View User Tasks in Tasklist', async () => {
            await (0, test_1.expect)(modelerCreatePage.viewProcessInstanceLink).toBeVisible({
                timeout: 120000,
            });
            await appsPage.clickCamundaApps();
            await appsPage.clickTasklist(clusterName);
            await (0, test_1.expect)(taskPanelPage.taskListPageBanner).toBeVisible({
                timeout: 60000,
            });
            await (0, UtilitiesPage_1.assertPageTextWithRetry)(page, 'candidateGroupTask' + randomName + '1');
            await (0, UtilitiesPage_1.assertPageTextWithRetry)(page, 'candidateGroupTask' + randomName + '2', true);
        });
        await _8_6_1.test.step('Clear cookies and reset session', async () => {
            const context = browser.contexts()[0];
            await context.clearCookies();
            await (0, sleep_1.sleep)(10000);
            await page.reload();
            await page.goto('/');
        });
        await _8_6_1.test.step('Login with Test User and Check Tasks in Tasklist ', async () => {
            const loginPage = new LoginPage_1.LoginPage(page);
            await loginPage.loginWithTestUser();
            await appsPage.clickCamundaApps();
            await appsPage.clickTasklist(clusterName);
            await (0, test_1.expect)(taskPanelPage.taskListPageBanner).toBeVisible({
                timeout: 120000,
            });
            await (0, UtilitiesPage_1.assertPageTextWithRetry)(page, 'candidateGroupTask' + randomName + '1');
            await (0, UtilitiesPage_1.assertPageTextWithRetry)(page, 'candidateGroupTask' + randomName + '2');
        });
        await _8_6_1.test.step('Clear cookies and reset session', async () => {
            await (0, resetSession_1.resetSession)(browser, page);
        });
        await _8_6_1.test.step('Login with Second Test User and Check Tasks in Tasklist ', async () => {
            const loginPage = new LoginPage_1.LoginPage(page);
            await loginPage.loginWithTestUser({
                username: process.env.C8_USERNAME_TEST_2,
                password: process.env.C8_PASSWORD_TEST_2,
            });
            await appsPage.clickCamundaApps();
            await appsPage.clickTasklist(clusterName);
            await (0, test_1.expect)(taskPanelPage.taskListPageBanner).toBeVisible({
                timeout: 120000,
            });
            await (0, UtilitiesPage_1.assertPageTextWithRetry)(page, 'candidateGroupTask' + randomName + '1', true);
            await (0, UtilitiesPage_1.assertPageTextWithRetry)(page, 'candidateGroupTask' + randomName + '2');
        });
    });
});
