"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const test_1 = require("@playwright/test");
const SM_8_6_1 = require("../../fixtures/SM-8.6");
const _setup_1 = require("../../test-setup.js");
const sleep_1 = require("../../utils/sleep");
const UtlitiesPage_1 = require("../../pages/SM-8.6/UtlitiesPage");
SM_8_6_1.test.describe.configure({ mode: 'parallel' });
SM_8_6_1.test.describe('HTO User Flow Tests', () => {
    SM_8_6_1.test.beforeEach(async ({ navigationPage }, testInfo) => {
        await navigationPage.goToModeler((testInfo.workerIndex + 1) * 1000);
    });
    SM_8_6_1.test.afterEach(async ({ page, navigationPage, identityPage }, testInfo) => {
        await (0, _setup_1.captureScreenshot)(page, testInfo);
        await (0, _setup_1.captureFailureVideo)(page, testInfo);
        if (testInfo.title.includes('Candidate Group')) {
            await (0, UtlitiesPage_1.deleteAllUserGroups)(navigationPage, identityPage);
        }
    });
    (0, SM_8_6_1.test)('Job Worker User Task Most Common Flow', async ({ modelerHomePage, navigationPage, modelerCreatePage, operateHomePage, operateProcessesPage, taskDetailsPage, taskPanelPage, operateProcessInstancePage, page, }) => {
        SM_8_6_1.test.slow();
        const processName = 'User_Task_Process' + (await (0, _setup_1.generateRandomStringAsync)(3));
        await SM_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 SM_8_6_1.test.step('Create BPMN Diagram with User Task and Start Process Instance', async () => {
            await modelerCreatePage.modelJobWorkerDiagram(processName);
            await modelerCreatePage.runProcessInstance();
        });
        await SM_8_6_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');
            const result = await operateProcessInstancePage.assertEitherIncidentOrCompletedIconVisible();
            (0, test_1.expect)(result).toBe('completed');
        });
    });
    (0, SM_8_6_1.test)('Zeebe User Task With Priority', async ({ page, modelerHomePage, navigationPage, modelerCreatePage, operateHomePage, operateProcessesPage, operateProcessInstancePage, taskDetailsPage, taskPanelPage, }) => {
        SM_8_6_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_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 SM_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 (0, sleep_1.sleep)(30000);
            await modelerCreatePage.runProcessInstance();
        });
        await SM_8_6_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: 60000,
            });
            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`);
            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)(5000);
            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_6_1.test)('User Task Editing Variables Flow', async ({ page, operateHomePage, modelerHomePage, navigationPage, modelerCreatePage, operateProcessesPage, operateProcessInstancePage, taskPanelPage, }) => {
        SM_8_6_1.test.slow();
        const processName = 'User_Task_Editing_Variables' + (await (0, _setup_1.generateRandomStringAsync)(3));
        await SM_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 SM_8_6_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_6_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();
            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();
        });
    });
    (0, SM_8_6_1.test)('User Task Restrictions Enabled Flow - Candidate User', async ({ page, modelerHomePage, navigationPage, modelerCreatePage, operateHomePage, operateProcessInstancePage, taskDetailsPage, taskPanelPage, settingsPage, loginPage, }) => {
        SM_8_6_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_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 SM_8_6_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.addParallelUserTasks(3, userTaskName);
            await modelerCreatePage.clickAppendElementButton();
            await modelerCreatePage.clickAppendEndEventButton('parallelGateway');
        });
        await SM_8_6_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('lisa');
            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('lisa');
            await (0, sleep_1.sleep)(1000);
            await modelerCreatePage.runProcessInstance();
        });
        await SM_8_6_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_6_1.test.step('Logout and Login with "lisa" User and Check Tasks in Tasklist', async () => {
            await settingsPage.clickOpenSettingsButton();
            await settingsPage.clickLogoutButton();
            await loginPage.fillUsername('lisa');
            await (0, test_1.expect)(loginPage.usernameInput).toHaveValue('lisa');
            await loginPage.fillPassword(process.env.DISTRO_QA_E2E_TESTS_IDENTITY_SECONDUSER_PASSWORD);
            await loginPage.clickLoginButton();
            await (0, test_1.expect)(taskPanelPage.tasklistBanner).toBeVisible({ timeout: 120000 });
        });
        await SM_8_6_1.test.step('Navigate to Tasklist and Assert User Tasks ', async () => {
            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_6_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_6_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_6_1.test)('User Task Restrictions Enabled Flow - Candidate Group', async ({ page, modelerHomePage, navigationPage, modelerCreatePage, operateHomePage, operateProcessInstancePage, taskDetailsPage, taskPanelPage, settingsPage, loginPage, identityPage, }) => {
        SM_8_6_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_6_1.test.step('Create Two User Groups in Identity', async () => {
            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_6_1.test.step('Assign Users to the Created Groups in Identity', async () => {
            await identityPage.clickUserGroup(groupNameSingle);
            await identityPage.clickAssignMembers();
            await identityPage.fillAssignMembers(['demo']);
            await identityPage.clickAssignSubButton();
            await identityPage.clickGroupsTab();
            await identityPage.clickUserGroup(groupNameMultiple);
            await identityPage.clickAssignMembers();
            await identityPage.fillAssignMembers(['bart', 'lisa']);
            await identityPage.clickAssignSubButton();
        });
        await SM_8_6_1.test.step('Create a BPMN Diagram Template', async () => {
            await navigationPage.goToModeler();
            await modelerHomePage.clickCrossComponentProjectFolder();
            await modelerHomePage.clickDiagramTypeDropdown();
            await modelerHomePage.clickBpmnTemplateOption();
        });
        await SM_8_6_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.addParallelUserTasks(2, userTaskName);
            await modelerCreatePage.clickAppendElementButton();
            await modelerCreatePage.clickAppendEndEventButton('parallelGateway');
        });
        await SM_8_6_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('lisa');
            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_6_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_6_1.test.step('Logout and Login with "lisa" User and Check Tasks in Tasklist', async () => {
            await settingsPage.clickOpenSettingsButton();
            await settingsPage.clickLogoutButton();
            await loginPage.fillUsername('lisa');
            await (0, test_1.expect)(loginPage.usernameInput).toHaveValue('lisa');
            await loginPage.fillPassword(process.env.DISTRO_QA_E2E_TESTS_IDENTITY_SECONDUSER_PASSWORD);
            await loginPage.clickLoginButton();
            await (0, test_1.expect)(taskPanelPage.tasklistBanner).toBeVisible({ timeout: 120000 });
        });
        await SM_8_6_1.test.step('Navigate to Tasklist and Assert User Tasks ', async () => {
            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_6_1.test.step('Logout and Login with "bart" User and Check Tasks in Tasklist', async () => {
            await settingsPage.clickOpenSettingsButton();
            await settingsPage.clickLogoutButton();
            await loginPage.fillUsername('bart');
            await (0, test_1.expect)(loginPage.usernameInput).toHaveValue('bart');
            await loginPage.fillPassword(process.env.DISTRO_QA_E2E_TESTS_IDENTITY_THIRDUSER_PASSWORD);
            await loginPage.clickLoginButton();
            await (0, test_1.expect)(taskPanelPage.tasklistBanner).toBeVisible({ timeout: 120000 });
        });
        await SM_8_6_1.test.step('Navigate to Tasklist and Assert User Tasks ', async () => {
            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_6_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_6_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_6_1.test)('RBA Off User Flow', async ({ page, identityPage, modelerHomePage, modelerCreatePage, taskPanelPage, navigationPage, taskProcessesPage, }) => {
        SM_8_6_1.test.slow();
        const randomString = await (0, _setup_1.generateRandomStringAsync)(3);
        const processName = 'User_Task_Process_RBA_OFF_' + randomString + '_';
        await SM_8_6_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_6_1.test.step('Navigate to Web Modeler', async () => {
            await navigationPage.goToModeler();
        });
        await SM_8_6_1.test.step('Open Cross Component Test Project', async () => {
            await modelerHomePage.clickCrossComponentProjectFolder();
        });
        await SM_8_6_1.test.step('Create Two BPMN Diagrams with User Task and Start Process Instance', async () => {
            await (0, UtlitiesPage_1.runMultipleProcesses)(page, modelerHomePage, modelerCreatePage, 2, processName);
        });
        await SM_8_6_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: 120000,
            });
            await (0, test_1.expect)(page.getByText(`${processName}2`).last()).toBeVisible({
                timeout: 120000,
            });
        });
    });
});
