"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 KeycloakUtils_1 = require("../../pages/SM-8.7/KeycloakUtils");
const loggingUtils_1 = require("../../utils/loggingUtils");
const UtlitiesPage_1 = require("../../pages/SM-8.7/UtlitiesPage");
SM_8_7_1.test.describe.configure({ mode: 'parallel' });
SM_8_7_1.test.describe('Deploy and run a process in Play', () => {
    SM_8_7_1.test.beforeEach(async ({ navigationPage, identityPage, identityTenantPage, keycloakLoginPage, keycloakAdminPage, }, 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)('User Tasks and Service Task', async ({ page, modelerHomePage, modelerCreatePage, playPage, context, navigationPage, }) => {
        const randomString = await (0, _setup_1.generateRandomStringAsync)(3);
        const processName = 'Play_Test_Process' + randomString;
        await SM_8_7_1.test.step('Open Cross Component Test Project', async () => {
            await context.clearCookies();
            await navigationPage.goToModeler();
            await modelerHomePage.clickCreateNewProjectButton();
            await modelerHomePage.createCrossComponentProjectFolder();
        });
        await SM_8_7_1.test.step('Create a BPMN Diagram with user tasks and service task', async () => {
            await (0, UtlitiesPage_1.modelDiagramFromFile)(page, modelerHomePage, modelerCreatePage, processName, 'Play_Test_User_Service_Task');
        });
        await SM_8_7_1.test.step('Open Play', async () => {
            await modelerCreatePage.switchToPlay();
            await modelerCreatePage.completePlayConfiguration();
        });
        await SM_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('play-user-task');
            await playPage.waitForCompleteJobButtonToBeAvailable();
            await playPage.clickCompleteJobButton();
            await playPage.waitForNextElementToBeActive('play-service-task');
            await playPage.waitForCompleteJobButtonToBeAvailable();
            await playPage.clickCompleteJobButton();
            await playPage.waitForProcessToBeCompleted();
        });
    });
    (0, SM_8_7_1.test)('Create,update and delete test scenarios in play', async ({ modelerHomePage, modelerCreatePage, playPage, context, navigationPage, page, }) => {
        // This test has two Play configuration switches, each with up to 180s timeout
        SM_8_7_1.test.slow();
        const randomString = await (0, _setup_1.generateRandomStringAsync)(3);
        const processName = 'Play_Test_Process' + randomString;
        const scenarioName = 'My first scenario' + randomString;
        const updatedScenarioName = 'My first scenario-updated' + randomString;
        await SM_8_7_1.test.step('Open Cross Component Test Project', async () => {
            await context.clearCookies();
            await navigationPage.goToModeler();
            await modelerHomePage.clickCreateNewProjectButton();
            await modelerHomePage.createCrossComponentProjectFolder();
        });
        await SM_8_7_1.test.step('Add A BPMN Template To The Project', async () => {
            await modelerHomePage.clickDiagramTypeDropdown();
            await modelerHomePage.clickBpmnTemplateOption();
        });
        await SM_8_7_1.test.step('Create a BPMN Diagram with simple start and end event', async () => {
            await (0, test_1.expect)(modelerCreatePage.generalPanel).toBeVisible({
                timeout: 120000,
            });
            await modelerCreatePage.enterDiagramName(processName);
            await modelerCreatePage.addParallelUserTasks(1, 'zeebe-user-task' + randomString);
            await modelerCreatePage.clickSecondPlacedGateway();
            await modelerCreatePage.clickAppendElementButton();
            await modelerCreatePage.clickAppendEndEventButton('parallelGateway');
            await (0, test_1.expect)(modelerCreatePage.generalPanel).toBeVisible({
                timeout: 30000,
            });
            // Wait for modeler background auto-save network requests to complete
            // before switching to Play, which deploys the current saved version.
            await page.waitForLoadState('networkidle');
        });
        await SM_8_7_1.test.step('Open Play', async () => {
            await modelerCreatePage.switchToPlay();
            await modelerCreatePage.completePlayConfiguration();
        });
        await SM_8_7_1.test.step('Start and complete the process instance in Play and save scenario', async () => {
            await playPage.dismissStartModal();
            await playPage.clickStartInstanceButton();
            await playPage.waitForInstanceDetailsToBeLoaded();
            await playPage.waitForNextElementToBeActive('zeebe-user-task' + randomString + '1');
            await playPage.waitForCompleteJobButtonToBeAvailable();
            await playPage.clickCompleteJobButton();
            await playPage.waitForProcessToBeCompleted();
            await playPage.clickSaveScenarioButton();
            await playPage.enterScenarioName(scenarioName);
            await playPage.confirmSaveScenario();
            await (0, test_1.expect)(playPage.saveScenarioModal).toBeHidden({ timeout: 10000 });
        });
        await SM_8_7_1.test.step('Update the saved scenario', async () => {
            await modelerCreatePage.switchToImplementTab();
            await (0, test_1.expect)(modelerCreatePage.generalPanel).toBeVisible({
                timeout: 30000,
            });
            await modelerCreatePage.clickFirstPlacedGateway();
            await modelerCreatePage.clickAppendElementButton();
            await modelerCreatePage.clickAppendTaskButton();
            await modelerCreatePage.clickConnectToOtherElementButton();
            await modelerCreatePage.clickSecondPlacedGateway();
            await (0, test_1.expect)(modelerCreatePage.generalPanel).toBeVisible({
                timeout: 30000,
            });
            // Wait for modeler background auto-save network requests to complete.
            await page.waitForLoadState('networkidle');
            await modelerCreatePage.switchToPlay();
            await modelerCreatePage.completePlayConfiguration();
            await playPage.clickStartInstanceButton();
            await playPage.waitForNextElementToBeActive('zeebe-user-task' + randomString + '1');
            await playPage.waitForCompleteJobButtonToBeAvailable();
            await playPage.clickCompleteJobButton();
            await playPage.waitForProcessToBeCompleted();
            await playPage.clickSaveScenarioButton();
            await playPage.enterScenarioName(updatedScenarioName);
            await playPage.confirmSaveScenario();
            await modelerCreatePage.assertScenarioNameVisible(updatedScenarioName);
        });
        await SM_8_7_1.test.step('Run all scenarios', async () => {
            await playPage.clickViewAllScenariosButton();
            await playPage.clickRunAllScenariosButton();
            await playPage.assertScenarioCompleted(scenarioName);
            await playPage.assertScenarioCompleted(updatedScenarioName);
        });
        await SM_8_7_1.test.step('Delete test scenario', async () => {
            await playPage.deleteScenario(scenarioName);
            await playPage.confirmDeleteScenario();
            await (0, test_1.expect)(page.locator('tr').filter({
                has: page.getByText(scenarioName, {
                    exact: true,
                }),
            })).toHaveCount(0);
        });
    });
});
