"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 resetSession_1 = require("../../utils/resetSession");
SM_8_8_1.test.describe.configure({ mode: 'parallel' });
SM_8_8_1.test.describe('HTO User Flow Tests', () => {
    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);
    });
    //Skipped due to bug 42918: https://github.com/camunda/camunda/issues/42918
    SM_8_8_1.test.skip('Job Worker User Task Most Common Flow @tasklistV1', async ({ modelerHomePage, navigationPage, modelerCreatePage, operateHomePage, operateProcessesPage, taskDetailsPage, taskPanelPage, operateProcessInstancePage, page, }) => {
        SM_8_8_1.test.slow();
        const processName = 'User_Task_Process' + (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 SM_8_8_1.test.step('View Process Instance in Operate, complete User Task in Tasklist & assert process complete in Operate', async () => {
            await navigationPage.goToOperate();
            await operateHomePage.clickProcessesTab();
            await operateProcessesPage.clickProcessInstanceLink(processName);
            await operateProcessInstancePage.activeIconAssertion();
            await navigationPage.goToTasklist();
            await taskPanelPage.openTask(processName);
            await taskDetailsPage.clickAssignToMeButton();
            await taskDetailsPage.clickCompleteTaskButton();
            await (0, test_1.expect)(page.getByText('Task completed')).toBeVisible({
                timeout: 200000,
            });
            await navigationPage.goToOperate();
            await operateHomePage.clickProcessesTab();
            await operateProcessesPage.clickProcessCompletedCheckbox();
            await operateProcessesPage.clickProcessInstanceLink(processName);
            await operateProcessInstancePage.completedIconAssertion();
        });
    });
    (0, SM_8_8_1.test)('Zeebe User Task With Priority', async ({ page, modelerHomePage, navigationPage, modelerCreatePage, operateHomePage, operateProcessesPage, operateProcessInstancePage, taskDetailsPage, taskPanelPage, }) => {
        SM_8_8_1.test.slow();
        const randomName = await (0, _setup_1.generateRandomStringAsync)(3);
        const processName = 'Zeebe_User_Task_Process_With_Priority' + randomName;
        const taskName = 'priorityTest' + randomName;
        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 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)(5000);
            await modelerCreatePage.clickCanvas();
            await modelerCreatePage.clickGeneralPropertiesPanel();
            await modelerCreatePage.clickIdInput();
            await modelerCreatePage.fillIdInput(processName);
            await modelerCreatePage.assertNameInput(processName);
            await (0, sleep_1.sleep)(1000);
            await modelerCreatePage.clickStartEventElement();
            await modelerCreatePage.addParallelUserTasks(4, taskName);
            await modelerCreatePage.clickAppendElementButton();
            await modelerCreatePage.clickAppendEndEventButton('parallelGateway');
            await modelerCreatePage.setPriority(taskName, 1, 4);
            await (0, sleep_1.sleep)(30000);
            await modelerCreatePage.runProcessInstance();
        });
        await SM_8_8_1.test.step('Complete User Task in Tasklist & assert process complete in Operate', async () => {
            await navigationPage.goToTasklist();
            await page.waitForLoadState('networkidle');
            await (0, sleep_1.sleep)(500);
            await (0, test_1.expect)(page.getByText(processName).first()).toBeVisible({
                timeout: 60000,
            });
            await (0, UtilitiesPage_1.completeTaskWithRetry)(page, taskPanelPage, taskDetailsPage, `${taskName}4`, 'critical');
            await (0, UtilitiesPage_1.completeTaskWithRetry)(page, taskPanelPage, taskDetailsPage, `${taskName}3`, 'high');
            await (0, UtilitiesPage_1.completeTaskWithRetry)(page, taskPanelPage, taskDetailsPage, `${taskName}2`, 'medium');
            await (0, UtilitiesPage_1.completeTaskWithRetry)(page, taskPanelPage, taskDetailsPage, `${taskName}1`, 'low');
            await taskPanelPage.filterBy('Completed');
            await taskPanelPage.clickCollapseFilter();
            await (0, test_1.expect)(page.getByRole('heading', { name: 'completed' })).toBeVisible({
                timeout: 45000,
            });
            await page.reload();
            await taskPanelPage.openTask(`${taskName}4`, false);
            await (0, test_1.expect)(page.getByText(processName).first()).toBeVisible({
                timeout: 60000,
            });
            await taskDetailsPage.taskAssertion(processName);
            await taskDetailsPage.priorityAssertion('critical');
            await (0, sleep_1.sleep)(10000);
            await navigationPage.goToOperate();
            await operateHomePage.clickProcessesTab();
            await operateProcessesPage.clickProcessInstanceLink(processName, 'completed');
            const result = await operateProcessInstancePage.assertEitherIncidentOrCompletedIconVisible();
            (0, test_1.expect)(result).toBe('completed');
        });
    });
    (0, SM_8_8_1.test)('User Task Editing Variables Flow', async ({ page, operateHomePage, modelerHomePage, navigationPage, modelerCreatePage, operateProcessesPage, operateProcessInstancePage, taskPanelPage, }) => {
        SM_8_8_1.test.slow();
        const processName = 'User_Task_Editing_Variables' + (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.modelCamundaUserTaskDiagram(processName);
            await modelerCreatePage.runProcessInstance('{"testVariable":"testValue"}');
            await (0, sleep_1.sleep)(60000);
        });
        await SM_8_8_1.test.step('View Process Instance in Operate, Edit the Variable & Assert the Variable is Updated in Tasklist', async () => {
            await navigationPage.goToOperate();
            await operateHomePage.clickProcessesTab();
            await operateProcessesPage.clickProcessInstanceLink(processName);
            await operateProcessInstancePage.activeIconAssertion();
            await (0, test_1.expect)(page.getByText('"testValue"')).toBeVisible({
                timeout: 120000,
            });
            await (0, test_1.expect)(page.getByText('testVariable', { exact: true })).toBeVisible();
            await operateHomePage.clickEditVariableButton('testVariable');
            await operateHomePage.clickVariableValueInput();
            await operateHomePage.clearVariableValueInput();
            await operateHomePage.fillVariableValueInput('"updatedValue"');
            await (0, test_1.expect)(operateHomePage.saveVariableButton).toBeVisible({
                timeout: 30000,
            });
            await operateHomePage.clickSaveVariableButton();
            await (0, test_1.expect)(operateHomePage.editVariableSpinner).not.toBeVisible({
                timeout: 120000,
            });
            await (0, test_1.expect)(page.getByText('"testValue"')).not.toBeVisible({
                timeout: 90000,
            });
            await (0, test_1.expect)(page.getByText('"updatedValue"')).toBeVisible({
                timeout: 90000,
            });
            await (0, sleep_1.sleep)(10000);
            await navigationPage.goToTasklist();
            await taskPanelPage.openTask(processName);
            await (0, test_1.expect)(page.getByText('testVariable')).toBeVisible();
            await (0, test_1.expect)(page.getByText('"updatedValue"')).toBeVisible();
            await (0, test_1.expect)(page.getByText('"testValue"')).not.toBeVisible();
        });
    });
    //Skipped due to bug 4920: https://github.com/camunda/camunda-platform-helm/issues/4920
    SM_8_8_1.test.skip('User Task Restrictions Enabled Flow - Candidate Group @tasklistV1', async ({ page, modelerHomePage, navigationPage, modelerCreatePage, operateHomePage, operateProcessInstancePage, taskDetailsPage, taskPanelPage, managementIdentityPage, keycloakAdminPage, keycloakLoginPage, ocIdentityHomePage, ocIdentityMappingRulesPage, ocIdentityRolesPage, ocIdentityGroupsPage, browser, }) => {
        SM_8_8_1.test.slow();
        const randomString = await (0, _setup_1.generateRandomStringAsync)(3);
        const userTaskName = 'candidateGroupTask' + randomString;
        const processName = 'User_Task_Process_Candidate_Group' + randomString;
        const groupNameSingle = await (0, _setup_1.generateRandomStringAsync)(4);
        const groupNameMultiple = await (0, _setup_1.generateRandomStringAsync)(4);
        const testUser1 = (await (0, _setup_1.generateRandomStringAsync)(6)).toLowerCase();
        const testUser2 = (await (0, _setup_1.generateRandomStringAsync)(6)).toLowerCase();
        const password = process.env.DISTRO_QA_E2E_TESTS_IDENTITY_FIRSTUSER_PASSWORD;
        const credentials1 = {
            username: testUser1,
            password: password,
        };
        const credentials2 = {
            username: testUser2,
            password: password,
        };
        await SM_8_8_1.test.step('Create Two New Test Users And Assign to Role', async () => {
            await navigationPage.goToOCIdentity();
            await (0, UtilitiesPage_1.createUserAndAssignToRole)(page, navigationPage, managementIdentityPage, keycloakLoginPage, keycloakAdminPage, ocIdentityHomePage, ocIdentityMappingRulesPage, ocIdentityRolesPage, testUser1, password);
            await (0, resetSession_1.resetSession)(browser, page);
            await (0, sleep_1.sleep)(10000);
            await navigationPage.goToOCIdentity();
            await (0, UtilitiesPage_1.createUserAndAssignToRole)(page, navigationPage, managementIdentityPage, keycloakLoginPage, keycloakAdminPage, ocIdentityHomePage, ocIdentityMappingRulesPage, ocIdentityRolesPage, testUser2, password);
        });
        await SM_8_8_1.test.step('Create Two User Groups in Identity', async () => {
            await ocIdentityHomePage.clickGroupsTab();
            await ocIdentityGroupsPage.createGroup(groupNameSingle, groupNameSingle);
            await ocIdentityGroupsPage.createGroup(groupNameMultiple, groupNameMultiple);
        });
        await SM_8_8_1.test.step('Assign Users to the Created Groups in Identity', async () => {
            await ocIdentityGroupsPage.clickGroupId(groupNameSingle);
            await ocIdentityGroupsPage.assignUserToGroup('demo');
            await ocIdentityHomePage.clickGroupsTab();
            await ocIdentityGroupsPage.clickGroupId(groupNameMultiple);
            await ocIdentityGroupsPage.assignUserToGroup(testUser1);
            await ocIdentityHomePage.clickGroupsTab();
            await ocIdentityGroupsPage.clickGroupId(groupNameMultiple);
            await ocIdentityGroupsPage.assignUserToGroup(testUser2);
        });
        await SM_8_8_1.test.step('Create a BPMN Diagram Template', async () => {
            await navigationPage.goToModeler();
            await modelerHomePage.clickCrossComponentProjectFolder();
        });
        await SM_8_8_1.test.step('Create BPMN Diagram with Multiple User Tasks', async () => {
            await (0, UtilitiesPage_1.modelDiagramFromFile)(page, modelerHomePage, modelerCreatePage, processName, 'Candidate_User_Process_Three_Tasks', 3, userTaskName);
        });
        await SM_8_8_1.test.step('Assign User tasks to Candidate Groups and Start Process Instance', async () => {
            await modelerCreatePage.selectUserTask(`${userTaskName}1`);
            await modelerCreatePage.expandAssignmentSection();
            await modelerCreatePage.clickCandidateGroupsInput();
            await modelerCreatePage.fillCandidateGroupsInput(groupNameSingle);
            await (0, sleep_1.sleep)(1000);
            await modelerCreatePage.clickAssigneeInput();
            await modelerCreatePage.fillAssigneeInput(testUser1);
            await modelerCreatePage.clickCanvas();
            await modelerCreatePage.selectUserTask(`${userTaskName}2`);
            await modelerCreatePage.expandAssignmentSection();
            await modelerCreatePage.clickCandidateGroupsInput();
            await modelerCreatePage.fillCandidateGroupsInput(groupNameMultiple);
            await (0, sleep_1.sleep)(1000);
            await modelerCreatePage.runProcessInstance();
        });
        await SM_8_8_1.test.step('View User Tasks in Tasklist', async () => {
            await navigationPage.goToTasklist();
            await (0, test_1.expect)(page.getByText(`${userTaskName}1`)).toBeVisible({
                timeout: 120000,
            });
            await (0, test_1.expect)(page.getByText(`${userTaskName}2`)).not.toBeVisible({
                timeout: 120000,
            });
        });
        await SM_8_8_1.test.step('Clear cookies and reset session', async () => {
            await (0, resetSession_1.resetSession)(browser, page); //a workaround for https://github.com/camunda/camunda/issues/34513
            await (0, sleep_1.sleep)(10000);
        });
        await SM_8_8_1.test.step('Navigate to Tasklist and Assert User Tasks ', async () => {
            await navigationPage.goToTasklist(undefined, credentials1);
            await (0, test_1.expect)(page.getByText(`${userTaskName}1`)).toBeVisible({
                timeout: 120000,
            });
            await (0, test_1.expect)(page.getByText(`${userTaskName}2`)).toBeVisible({
                timeout: 120000,
            });
        });
        await SM_8_8_1.test.step('Clear cookies and reset session', async () => {
            await (0, resetSession_1.resetSession)(browser, page); //a workaround for https://github.com/camunda/camunda/issues/34513
            await (0, sleep_1.sleep)(10000);
        });
        await SM_8_8_1.test.step('Navigate to Tasklist and Assert User Tasks ', async () => {
            await navigationPage.goToTasklist(undefined, credentials2);
            await (0, test_1.expect)(page.getByText(`${userTaskName}1`)).not.toBeVisible({
                timeout: 120000,
            });
            await (0, test_1.expect)(page.getByText(`${userTaskName}2`)).toBeVisible({
                timeout: 120000,
            });
        });
        await SM_8_8_1.test.step('Complete a User Task', async () => {
            await taskPanelPage.openTask(`${userTaskName}2`);
            await taskDetailsPage.clickAssignToMeButton();
            await taskDetailsPage.clickCompleteTaskButton();
            await (0, test_1.expect)(page.getByText('Task completed')).toBeVisible({
                timeout: 200000,
            });
        });
        await SM_8_8_1.test.step('Navigate to Operate and Assert Process Instance', async () => {
            await navigationPage.goToOperate(undefined, credentials2);
            await operateHomePage.openProcess(processName);
            await operateProcessInstancePage.activeUserTaskIconVisibleAssertion(`state-overlay-${userTaskName}1-active`);
            await operateProcessInstancePage.activeUserTaskIconNotVisibleAssertion(`state-overlay-${userTaskName}2-active`);
        });
    });
    (0, SM_8_8_1.test)('User Task Restrictions Enabled Flow - Candidate User @tasklistV1', async ({ page, modelerHomePage, navigationPage, modelerCreatePage, operateHomePage, operateProcessInstancePage, taskDetailsPage, taskPanelPage, managementIdentityPage, keycloakAdminPage, keycloakLoginPage, ocIdentityMappingRulesPage, ocIdentityHomePage, ocIdentityRolesPage, browser, }) => {
        SM_8_8_1.test.slow();
        const randomString = await (0, _setup_1.generateRandomStringAsync)(3);
        const userTaskName = 'candidateUserTask' + randomString;
        const processName = 'User_Task_Process_Candidate_User' + randomString;
        const testUser = (await (0, _setup_1.generateRandomStringAsync)(6)).toLowerCase();
        const password = process.env.DISTRO_QA_E2E_TESTS_IDENTITY_FIRSTUSER_PASSWORD;
        const credentials = {
            username: testUser,
            password: password,
        };
        await SM_8_8_1.test.step('Create new Test User And Assign to Role', async () => {
            await navigationPage.goToOCIdentity();
            await (0, UtilitiesPage_1.createUserAndAssignToRole)(page, navigationPage, managementIdentityPage, keycloakLoginPage, keycloakAdminPage, ocIdentityHomePage, ocIdentityMappingRulesPage, ocIdentityRolesPage, testUser, password);
        });
        await SM_8_8_1.test.step('Open Cross Component Test Project and Create a BPMN Diagram Template', async () => {
            await navigationPage.goToModeler();
            await modelerHomePage.clickCrossComponentProjectFolder();
            await modelerHomePage.clickDiagramTypeDropdown();
            await modelerHomePage.clickBpmnTemplateOption();
        });
        await SM_8_8_1.test.step('Create BPMN Diagram with Multiple User Tasks', async () => {
            await (0, test_1.expect)(modelerCreatePage.generalPanel).toBeVisible({
                timeout: 120000,
            });
            await modelerCreatePage.enterDiagramName(processName);
            await (0, sleep_1.sleep)(10000);
            await modelerCreatePage.clickStartEventElement();
            await modelerCreatePage.clickGeneralPropertiesPanel();
            await modelerCreatePage.assertNameInput(processName);
            await modelerCreatePage.clickStartEventElement();
            await modelerCreatePage.addParallelUserTasks(3, userTaskName);
            await modelerCreatePage.clickAppendElementButton();
            await modelerCreatePage.clickAppendEndEventButton('parallelGateway');
        });
        await SM_8_8_1.test.step('Assign User tasks to Candidate Users and Start Process Instance', async () => {
            await modelerCreatePage.selectUserTask(`${userTaskName}1`);
            await modelerCreatePage.expandAssignmentSection();
            await modelerCreatePage.clickCandidateUsersInput();
            await modelerCreatePage.fillCandidateUsersInput(testUser);
            await modelerCreatePage.clickAssigneeInput();
            await modelerCreatePage.fillAssigneeInput('demo');
            await modelerCreatePage.clickCanvas();
            await modelerCreatePage.selectUserTask(`${userTaskName}2`);
            await modelerCreatePage.expandAssignmentSection();
            await modelerCreatePage.clickCandidateUsersInput();
            await modelerCreatePage.fillCandidateUsersInput('demo');
            await modelerCreatePage.clickCanvas();
            await modelerCreatePage.selectUserTask(`${userTaskName}3`);
            await modelerCreatePage.expandAssignmentSection();
            await modelerCreatePage.clickCandidateUsersInput();
            await modelerCreatePage.fillCandidateUsersInput(testUser);
            await (0, sleep_1.sleep)(1000);
            await modelerCreatePage.runProcessInstance();
        });
        await SM_8_8_1.test.step('View User Tasks in Tasklist', async () => {
            await navigationPage.goToTasklist();
            await (0, test_1.expect)(page.getByText(`${userTaskName}1`)).toBeVisible({
                timeout: 120000,
            });
            await (0, test_1.expect)(page.getByText(`${userTaskName}2`)).toBeVisible({
                timeout: 120000,
            });
            await (0, test_1.expect)(page.getByText(`${userTaskName}3`)).not.toBeVisible({
                timeout: 120000,
            });
        });
        await SM_8_8_1.test.step('Clear cookies and reset session', async () => {
            await (0, resetSession_1.resetSession)(browser, page); //a workaround for https://github.com/camunda/camunda/issues/34513
            await (0, sleep_1.sleep)(10000);
        });
        await SM_8_8_1.test.step('Navigate to Tasklist and Assert User Tasks ', async () => {
            await navigationPage.goToTasklist(undefined, credentials);
            await (0, test_1.expect)(page.getByText(`${userTaskName}1`)).toBeVisible({
                timeout: 120000,
            });
            await (0, test_1.expect)(page.getByText(`${userTaskName}2`)).not.toBeVisible({
                timeout: 120000,
            });
            await (0, test_1.expect)(page.getByText(`${userTaskName}3`)).toBeVisible({
                timeout: 120000,
            });
        });
        await SM_8_8_1.test.step('Complete a User Task', async () => {
            await taskPanelPage.openTask(`${userTaskName}3`);
            await taskDetailsPage.clickAssignToMeButton();
            await taskDetailsPage.clickCompleteTaskButton();
            await (0, test_1.expect)(page.getByText('Task completed')).toBeVisible({
                timeout: 200000,
            });
        });
        await SM_8_8_1.test.step('Navigate to Operate and Assert Process Instance', async () => {
            await navigationPage.goToOperate(undefined, credentials);
            await operateHomePage.openProcess(processName);
            await operateProcessInstancePage.activeUserTaskIconVisibleAssertion(`state-overlay-${userTaskName}1-active`);
            await operateProcessInstancePage.activeUserTaskIconVisibleAssertion(`state-overlay-${userTaskName}2-active`);
            await operateProcessInstancePage.activeUserTaskIconNotVisibleAssertion(`state-overlay-${userTaskName}3-active`);
        });
    });
    (0, SM_8_8_1.test)('RBA Off User Flow', async ({ page, modelerHomePage, modelerCreatePage, taskPanelPage, navigationPage, taskProcessesPage, ocIdentityHomePage, ocIdentityAuthorizationsPage, }) => {
        SM_8_8_1.test.slow();
        const randomString = await (0, _setup_1.generateRandomStringAsync)(3);
        const processName = 'User_Task_Process_RBA_OFF_' + randomString + '_';
        await SM_8_8_1.test.step('Navigate to Identity', async () => {
            await navigationPage.goToOCIdentity();
            await ocIdentityHomePage.clickAuthorizationsTab();
            await ocIdentityAuthorizationsPage.clickProcessDefinitionTab();
            await (0, test_1.expect)(page.getByText(processName).first()).not.toBeVisible({
                timeout: 30000,
            });
        });
        await SM_8_8_1.test.step('Navigate to Web Modeler', async () => {
            await navigationPage.goToModeler();
        });
        await SM_8_8_1.test.step('Open Cross Component Test Project', async () => {
            await modelerHomePage.clickCrossComponentProjectFolder();
        });
        await SM_8_8_1.test.step('Create Two BPMN Diagrams with User Task and Start Process Instance', async () => {
            await (0, UtilitiesPage_1.runMultipleProcesses)(page, modelerHomePage, modelerCreatePage, 2, processName, processName);
        });
        await SM_8_8_1.test.step('Navigate to Tasklist and Make Sure that the Two Deployed Processes Are Accessible', async () => {
            await navigationPage.goToTasklist();
            await taskPanelPage.clickProcessesTab();
            await taskProcessesPage.clickpopupContinueButton();
            await taskProcessesPage.startProcess(processName + '1');
            await (0, test_1.expect)(page.getByText(`${processName}1`).last()).toBeVisible({
                timeout: 120000,
            });
            await taskPanelPage.clickProcessesTab();
            await taskProcessesPage.clickpopupContinueButton();
            await taskProcessesPage.startProcess(processName + '2');
            await (0, test_1.expect)(page.getByText(`${processName}2`).last()).toBeVisible({
                timeout: 120000,
            });
        });
    });
});
