"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const _setup_1 = require("../../test-setup.js");
const SM_8_10_1 = require("../../fixtures/SM-8.10");
const test_1 = require("@playwright/test");
const sleep_1 = require("../../utils/sleep");
const UtilitiesPage_1 = require("../../pages/SM-8.10/UtilitiesPage");
if (process.env.IS_MIGRATION === 'true') {
    SM_8_10_1.test.describe.configure({ mode: 'parallel' });
    SM_8_10_1.test.describe('Migration Path Tests', () => {
        SM_8_10_1.test.beforeEach(async ({ navigationPage }, testInfo) => {
            await navigationPage.goToManagementIdentity((testInfo.workerIndex + 1) * 1000);
        });
        SM_8_10_1.test.afterEach(async ({ page }, testInfo) => {
            await (0, _setup_1.captureScreenshot)(page, testInfo);
            await (0, _setup_1.captureFailureVideo)(page, testInfo);
        });
        (0, SM_8_10_1.test)('Basic Navigation', async ({ navigationPage }) => {
            await SM_8_10_1.test.step('Assert Web Modeler Navigation', async () => {
                await navigationPage.goToModeler();
            });
            await SM_8_10_1.test.step('Assert Tasklist Navigation', async () => {
                await navigationPage.goToTasklist();
            });
            await SM_8_10_1.test.step('Assert Operate Navigation', async () => {
                await navigationPage.goToOperate();
            });
            await SM_8_10_1.test.step('Assert Optimize Navigation', async () => {
                await navigationPage.goToOptimize();
            });
            await SM_8_10_1.test.step('Assert OC Identity Navigation', async () => {
                await navigationPage.goToOCAdmin();
            });
        });
        // Skipped due to bug #56406: https://github.com/camunda/camunda/issues/56406
        SM_8_10_1.test.skip('Assert Most Common Flow User Flow With All Apps Process Migration', async ({ page, navigationPage, operateHomePage, operateProcessesPage, operateProcessInstancePage, optimizeHomePage, optimizeCollectionsPage, optimizeReportPage, taskPanelPage, }) => {
            SM_8_10_1.test.slow();
            const processName = 'Zeebe_User_Task_Process';
            await SM_8_10_1.test.step('View Process Instance in Operate', async () => {
                await navigationPage.goToOperate();
                await (0, test_1.expect)(operateHomePage.processesTab).toBeVisible({
                    timeout: 120000,
                });
                await operateHomePage.clickProcessesTab();
                await operateProcessesPage.clickProcessCompletedCheckbox();
                await operateProcessesPage.clickProcessInstanceLinkWithPartialNameMatch(processName);
                await operateProcessInstancePage.completedIconAssertion();
            });
            await SM_8_10_1.test.step('View Process Instance in Tasklist', async () => {
                await navigationPage.goToTasklist();
                await taskPanelPage.filterBy('Completed');
                await taskPanelPage.clickCollapseFilter();
                await (0, test_1.expect)(page.getByRole('heading', { name: 'completed' })).toBeVisible({
                    timeout: 45000,
                });
                await (0, test_1.expect)(page.getByText(processName).first()).toBeVisible({
                    timeout: 60000,
                });
            });
            await SM_8_10_1.test.step('View Report in Optimize', async () => {
                await navigationPage.goToOptimize();
                // Re-open the Collections list on every attempt: the migrated report
                // only renders in the Collections entity list, while a bare page
                // reload returns to the Optimize home dashboard. Polling that just
                // reloads the page therefore never re-surfaces the report once the
                // first check misses during post-upgrade import lag.
                const maxRefreshes = 20;
                for (let attempt = 0; attempt < maxRefreshes; attempt++) {
                    await optimizeHomePage.clickCollectionsLink();
                    try {
                        await optimizeCollectionsPage.reportAuthor.waitFor({
                            state: 'visible',
                            timeout: 15000,
                        });
                        break;
                    }
                    catch {
                        await page.reload();
                        await page.waitForLoadState('domcontentloaded');
                    }
                }
                await (0, test_1.expect)(optimizeCollectionsPage.reportAuthor).toBeVisible({
                    timeout: 60000,
                });
                await optimizeCollectionsPage.clickFirstProcessReport();
                await optimizeReportPage.waitUntilLocatorIsVisible(optimizeReportPage.oneUserTaskInstance, page);
                await (0, test_1.expect)(optimizeReportPage.oneUserTaskInstance).toBeVisible({
                    timeout: 90000,
                });
            });
        });
        // Skipped due to bug #320: https://github.com/camunda/marketplace-api/issues/320
        SM_8_10_1.test.skip('Assert REST Connector Process Migration @tasklistV2', async ({ page, operateHomePage, navigationPage, operateProcessesPage, operateProcessInstancePage, }) => {
            SM_8_10_1.test.slow();
            const processName = 'REST_Connector_Basic_Auth_Process';
            await SM_8_10_1.test.step('View Process Instance in Operate, assert it completes and assert result expression', async () => {
                await navigationPage.goToOperate();
                await operateHomePage.clickProcessesTab();
                await operateProcessesPage.clickProcessCompletedCheckbox();
                await operateProcessesPage.clickProcessInstanceLinkWithPartialNameMatch(processName);
                await operateProcessInstancePage.completedIconAssertion();
                await (0, test_1.expect)(page.getByTestId('variables-list')).toBeVisible({
                    timeout: 60000,
                });
                (0, test_1.expect)((await operateProcessInstancePage.connectorResultVariableName('message')).isVisible()).toBeTruthy();
                await (0, test_1.expect)(page
                    .getByTestId('variable-message')
                    .getByText('"Message from Mock!"')).toBeVisible({ timeout: 60000 });
            });
        });
        (0, SM_8_10_1.test)('Assert Users Persist in Management Identity With Correct Roles @tasklistV2', async ({ managementIdentityPage, identityUsersPage, }) => {
            await managementIdentityPage.clickUsersLink();
            await identityUsersPage.assertUserIsAssignedCorrectRole('demo', [
                'Default user role',
                'ManagementIdentity',
                'Optimize',
                'Orchestration',
                'Web Modeler',
                'Web Modeler Admin',
            ]);
            await managementIdentityPage.clickUsersLink();
            await identityUsersPage.assertUserIsAssignedCorrectRole('bart', [
                'Default user role',
                'ManagementIdentity',
                'Optimize',
                'Orchestration',
                'Web Modeler',
                'Web Modeler Admin',
            ]);
            await managementIdentityPage.clickUsersLink();
            await identityUsersPage.assertUserIsAssignedCorrectRole('lisa', [
                'Default user role',
                'ManagementIdentity',
                'Optimize',
                'Orchestration',
                'Web Modeler',
                'Web Modeler Admin',
            ]);
        });
        (0, SM_8_10_1.test)('Assert Demo User Can Deploy Processes', async ({ page, modelerHomePage, navigationPage, modelerCreatePage, operateHomePage, operateProcessesPage, operateProcessInstancePage, taskDetailsPage, taskPanelPage, }) => {
            SM_8_10_1.test.slow();
            const randomName = await (0, _setup_1.generateRandomStringAsync)(3);
            const processName = 'Demo_User_Process' + randomName;
            await SM_8_10_1.test.step('Open Cross Component Test Project and Create a BPMN Diagram Template', async () => {
                await navigationPage.goToModeler();
                await modelerHomePage.clickCrossComponentProjectFolder();
                await modelerHomePage.clickDiagramTypeDropdown();
                await modelerHomePage.clickBpmnTemplateOption();
            });
            await SM_8_10_1.test.step('Create BPMN Diagram with Zeebe User Task and Start Process Instance', async () => {
                await modelerCreatePage.modelCamundaUserTaskDiagram(processName);
                await modelerCreatePage.runProcessInstance();
                await (0, sleep_1.sleep)(20000);
            });
            await SM_8_10_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 (0, UtilitiesPage_1.completeTaskWithRetry)(page, taskPanelPage, taskDetailsPage, processName, 'medium');
                await navigationPage.goToOperate();
                await (0, test_1.expect)(operateHomePage.processesTab).toBeVisible({
                    timeout: 120000,
                });
                await operateHomePage.clickProcessesTab();
                await operateProcessesPage.clickProcessInstanceLink(processName, 'completed');
                await operateProcessInstancePage.completedIconAssertion();
            });
        });
        (0, SM_8_10_1.test)('Assert Lisa User Can Deploy Processes', async ({ page, modelerHomePage, navigationPage, modelerCreatePage, operateHomePage, operateProcessesPage, operateProcessInstancePage, taskDetailsPage, taskPanelPage, loginPage, managementIdentityPage, }) => {
            SM_8_10_1.test.slow();
            const randomName = await (0, _setup_1.generateRandomStringAsync)(3);
            const processName = 'Lisa_User_Process' + randomName;
            await SM_8_10_1.test.step('Logout and Login with "lisa" User', async () => {
                await managementIdentityPage.clickOpenSidebarButton();
                await managementIdentityPage.clickLogoutButton();
                await loginPage.login('lisa', process.env.DISTRO_QA_E2E_TESTS_IDENTITY_SECONDUSER_PASSWORD);
            });
            await SM_8_10_1.test.step('Open Cross Component Test Project and Create a BPMN Diagram Template', async () => {
                await navigationPage.goToModeler();
                await modelerHomePage.createCrossComponentProjectFolder();
                await modelerHomePage.clickDiagramTypeDropdown();
                await modelerHomePage.clickBpmnTemplateOption();
            });
            await SM_8_10_1.test.step('Create BPMN Diagram with Zeebe User Task and Start Process Instance', async () => {
                await modelerCreatePage.modelCamundaUserTaskDiagram(processName);
                await modelerCreatePage.runProcessInstance();
                await (0, sleep_1.sleep)(20000);
            });
            await SM_8_10_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 (0, UtilitiesPage_1.completeTaskWithRetry)(page, taskPanelPage, taskDetailsPage, processName, 'medium');
                await navigationPage.goToOperate();
                await (0, test_1.expect)(operateHomePage.processesTab).toBeVisible({
                    timeout: 120000,
                });
                await operateHomePage.clickProcessesTab();
                await operateProcessesPage.clickProcessInstanceLink(processName, 'completed');
                await operateProcessInstancePage.completedIconAssertion();
            });
        });
        (0, SM_8_10_1.test)('Assert Bart User Can Deploy Processes', async ({ page, modelerHomePage, navigationPage, modelerCreatePage, operateHomePage, operateProcessesPage, operateProcessInstancePage, taskDetailsPage, taskPanelPage, loginPage, managementIdentityPage, }) => {
            SM_8_10_1.test.slow();
            const randomName = await (0, _setup_1.generateRandomStringAsync)(3);
            const processName = 'Bart_User_Process' + randomName;
            await SM_8_10_1.test.step('Logout and Login with "bart" User', async () => {
                await managementIdentityPage.clickOpenSidebarButton();
                await managementIdentityPage.clickLogoutButton();
                await loginPage.login('bart', process.env.DISTRO_QA_E2E_TESTS_IDENTITY_THIRDUSER_PASSWORD);
            });
            await SM_8_10_1.test.step('Open Cross Component Test Project and Create a BPMN Diagram Template', async () => {
                await navigationPage.goToModeler();
                await modelerHomePage.createCrossComponentProjectFolder();
                await modelerHomePage.clickDiagramTypeDropdown();
                await modelerHomePage.clickBpmnTemplateOption();
            });
            await SM_8_10_1.test.step('Create BPMN Diagram with Zeebe User Task and Start Process Instance', async () => {
                await modelerCreatePage.modelCamundaUserTaskDiagram(processName);
                await modelerCreatePage.runProcessInstance();
                await (0, sleep_1.sleep)(20000);
            });
            await SM_8_10_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 (0, UtilitiesPage_1.completeTaskWithRetry)(page, taskPanelPage, taskDetailsPage, processName, 'medium');
                await navigationPage.goToOperate();
                await (0, test_1.expect)(operateHomePage.processesTab).toBeVisible({
                    timeout: 120000,
                });
                await operateHomePage.clickProcessesTab();
                await operateProcessesPage.clickProcessInstanceLink(processName, 'completed');
                await operateProcessInstancePage.completedIconAssertion();
            });
        });
    });
}
