"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const test_1 = require("@playwright/test");
const c8Run_8_6_1 = require("../../fixtures/c8Run-8.6");
const zeebeClient_1 = require("../../utils/zeebeClient");
const UtilitiesPage_1 = require("../../pages/c8Run-8.6/UtilitiesPage");
const sleep_1 = require("../../utils/sleep");
const _setup_1 = require("../../test-setup.js");
c8Run_8_6_1.test.beforeAll(async () => {
    await Promise.all([
        (0, zeebeClient_1.deploy)('./resources/Job_Worker_Process.bpmn'),
        (0, zeebeClient_1.deploy)('./resources/Variable_Process.bpmn'),
        (0, zeebeClient_1.deploy)('./resources/Zeebe_User_Task.bpmn'),
        (0, zeebeClient_1.deploy)('./resources/New Form.form'),
        (0, zeebeClient_1.deploy)('./resources/User_Task_Process_With_Form.bpmn'),
        (0, zeebeClient_1.deploy)('./resources/Start_Form_Process.bpmn'),
        (0, zeebeClient_1.deploy)('./resources/Zeebe_User_Task_Process_With_Priority.bpmn'),
    ]);
    await Promise.all([
        (0, zeebeClient_1.createInstances)('Job_Worker_Process', 1, 1),
        (0, zeebeClient_1.createInstances)('Zeebe_User_Task', 1, 1),
        (0, zeebeClient_1.createInstances)('Variable_Process', 1, 1, {
            testVariable: 'testValue',
        }),
        (0, zeebeClient_1.createInstances)('Form_User_Task', 1, 1),
        (0, zeebeClient_1.createInstances)('Start_Form_Process', 1, 1),
        (0, zeebeClient_1.createInstances)('Zeebe_User_Task_Process_With_Priority', 1, 1),
    ]);
});
//Skipped due to bug 46814: https://github.com/camunda/camunda/issues/46814
c8Run_8_6_1.test.describe.skip('HTO User Flow Tests', () => {
    c8Run_8_6_1.test.beforeEach(async ({ page, taskListLoginPage, taskPanelPage }) => {
        await (0, UtilitiesPage_1.navigateToApp)(page, 'tasklist');
        await taskListLoginPage.login('demo', 'demo');
        await taskPanelPage.taskListBannerIsVisible();
    });
    c8Run_8_6_1.test.afterEach(async ({ page }, testInfo) => {
        await (0, _setup_1.captureScreenshot)(page, testInfo);
        await (0, _setup_1.captureFailureVideo)(page, testInfo);
    });
    (0, c8Run_8_6_1.test)('User Task Most Common Flow', async ({ operateLoginPage, operateHomePage, operateProcessesPage, taskDetailsPage, taskPanelPage, operateProcessInstancePage, taskListLoginPage, page, }) => {
        await c8Run_8_6_1.test.step('View Process Instance in Operate, complete User Task in Tasklist & assert process complete in Operate', async () => {
            await (0, UtilitiesPage_1.navigateToApp)(page, 'operate');
            await operateLoginPage.login('demo', 'demo');
            await operateHomePage.operateBannerIsVisible();
            await (0, test_1.expect)(operateHomePage.processesTab).toBeVisible({ timeout: 180000 });
            await operateHomePage.clickProcessesTab();
            await operateProcessesPage.clickProcessInstanceLink('Job_Worker_Process');
            await operateProcessInstancePage.activeIconAssertion();
            await (0, UtilitiesPage_1.navigateToApp)(page, 'tasklist');
            await taskListLoginPage.login('demo', 'demo');
            await taskPanelPage.openTask('Job_Worker_Process');
            await taskDetailsPage.clickAssignToMeButton();
            await taskDetailsPage.clickCompleteTaskButton();
            await (0, test_1.expect)(page.getByText('Task completed')).toBeVisible({
                timeout: 200000,
            });
            await (0, UtilitiesPage_1.navigateToApp)(page, 'operate');
            await operateLoginPage.login('demo', 'demo');
            await (0, test_1.expect)(operateHomePage.processesTab).toBeVisible({ timeout: 120000 });
            await operateHomePage.clickProcessesTab();
            await operateProcessesPage.clickProcessCompletedCheckbox();
            await (0, sleep_1.sleep)(10000);
            await operateProcessesPage.clickProcessInstanceLink('Job_Worker_Process');
            await operateProcessInstancePage.completedIconAssertion();
        });
    });
    (0, c8Run_8_6_1.test)('User Task Editing Variables Flow', async ({ page, operateHomePage, operateProcessesPage, operateProcessInstancePage, taskPanelPage, taskListLoginPage, operateLoginPage, taskDetailsPage, }) => {
        await c8Run_8_6_1.test.step('View Process Instance in Operate, Edit the Variable & Assert the Variable is Updated in Tasklist', async () => {
            await (0, UtilitiesPage_1.navigateToApp)(page, 'operate');
            await operateLoginPage.login('demo', 'demo');
            await (0, test_1.expect)(operateHomePage.processesTab).toBeVisible({ timeout: 180000 });
            await operateHomePage.clickProcessesTab();
            await operateProcessesPage.clickProcessInstanceLink('Variable_Process');
            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 (0, UtilitiesPage_1.navigateToApp)(page, 'tasklist');
            await taskListLoginPage.login('demo', 'demo');
            await taskPanelPage.openTask('Variable_Process');
            await taskDetailsPage.clickAssignToMeButton();
            await (0, test_1.expect)(page.getByText('Assigning...')).not.toBeVisible({
                timeout: 90000,
            });
            await (0, test_1.expect)(page.getByText('testVariable', { exact: true })).toBeVisible();
            await taskDetailsPage.assertVariableValue('testVariable', '"updatedValue"');
            await taskDetailsPage.clickCompleteTaskButton();
            await (0, test_1.expect)(page.getByText('Task completed')).toBeVisible({
                timeout: 200000,
            });
        });
    });
    (0, c8Run_8_6_1.test)('Form.js Integration with User Task', async ({ taskDetailsPage, taskPanelPage, operateHomePage, operateProcessesPage, operateProcessInstancePage, taskListLoginPage, operateLoginPage, page, }) => {
        await c8Run_8_6_1.test.step('View Process Instance in Operate and complete User Task in Tasklist', async () => {
            await (0, UtilitiesPage_1.navigateToApp)(page, 'operate');
            await operateLoginPage.login('demo', 'demo');
            await (0, test_1.expect)(operateHomePage.processesTab).toBeVisible({ timeout: 180000 });
            await operateHomePage.clickProcessesTab();
            await operateProcessesPage.clickProcessInstanceLink('Form_User_Task');
            await operateProcessInstancePage.activeIconAssertion();
            await (0, UtilitiesPage_1.navigateToApp)(page, 'tasklist');
            await taskListLoginPage.login('demo', 'demo');
            await taskPanelPage.openTask('Form_User_Task');
            await taskDetailsPage.clickAssignToMeButton();
            await taskDetailsPage.clickTextInput();
            await taskDetailsPage.fillTextInput('Test User');
            await taskDetailsPage.clickCompleteTaskButton();
            await (0, test_1.expect)(page.getByText('Task completed')).toBeVisible({
                timeout: 200000,
            });
            await (0, UtilitiesPage_1.navigateToApp)(page, 'operate');
            await operateLoginPage.login('demo', 'demo');
            await operateHomePage.clickProcessesTab();
            await operateProcessesPage.clickProcessCompletedCheckbox();
            await (0, sleep_1.sleep)(1000);
            await operateProcessesPage.clickProcessInstanceLink('Form_User_Task');
            await operateProcessInstancePage.completedIconAssertion();
        });
    });
    (0, c8Run_8_6_1.test)('Form.js Integration with Start form', async ({ operateHomePage, operateProcessesPage, operateProcessInstancePage, page, operateLoginPage, }) => {
        await c8Run_8_6_1.test.step('View Process Instance in Operate and check if process is complete', async () => {
            await (0, UtilitiesPage_1.navigateToApp)(page, 'operate');
            await operateLoginPage.login('demo', 'demo');
            await (0, test_1.expect)(operateHomePage.processesTab).toBeVisible({ timeout: 180000 });
            await operateHomePage.clickProcessesTab();
            await operateProcessesPage.clickProcessCompletedCheckbox();
            await (0, sleep_1.sleep)(1000);
            await operateProcessesPage.clickProcessInstanceLink('Start_Form_Process');
            await operateProcessInstancePage.completedIconAssertion();
        });
    });
    (0, c8Run_8_6_1.test)('Zeebe User Task User Flow', async ({ page, operateHomePage, operateProcessesPage, operateProcessInstancePage, taskDetailsPage, taskPanelPage, operateLoginPage, taskListLoginPage, }) => {
        await c8Run_8_6_1.test.step('View Process Instance in Operate, complete User Task in Tasklist', async () => {
            await (0, UtilitiesPage_1.navigateToApp)(page, 'operate');
            await operateLoginPage.login('demo', 'demo');
            await operateHomePage.clickProcessesTab();
            await operateProcessesPage.clickProcessInstanceLink('Zeebe_User_Task');
            await operateProcessInstancePage.activeIconAssertion();
            await (0, UtilitiesPage_1.navigateToApp)(page, 'tasklist');
            await taskListLoginPage.login('demo', 'demo');
            await (0, test_1.expect)(page.getByText('Zeebe_User_Task').first()).toBeVisible({
                timeout: 60000,
            });
            await (0, UtilitiesPage_1.completeTaskWithRetry)(taskPanelPage, taskDetailsPage, 'Zeebe_User_Task', 'Medium');
            await (0, UtilitiesPage_1.navigateToApp)(page, 'operate');
            await operateLoginPage.login('demo', 'demo');
            await (0, test_1.expect)(operateHomePage.processesTab).toBeVisible({ timeout: 120000 });
            await operateHomePage.clickProcessesTab();
            await operateProcessesPage.clickProcessCompletedCheckbox();
            await page.reload();
            await operateProcessesPage.clickProcessInstanceLink('Zeebe_User_Task');
            await operateProcessInstancePage.completedIconAssertion();
        });
    });
    (0, c8Run_8_6_1.test)('Zeebe User Task With Priority', async ({ page, operateHomePage, operateProcessesPage, operateProcessInstancePage, taskDetailsPage, taskPanelPage, operateLoginPage, }) => {
        await c8Run_8_6_1.test.step('Complete User Task in Tasklist & assert process complete in Operate', async () => {
            await (0, test_1.expect)(page.getByText('Zeebe_User_Task_Process_With_Priority').first()).toBeVisible({ timeout: 60000 });
            await (0, UtilitiesPage_1.completeTaskWithRetry)(taskPanelPage, taskDetailsPage, 'priorityTest4', 'critical');
            await (0, UtilitiesPage_1.completeTaskWithRetry)(taskPanelPage, taskDetailsPage, 'priorityTest3', 'high');
            await (0, UtilitiesPage_1.completeTaskWithRetry)(taskPanelPage, taskDetailsPage, 'priorityTest2', 'medium');
            await (0, UtilitiesPage_1.completeTaskWithRetry)(taskPanelPage, taskDetailsPage, 'priorityTest1', 'low');
            await taskPanelPage.filterBy('Completed');
            await (0, test_1.expect)(page.getByRole('heading', { name: 'completed' })).toBeVisible({
                timeout: 45000,
            });
            await taskPanelPage.clickCollapseFilter();
            await page.reload();
            await taskPanelPage.openTask('priorityTest4');
            await (0, test_1.expect)(page.getByText('Zeebe_User_Task_Process_With_Priority').first()).toBeVisible({ timeout: 60000 });
            await taskDetailsPage.taskAssertion('Zeebe_User_Task_Process_With_Priority');
            await taskDetailsPage.priorityAssertion('critical');
            await (0, UtilitiesPage_1.navigateToApp)(page, 'operate');
            await operateLoginPage.login('demo', 'demo');
            await operateHomePage.clickProcessesTab();
            await operateProcessesPage.clickProcessCompletedCheckbox();
            await page.reload();
            await operateProcessesPage.clickProcessInstanceLink('Zeebe_User_Task_Process_With_Priority');
            await operateProcessInstancePage.completedIconAssertion();
        });
    });
});
