"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");
SM_8_7_1.test.describe.parallel('Web Modeler User Flow Tests', () => {
    SM_8_7_1.test.beforeEach(async ({ navigationPage, identityPage, keycloakLoginPage, keycloakAdminPage, identityTenantPage, }, testInfo) => {
        (0, loggingUtils_1.setupTestLogging)(testInfo);
        await (0, KeycloakUtils_1.setupKeycloakUser)(navigationPage, identityPage, keycloakLoginPage, keycloakAdminPage, identityTenantPage);
    });
    SM_8_7_1.test.afterEach(async ({ page }, testInfo) => {
        await (0, _setup_1.captureScreenshot)(page, testInfo);
        await (0, _setup_1.captureFailureVideo)(page, testInfo);
        (0, loggingUtils_1.cleanupTestLogging)();
    });
    (0, SM_8_7_1.test)('Form.js Integration with User Task', async ({ context, taskDetailsPage, taskPanelPage, modelerHomePage, navigationPage, modelerCreatePage, operateHomePage, operateProcessesPage, operateProcessInstancePage, page, }) => {
        const randomString = await (0, _setup_1.generateRandomStringAsync)(3);
        const processName = 'User_Task_Process_With_Form' + randomString;
        const formName = 'New form' + randomString;
        await SM_8_7_1.test.step('Open Cross Component Test Project and Create a Simple Form', async () => {
            await context.clearCookies();
            await navigationPage.goToModeler(1000);
            await modelerHomePage.clickCreateNewProjectButton();
            await modelerHomePage.createCrossComponentProjectFolder();
            await modelerHomePage.clickDiagramTypeDropdown();
            await modelerHomePage.clickFormOption();
            await modelerHomePage.enterFormName(formName);
        });
        await SM_8_7_1.test.step('Add A BPMN Template To The Project', async () => {
            await modelerHomePage.clickProjectBreadcrumb();
            await modelerHomePage.clickDiagramTypeDropdown();
            await modelerHomePage.clickBpmnTemplateOption();
        });
        await SM_8_7_1.test.step('Create BPMN Diagram with a User Task with an embedded Form and Start Process Instance', async () => {
            await modelerCreatePage.modelCamundaUserTaskDiagram(processName, '', formName);
            await modelerCreatePage.runProcessInstance();
        });
        await SM_8_7_1.test.step('View Process Instance in Operate and complete User Task in Tasklist', async () => {
            await navigationPage.goToOperate();
            await operateHomePage.clickProcessesTab();
            await operateProcessesPage.clickProcessInstanceLink(processName);
            await operateProcessInstancePage.activeIconAssertion();
            await navigationPage.goToTasklist();
            await page.reload();
            await taskPanelPage.openTask(processName);
            await (0, UtlitiesPage_1.completeTaskWithRetry)(page, taskPanelPage, taskDetailsPage, processName, 'medium');
        });
    });
    (0, SM_8_7_1.test)('Form.js Integration with Start form', async ({ context, modelerHomePage, modelerCreatePage, navigationPage, operateHomePage, operateProcessesPage, operateProcessInstancePage, }) => {
        const randomString = await (0, _setup_1.generateRandomStringAsync)(3);
        const processName = 'Start_Form_Process' + randomString;
        const formName = 'New form' + randomString;
        await SM_8_7_1.test.step('Open Cross Component Test Project and Create a Simple Form', async () => {
            await context.clearCookies();
            await navigationPage.goToModeler(1000);
            await modelerHomePage.clickCreateNewProjectButton();
            await modelerHomePage.createCrossComponentProjectFolder();
            await modelerHomePage.clickDiagramTypeDropdown();
            await modelerHomePage.clickFormOption();
            await modelerHomePage.enterFormName(formName);
        });
        await SM_8_7_1.test.step('Add A BPMN Template To The Project', async () => {
            await modelerHomePage.clickProjectBreadcrumb();
            await modelerHomePage.clickDiagramTypeDropdown();
            await modelerHomePage.clickBpmnTemplateOption();
        });
        await SM_8_7_1.test.step('Create BPMN Diagram with a start event with an linked Form and Start Process Instance', async () => {
            await (0, test_1.expect)(modelerCreatePage.generalPanel).toBeVisible({
                timeout: 120000,
            });
            await modelerCreatePage.enterDiagramName(processName);
            await modelerCreatePage.hoverOnStartEvent();
            await modelerCreatePage.clickEmbedFormButton();
            await modelerCreatePage.clickForm(formName);
            await modelerCreatePage.clickEmbedButton();
            await modelerCreatePage.clickAppendElementButton();
            await modelerCreatePage.clickAppendEndEventButton();
            await modelerCreatePage.runProcessInstance();
        });
        await SM_8_7_1.test.step('View Process Instance in Operate and check if process is complete', async () => {
            await navigationPage.goToOperate();
            await operateHomePage.clickProcessesTab();
            await operateProcessesPage.clickProcessInstanceLink(processName, 'completed');
            await operateProcessInstancePage.completedIconAssertion();
        });
    });
    (0, SM_8_7_1.test)('Timer Event User Flow', async ({ context, modelerHomePage, modelerCreatePage, operateHomePage, operateProcessInstancePage, operateProcessesPage, navigationPage, }) => {
        const processName = 'Timer_Event_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(1000);
            await modelerHomePage.clickCreateNewProjectButton();
            await modelerHomePage.createCrossComponentProjectFolder();
            await modelerHomePage.clickDiagramTypeDropdown();
            await modelerHomePage.clickBpmnTemplateOption();
        });
        await SM_8_7_1.test.step('Create BPMN Diagram with Timer Event and Deploy Diagram', async () => {
            await (0, test_1.expect)(modelerCreatePage.generalPanel).toBeVisible({
                timeout: 120000,
            });
            await modelerCreatePage.enterDiagramName(processName);
            await modelerCreatePage.clickAppendElementButton();
            await modelerCreatePage.clickIntermediateBoundaryEvent();
            await modelerCreatePage.clickChangeTypeButton();
            await modelerCreatePage.clickTimerEventOption();
            await modelerCreatePage.clickTimerEventSettings();
            await modelerCreatePage.selectTimerType('timeDuration');
            await modelerCreatePage.clickTimerValue();
            await modelerCreatePage.fillTimerValue('PT5S');
            await modelerCreatePage.clickAppendElementButton();
            await modelerCreatePage.clickAppendEndEventButton();
            await modelerCreatePage.runProcessInstance();
        });
        await SM_8_7_1.test.step('Assert Diagram Has Successfully Completed in Operate', async () => {
            await navigationPage.goToOperate();
            await (0, test_1.expect)(operateHomePage.processesTab).toBeVisible({ timeout: 120000 });
            await operateHomePage.clickProcessesTab();
            await operateProcessesPage.clickProcessInstanceLink(processName, 'completed');
            const result = await operateProcessInstancePage.assertEitherIncidentOrCompletedIconVisible();
            (0, test_1.expect)(result).toBe('completed');
        });
    });
});
