"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const test_1 = require("@playwright/test");
const _8_7_1 = require("../../fixtures/8.7");
const _setup_1 = require("../../test-setup.js");
const sleep_1 = require("../../utils/sleep");
const UtilitiesPage_1 = require("../../pages/8.7/UtilitiesPage");
const users_1 = require("../../utils/users");
const testUser = (0, users_1.getTestUser)('twentyFourthUser');
const defaultClusterName = 'Test Cluster';
_8_7_1.test.describe.configure({ mode: 'parallel' });
_8_7_1.test.describe('Deploy and run a process in Play', () => {
    _8_7_1.test.beforeEach(async ({ page, loginPage }, testInfo) => {
        await (0, UtilitiesPage_1.loginWithRetry)(page, loginPage, testUser, (testInfo.workerIndex + 1) * 1000);
    });
    _8_7_1.test.afterEach(async ({ page }, testInfo) => {
        await (0, _setup_1.captureScreenshot)(page, testInfo);
        await (0, _setup_1.captureFailureVideo)(page, testInfo);
    });
    (0, _8_7_1.test)('User Tasks and Service Task', async ({ modelerHomePage, modelerCreatePage, playPage, homePage, appsPage, }) => {
        _8_7_1.test.slow();
        const randomString = await (0, _setup_1.generateRandomStringAsync)(3);
        const processName = 'Play_Test_Process' + randomString;
        await _8_7_1.test.step('Navigate to Web Modeler', async () => {
            await (0, test_1.expect)(homePage.camundaComponentsButton).toBeVisible({
                timeout: 40000,
            });
            await appsPage.clickCamundaApps();
            await appsPage.clickModeler();
            await (0, test_1.expect)(modelerHomePage.modelerPageBanner).toBeVisible({
                timeout: 120000,
            });
        });
        await _8_7_1.test.step('Open Cross Component Test Project', async () => {
            await modelerHomePage.clickCrossComponentProjectFolder();
        });
        await _8_7_1.test.step('Add A BPMN Template To The Project', async () => {
            await modelerHomePage.clickDiagramTypeDropdown();
            await modelerHomePage.clickBpmnTemplateOption();
        });
        await _8_7_1.test.step('Create a BPMN Diagram with user tasks and service task', async () => {
            await (0, test_1.expect)(modelerCreatePage.generalPanel).toBeVisible({
                timeout: 120000,
            });
            await modelerCreatePage.enterDiagramName(processName);
            await (0, sleep_1.sleep)(20000);
            await modelerCreatePage.clickAppendElementButton();
            await modelerCreatePage.clickAppendTaskButton();
            await modelerCreatePage.clickChangeTypeButton();
            await modelerCreatePage.clickUserTaskOption();
            await modelerCreatePage.chooseImplementationOption('jobWorker');
            await modelerCreatePage.clickGeneralPropertiesPanel();
            await modelerCreatePage.clickIdInput();
            await modelerCreatePage.fillIdInput('tasklist-user-task' + randomString);
            await modelerCreatePage.clickAppendElementButton();
            await modelerCreatePage.clickAppendTaskButton();
            await modelerCreatePage.clickChangeTypeButton();
            await modelerCreatePage.clickUserTaskOption();
            await modelerCreatePage.clickIdInput();
            await modelerCreatePage.fillIdInput('zeebe-user-task' + randomString);
            await modelerCreatePage.clickAppendElementButton();
            await modelerCreatePage.clickAppendTaskButton();
            await modelerCreatePage.clickChangeTypeButton();
            await modelerCreatePage.clickServiceTaskOption();
            await modelerCreatePage.clickIdInput();
            await modelerCreatePage.fillIdInput('service-task' + randomString);
            await modelerCreatePage.clickTaskDefinitionPropertiesPanel();
            await modelerCreatePage.clickJobTypeInput();
            await modelerCreatePage.fillJobTypeInput('someJob' + randomString);
            await modelerCreatePage.clickAppendElementButton();
            await modelerCreatePage.clickAppendEndEventButton();
            await (0, sleep_1.sleep)(60000);
        });
        await _8_7_1.test.step('Open Play', async () => {
            await modelerCreatePage.switchToPlay();
            await modelerCreatePage.completePlayConfiguration(defaultClusterName);
        });
        await _8_7_1.test.step('Start and complete the process instance in Play', async () => {
            await playPage.dismissStartModal();
            await playPage.clickStartInstanceButton();
            await playPage.waitForInstanceDetailsToBeLoaded();
            await playPage.waitForNextElementToBeActive('tasklist-user-task' + randomString);
            await playPage.waitForCompleteJobButtonToBeAvailable();
            await playPage.clickCompleteJobButton();
            await playPage.waitForNextElementToBeActive('zeebe-user-task' + randomString);
            await playPage.waitForCompleteJobButtonToBeAvailable();
            await playPage.clickCompleteJobButton();
            await playPage.waitForNextElementToBeActive('service-task' + randomString);
            await playPage.waitForCompleteJobButtonToBeAvailable();
            await playPage.clickCompleteJobButton();
            await playPage.waitForProcessToBeCompleted();
        });
    });
});
