"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const test_1 = require("@playwright/test");
const SM_8_7_1 = require("../../fixtures/SM-8.7");
const _setup_1 = require("../../test-setup.js");
const UtlitiesPage_1 = require("../../pages/SM-8.7/UtlitiesPage");
const KeycloakUtils_1 = require("../../pages/SM-8.7/KeycloakUtils");
const loggingUtils_1 = require("../../utils/loggingUtils");
const env_1 = require("../../utils/env");
// OpenSearch indexes Zeebe events more slowly than Elasticsearch, so
// process/task names take longer to appear in Tasklist and Operate.
const taskVisibilityTimeout = env_1.isOpenSearch ? 240000 : 120000;
const processNameTimeout = env_1.isOpenSearch ? 180000 : 60000;
SM_8_7_1.test.describe.parallel('HTO User Flow Tests', () => {
    SM_8_7_1.test.beforeEach(async ({ navigationPage, identityPage, keycloakLoginPage, keycloakAdminPage, context, identityTenantPage, }, testInfo) => {
        // Set up test context for logging
        (0, loggingUtils_1.setupTestLogging)(testInfo);
        await context.clearCookies();
        const user1 = 'lisa' + (await (0, _setup_1.generateRandomStringAsync)(3)).toLowerCase();
        const user2 = 'bart' + (await (0, _setup_1.generateRandomStringAsync)(3)).toLowerCase();
        navigationPage.user1 = user1;
        navigationPage.user2 = user2;
        await (0, KeycloakUtils_1.createUser)(navigationPage, identityPage, keycloakLoginPage, keycloakAdminPage, user1, 'lisa', identityTenantPage);
        await context.clearCookies();
        await (0, KeycloakUtils_1.createUser)(navigationPage, identityPage, keycloakLoginPage, keycloakAdminPage, user2, 'bart', identityTenantPage);
        await context.clearCookies();
        await (0, KeycloakUtils_1.setupKeycloakUser)(navigationPage, identityPage, keycloakLoginPage, keycloakAdminPage, identityTenantPage);
    });
    SM_8_7_1.test.afterEach(async ({ page, context }, testInfo) => {
        await context.clearCookies();
        await (0, _setup_1.captureScreenshot)(page, testInfo);
        await (0, _setup_1.captureFailureVideo)(page, testInfo);
        // Clean up test context for logging
        (0, loggingUtils_1.cleanupTestLogging)();
    });
    (0, SM_8_7_1.test)('Job Worker User Task Most Common Flow', async ({ modelerHomePage, navigationPage, modelerCreatePage, operateHomePage, operateProcessesPage, taskDetailsPage, taskPanelPage, operateProcessInstancePage, page, context, }) => {
        SM_8_7_1.test.slow();
        const processName = 'User_Task_Process' + (await (0, _setup_1.generateRandomStringAsync)(3));
        await SM_8_7_1.test.step('Open Cross Component Test Project and Create a BPMN Diagram Template', async () => {
            await context.clearCookies();
            await navigationPage.goToModeler();
            await modelerHomePage.clickCreateNewProjectButton();
            await modelerHomePage.createCrossComponentProjectFolder();
            await modelerHomePage.clickDiagramTypeDropdown();
            await modelerHomePage.clickBpmnTemplateOption();
        });
        await SM_8_7_1.test.step('Create BPMN Diagram with User Task and Start Process Instance', async () => {
            await modelerCreatePage.modelJobWorkerDiagram(processName);
            await modelerCreatePage.runProcessInstance();
        });
        await SM_8_7_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.clickProcessInstanceLink(processName, 'completed');
            await operateProcessInstancePage.completedIconAssertion();
        });
    });
    (0, SM_8_7_1.test)('Zeebe User Task With Priority', async ({ page, modelerHomePage, modelerCreatePage, operateHomePage, operateProcessesPage, operateProcessInstancePage, taskDetailsPage, taskPanelPage, context, navigationPage, }) => {
        SM_8_7_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_7_1.test.step('Open Cross Component Test Project and Create a BPMN Diagram Template', async () => {
            await context.clearCookies();
            await navigationPage.goToModeler();
            await modelerHomePage.clickCreateNewProjectButton();
            await modelerHomePage.createCrossComponentProjectFolder();
            await modelerHomePage.clickDiagramTypeDropdown();
            await modelerHomePage.clickBpmnTemplateOption();
        });
        await SM_8_7_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 modelerCreatePage.addParallelUserTasks(4, taskName);
            await modelerCreatePage.clickAppendElementButton();
            await modelerCreatePage.clickAppendEndEventButton('parallelGateway');
            await modelerCreatePage.setPriority(taskName, 1, 4);
            await modelerCreatePage.runProcessInstance();
        });
        await SM_8_7_1.test.step('Complete User Task in Tasklist & assert process complete in Operate', async () => {
            await navigationPage.goToTasklist();
            await (0, test_1.expect)(page.getByText(processName).first()).toBeVisible({
                timeout: processNameTimeout,
            });
            await (0, UtlitiesPage_1.completeTaskWithRetry)(page, taskPanelPage, taskDetailsPage, `${taskName}4`, 'critical');
            await (0, UtlitiesPage_1.completeTaskWithRetry)(page, taskPanelPage, taskDetailsPage, `${taskName}3`, 'high');
            await (0, UtlitiesPage_1.completeTaskWithRetry)(page, taskPanelPage, taskDetailsPage, `${taskName}2`, 'medium');
            await (0, UtlitiesPage_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: processNameTimeout,
            });
            await taskDetailsPage.taskAssertion(processName);
            await taskDetailsPage.priorityAssertion('critical');
            await navigationPage.goToOperate();
            await operateHomePage.clickProcessesTab();
            await operateProcessesPage.clickProcessCompletedCheckbox();
            await operateProcessesPage.clickProcessInstanceLink(processName, 'completed');
            const result = await operateProcessInstancePage.assertEitherIncidentOrCompletedIconVisible();
            (0, test_1.expect)(result).toBe('completed');
        });
    });
    (0, SM_8_7_1.test)('User Task Editing Variables Flow', async ({ page, operateHomePage, modelerHomePage, navigationPage, modelerCreatePage, operateProcessesPage, operateProcessInstancePage, taskPanelPage, context, }) => {
        SM_8_7_1.test.slow();
        const processName = 'User_Task_Editing_Variables' + (await (0, _setup_1.generateRandomStringAsync)(3));
        await SM_8_7_1.test.step('Open Cross Component Test Project and Create a BPMN Diagram Template', async () => {
            await context.clearCookies();
            await navigationPage.goToModeler();
            await modelerHomePage.clickCreateNewProjectButton();
            await modelerHomePage.createCrossComponentProjectFolder();
            await modelerHomePage.clickDiagramTypeDropdown();
            await modelerHomePage.clickBpmnTemplateOption();
        });
        await SM_8_7_1.test.step('Create BPMN Diagram with User Task and Start Process Instance', async () => {
            await modelerCreatePage.modelCamundaUserTaskDiagram(processName);
            await modelerCreatePage.runProcessInstance('{"testVariable":"testValue"}');
        });
        await SM_8_7_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);
            const result = await operateProcessInstancePage.assertEitherIncidentOrActiveIconVisible();
            (0, test_1.expect)(result).toBe('active');
            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();
            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();
        });
    });
    (0, SM_8_7_1.test)('User Task Restrictions Enabled Flow - Candidate User', async ({ page, modelerHomePage, navigationPage, modelerCreatePage, operateHomePage, operateProcessInstancePage, taskDetailsPage, taskPanelPage, settingsPage, loginPage, context, }) => {
        SM_8_7_1.test.slow();
        const randomString = await (0, _setup_1.generateRandomStringAsync)(3);
        const userTaskName = 'candidateUserTask' + randomString;
        const processName = 'User_Task_Process_Candidate_User' + randomString;
        await SM_8_7_1.test.step('Open Cross Component Test Project and Create a BPMN Diagram Template', async () => {
            await context.clearCookies();
            await navigationPage.goToModeler();
            await modelerHomePage.clickCreateNewProjectButton();
            await modelerHomePage.createCrossComponentProjectFolder();
            await modelerHomePage.clickDiagramTypeDropdown();
            await modelerHomePage.clickBpmnTemplateOption();
        });
        await SM_8_7_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 modelerCreatePage.addParallelUserTasks(3, userTaskName);
            await modelerCreatePage.clickAppendElementButton();
            await modelerCreatePage.clickAppendEndEventButton('parallelGateway');
        });
        await SM_8_7_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(navigationPage.user1);
            await modelerCreatePage.clickAssigneeInput();
            await modelerCreatePage.fillAssigneeInput(navigationPage.activeUser);
            await modelerCreatePage.clickCanvas();
            await modelerCreatePage.selectUserTask(`${userTaskName}2`);
            await modelerCreatePage.expandAssignmentSection();
            await modelerCreatePage.clickCandidateUsersInput();
            await modelerCreatePage.fillCandidateUsersInput(navigationPage.activeUser);
            await modelerCreatePage.clickCanvas();
            await modelerCreatePage.selectUserTask(`${userTaskName}3`);
            await modelerCreatePage.expandAssignmentSection();
            await modelerCreatePage.clickCandidateUsersInput();
            await modelerCreatePage.fillCandidateUsersInput(navigationPage.user1);
            await modelerCreatePage.runProcessInstance();
        });
        await SM_8_7_1.test.step('View User Tasks in Tasklist', async () => {
            await navigationPage.goToTasklist();
            await (0, test_1.expect)(page.getByText(`${userTaskName}1`)).toBeVisible({
                timeout: taskVisibilityTimeout,
            });
            await (0, test_1.expect)(page.getByText(`${userTaskName}2`)).toBeVisible({
                timeout: taskVisibilityTimeout,
            });
            await (0, test_1.expect)(page.getByText(`${userTaskName}3`)).not.toBeVisible({
                timeout: taskVisibilityTimeout,
            });
        });
        await SM_8_7_1.test.step('Logout and Login with "lisa" User and Check Tasks in Tasklist', async () => {
            await settingsPage.clickOpenSettingsButton();
            await settingsPage.clickLogoutButton();
            await loginPage.fillUsername(navigationPage.user1);
            await (0, test_1.expect)(loginPage.usernameInput).toHaveValue(navigationPage.user1);
            await loginPage.fillPassword('lisa');
            await loginPage.clickLoginButton();
            await (0, test_1.expect)(taskPanelPage.tasklistBanner).toBeVisible({ timeout: 120000 });
        });
        await SM_8_7_1.test.step('Navigate to Tasklist and Assert User Tasks ', async () => {
            await (0, test_1.expect)(page.getByText(`${userTaskName}1`)).toBeVisible({
                timeout: taskVisibilityTimeout,
            });
            await (0, test_1.expect)(page.getByText(`${userTaskName}2`)).not.toBeVisible({
                timeout: taskVisibilityTimeout,
            });
            await (0, test_1.expect)(page.getByText(`${userTaskName}3`)).toBeVisible({
                timeout: taskVisibilityTimeout,
            });
        });
        await SM_8_7_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_7_1.test.step('Navigate to Operate and Assert Process Instance', async () => {
            await navigationPage.goToOperate();
            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_7_1.test)('User Task Restrictions Enabled Flow - Candidate Group', async ({ page, modelerHomePage, navigationPage, modelerCreatePage, operateHomePage, operateProcessInstancePage, taskDetailsPage, taskPanelPage, settingsPage, loginPage, identityPage, context, }) => {
        SM_8_7_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);
        await SM_8_7_1.test.step('Create Two User Groups in Identity', async () => {
            await context.clearCookies();
            await navigationPage.goToIdentity();
            await identityPage.clickGroupsTab();
            await identityPage.clickCreateGroupButton();
            await identityPage.fillGroupNameInput(groupNameSingle);
            await identityPage.clickCreateGroupSubButton();
            await (0, test_1.expect)(identityPage.createGroupDialoge).not.toBeVisible({
                timeout: 60000,
            });
            await identityPage.clickCreateGroupButton();
            await identityPage.fillGroupNameInput(groupNameMultiple);
            await identityPage.clickCreateGroupSubButton();
            await (0, test_1.expect)(identityPage.createGroupDialoge).not.toBeVisible({
                timeout: 60000,
            });
        });
        await SM_8_7_1.test.step('Assign Users to the Created Groups in Identity', async () => {
            await identityPage.clickUserGroup(groupNameSingle);
            await identityPage.clickAssignMembers();
            await identityPage.fillAssignMembers([navigationPage.activeUser]);
            await identityPage.clickAssignSubButton();
            await identityPage.clickGroupsTab();
            await identityPage.clickUserGroup(groupNameMultiple);
            await identityPage.clickAssignMembers();
            await identityPage.fillAssignMembers([
                navigationPage.user2,
                navigationPage.user1,
            ]);
            await identityPage.clickAssignSubButton();
        });
        await SM_8_7_1.test.step('Create a BPMN Diagram Template', async () => {
            await navigationPage.goToModeler();
            await modelerHomePage.clickCreateNewProjectButton();
            await modelerHomePage.createCrossComponentProjectFolder();
            await modelerHomePage.clickDiagramTypeDropdown();
            await modelerHomePage.clickBpmnTemplateOption();
        });
        await SM_8_7_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 modelerCreatePage.addParallelUserTasks(2, userTaskName);
            await modelerCreatePage.clickAppendElementButton();
            await modelerCreatePage.clickAppendEndEventButton('parallelGateway');
        });
        await SM_8_7_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 modelerCreatePage.clickAssigneeInput();
            await modelerCreatePage.fillAssigneeInput(navigationPage.user1);
            await modelerCreatePage.clickCanvas();
            await modelerCreatePage.selectUserTask(`${userTaskName}2`);
            await modelerCreatePage.expandAssignmentSection();
            await modelerCreatePage.clickCandidateGroupsInput();
            await modelerCreatePage.fillCandidateGroupsInput(groupNameMultiple);
            await modelerCreatePage.runProcessInstance();
        });
        await SM_8_7_1.test.step('View User Tasks in Tasklist', async () => {
            await navigationPage.goToTasklist();
            await (0, test_1.expect)(page.getByText(`${userTaskName}1`)).toBeVisible({
                timeout: taskVisibilityTimeout,
            });
            await (0, test_1.expect)(page.getByText(`${userTaskName}2`)).not.toBeVisible({
                timeout: taskVisibilityTimeout,
            });
        });
        await SM_8_7_1.test.step('Logout and Login with "lisa" User and Check Tasks in Tasklist', async () => {
            await settingsPage.clickOpenSettingsButton();
            await settingsPage.clickLogoutButton();
            await loginPage.fillUsername(navigationPage.user1);
            await (0, test_1.expect)(loginPage.usernameInput).toHaveValue(navigationPage.user1);
            await loginPage.fillPassword('lisa');
            await loginPage.clickLoginButton();
            await (0, test_1.expect)(taskPanelPage.tasklistBanner).toBeVisible({ timeout: 120000 });
        });
        await SM_8_7_1.test.step('Navigate to Tasklist and Assert User Tasks ', async () => {
            await (0, test_1.expect)(page.getByText(`${userTaskName}1`)).toBeVisible({
                timeout: taskVisibilityTimeout,
            });
            await (0, test_1.expect)(page.getByText(`${userTaskName}2`)).toBeVisible({
                timeout: taskVisibilityTimeout,
            });
        });
        await SM_8_7_1.test.step('Logout and Login with "bart" User and Check Tasks in Tasklist', async () => {
            await settingsPage.clickOpenSettingsButton();
            await settingsPage.clickLogoutButton();
            await loginPage.fillUsername(navigationPage.user2);
            await (0, test_1.expect)(loginPage.usernameInput).toHaveValue(navigationPage.user2);
            await loginPage.fillPassword('bart');
            await loginPage.clickLoginButton();
            await (0, test_1.expect)(taskPanelPage.tasklistBanner).toBeVisible({ timeout: 120000 });
        });
        await SM_8_7_1.test.step('Navigate to Tasklist and Assert User Tasks ', async () => {
            await (0, test_1.expect)(page.getByText(`${userTaskName}1`)).not.toBeVisible({
                timeout: taskVisibilityTimeout,
            });
            await (0, test_1.expect)(page.getByText(`${userTaskName}2`)).toBeVisible({
                timeout: taskVisibilityTimeout,
            });
        });
        await SM_8_7_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_7_1.test.step('Navigate to Operate and Assert Process Instance', async () => {
            await navigationPage.goToOperate();
            await operateHomePage.openProcess(processName);
            await operateProcessInstancePage.activeUserTaskIconVisibleAssertion(`state-overlay-${userTaskName}1-active`);
            await operateProcessInstancePage.activeUserTaskIconNotVisibleAssertion(`state-overlay-${userTaskName}2-active`);
        });
    });
    (0, SM_8_7_1.test)('RBA Off User Flow', async ({ page, identityPage, modelerHomePage, modelerCreatePage, taskPanelPage, navigationPage, taskProcessesPage, context, }) => {
        SM_8_7_1.test.slow();
        const randomString = await (0, _setup_1.generateRandomStringAsync)(3);
        const processName = 'User_Task_Process_RBA_OFF_' + randomString + '_';
        await SM_8_7_1.test.step('Navigate to Identity', async () => {
            await navigationPage.goToIdentity();
            await identityPage.clickUsersLink();
            await identityPage.clickDemoUser();
            await (0, test_1.expect)(identityPage.authorizationsTab).not.toBeVisible({
                timeout: 60000,
            });
        });
        await SM_8_7_1.test.step('Navigate to Web Modeler', async () => {
            await context.clearCookies();
            await navigationPage.goToModeler();
        });
        await SM_8_7_1.test.step('Open Cross Component Test Project', async () => {
            await modelerHomePage.clickCreateNewProjectButton();
            await modelerHomePage.createCrossComponentProjectFolder();
        });
        await SM_8_7_1.test.step('Create Two BPMN Diagrams with User Task and Start Process Instance', async () => {
            await (0, UtlitiesPage_1.runMultipleProcesses)(modelerHomePage, modelerCreatePage, 2, processName);
        });
        await SM_8_7_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 (0, test_1.expect)(page.getByText(`${processName}1`).last()).toBeVisible({
                timeout: taskVisibilityTimeout,
            });
            await (0, test_1.expect)(page.getByText(`${processName}2`).last()).toBeVisible({
                timeout: taskVisibilityTimeout,
            });
        });
    });
});
