"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
 * SaaS Migration Path User Flows (8.8 → 8.9)
 *
 * This test suite focuses on UI upgrade automation and basic validation.
 * Comprehensive functionality validation is handled by smoke test comparison
 * rather than custom data validation to avoid code duplication.
 *
 * The complete upgrade testing flow:
 * 1. Pre-upgrade: Infrastructure setup + smoke test baseline capture
 * 2. Upgrade UI: This file's @saasUpgrade test (UI automation)
 * 3. Post-upgrade: Smoke test comparison for comprehensive validation
 *
 */
const _setup_1 = require("../../test-setup.js");
const _8_9_1 = require("../../fixtures/8.9");
const test_1 = require("@playwright/test");
const UtilitiesPage_1 = require("../../pages/8.9/UtilitiesPage");
const users_1 = require("../../utils/users");
// For SaaS upgrade testing, use dynamically created organization owner credentials
// For regular testing, fall back to predefined test user
const testUser = process.env.IS_MIGRATION === 'true'
    ? {
        username: process.env.C8_USERNAME,
        password: process.env.C8_PASSWORD,
    }
    : (0, users_1.getTestUser)('twentyFirstUser');
_8_9_1.test.describe('SaaS Migration Path Tests', () => {
    _8_9_1.test.beforeEach(async ({ page, loginPage }, testInfo) => {
        // Skip if not in migration mode
        if (process.env.IS_MIGRATION !== 'true') {
            _8_9_1.test.skip(true, 'Skipping migration tests outside of migration mode');
        }
        await (0, UtilitiesPage_1.loginWithRetry)(page, loginPage, testUser, (testInfo.workerIndex + 1) * 1000);
    });
    _8_9_1.test.afterEach(async ({ page }, testInfo) => {
        await (0, _setup_1.captureScreenshot)(page, testInfo);
        await (0, _setup_1.captureFailureVideo)(page, testInfo);
    });
    (0, _8_9_1.test)('SaaS UI Upgrade Flow Automation @saasUpgrade', async ({ homePage, clusterPage, clusterDetailsPage, }) => {
        await homePage.clickClusters();
        await clusterPage.clickClusterLink('Test Cluster');
        await clusterDetailsPage.performClusterUpdate();
        await homePage.clickClusters();
        await clusterPage.assertClusterHealthyStatusWithRetry('Test Cluster');
        await (0, test_1.expect)(clusterPage.clusterVersion('Test Cluster', '8.9')).toBeVisible();
    });
    (0, _8_9_1.test)('Basic Navigation After SaaS Upgrade', async ({ homePage, appsPage, modelerHomePage, operateHomePage, optimizeHomePage, taskPanelPage, ocIdentityHomePage, }) => {
        const clusterName = 'Test Cluster';
        await _8_9_1.test.step('Assert Web Modeler Navigation', async () => {
            await appsPage.clickCamundaApps();
            await appsPage.clickModeler();
            await (0, test_1.expect)(modelerHomePage.modelerPageBanner).toBeVisible({
                timeout: 120000,
            });
            await modelerHomePage.clickMessageBanner();
        });
        await _8_9_1.test.step('Assert Console Navigation', async () => {
            await appsPage.clickCamundaApps();
            await appsPage.clickConsoleLink();
            await (0, test_1.expect)(homePage.consoleBanner).toBeVisible({
                timeout: 120000,
            });
        });
        await _8_9_1.test.step('Assert Operate Navigation', async () => {
            await appsPage.clickCamundaApps();
            await appsPage.clickOperate(clusterName);
            await (0, test_1.expect)(operateHomePage.operateBanner).toBeVisible({
                timeout: 120000,
            });
        });
        await _8_9_1.test.step('Assert Optimize Navigation', async () => {
            await appsPage.clickCamundaApps();
            await appsPage.clickOptimize(clusterName);
            await (0, test_1.expect)(optimizeHomePage.optimizeBanner).toBeVisible({
                timeout: 120000,
            });
        });
        await _8_9_1.test.step('Assert Tasklist Navigation', async () => {
            await appsPage.clickCamundaApps();
            await appsPage.clickTasklist(clusterName);
            await (0, test_1.expect)(taskPanelPage.taskListPageBanner).toBeVisible({
                timeout: 120000,
            });
        });
        await _8_9_1.test.step('Assert Admin Navigation', async () => {
            await appsPage.clickCamundaApps();
            await appsPage.clickAdmin(clusterName);
            await (0, test_1.expect)(ocIdentityHomePage.adminBanner).toBeVisible({
                timeout: 120000,
            });
        });
    });
    (0, _8_9_1.test)('Assert Process Instances Persist After SaaS Upgrade', async ({ page, appsPage, operateHomePage, operateProcessesPage, operateProcessInstancePage, optimizeHomePage, optimizeReportPage, taskPanelPage, }) => {
        _8_9_1.test.slow();
        // Use the same fixed names that were created in the pre-upgrade smoke tests
        const processName = 'Zeebe_User_Task_ProcessUpgradeTest';
        const task1Name = 'zeebeUserTaskWithFormUpgradeTest1';
        const task2Name = 'zeebeUserTaskWithFormUpgradeTest2';
        const reportName = 'UpgradeTestReport';
        const clusterName = 'Test Cluster';
        await _8_9_1.test.step('View Process Instance in Operate', async () => {
            await appsPage.clickCamundaApps();
            await appsPage.clickOperate(clusterName);
            await (0, test_1.expect)(operateHomePage.processesTab).toBeVisible({
                timeout: 120000,
            });
            await operateHomePage.clickProcessesTab();
            await operateProcessesPage.clickProcessCompletedCheckbox();
            await operateProcessesPage.clickProcessInstanceLink(processName);
            await operateProcessInstancePage.assertProcessCompleteStatusWithRetry();
        });
        await _8_9_1.test.step('View Process Instance in Tasklist', async () => {
            await appsPage.clickCamundaApps();
            await appsPage.clickTasklist(clusterName);
            await taskPanelPage.filterBy('Completed');
            await (0, test_1.expect)(page.getByRole('heading', { name: 'completed' })).toBeVisible({
                timeout: 45000,
            });
            await (0, test_1.expect)(page.getByText(task1Name)).toBeVisible({
                timeout: 60000,
            });
            await (0, test_1.expect)(page.getByText(task2Name)).toBeVisible({
                timeout: 60000,
            });
        });
        await _8_9_1.test.step('View Report in Optimize', async () => {
            await appsPage.clickCamundaApps();
            await appsPage.clickOptimize(clusterName);
            await optimizeHomePage.clickCollectionsLink();
            // Look for the specific report created during pre-upgrade smoke tests
            await (0, test_1.expect)(page.getByText(reportName)).toBeVisible({
                timeout: 60000,
            });
            await page.getByText(reportName).click();
            await optimizeReportPage.waitUntilLocatorIsVisible(optimizeReportPage.oneUserTaskInstance.first(), page);
            await (0, test_1.expect)(optimizeReportPage.oneUserTaskInstance.first()).toBeVisible({
                timeout: 90000,
            });
        });
    });
    (0, _8_9_1.test)('Assert SaaS Organization Data Persists After Upgrade', async ({ page, appsPage, homePage, consoleOrganizationsPage, }) => {
        await _8_9_1.test.step('Verify Organization Settings Persist', async () => {
            await appsPage.clickCamundaApps();
            await appsPage.clickConsoleLink();
            await homePage.organizationTab.click();
        });
        await _8_9_1.test.step('Verify User Roles and Permissions Persist', async () => {
            await consoleOrganizationsPage.clickUsersTab();
            // Verify existing users still have correct roles
            await (0, test_1.expect)(page.getByRole('cell', { name: 'Owner' })).toBeVisible();
            await (0, test_1.expect)(page.getByRole('cell', { name: 'Developer' })).toBeVisible();
            await (0, test_1.expect)(page.getByRole('cell', { name: 'Modeler' })).toBeVisible();
            await (0, test_1.expect)(page.getByRole('cell', { name: 'Admin' })).toBeVisible();
        });
    });
    (0, _8_9_1.test)('Assert Connectors Still Function After SaaS Upgrade @tasklistV2', async ({ operateHomePage, appsPage, operateProcessesPage, operateProcessInstancePage, }) => {
        _8_9_1.test.slow();
        // Use the same fixed name that was created in the pre-upgrade smoke tests
        const processName = 'REST_Connector_Basic_Auth_ProcessUpgradeTest';
        const clusterName = 'Test Cluster';
        await _8_9_1.test.step('View Connector Process Instance in Operate', async () => {
            await appsPage.clickCamundaApps();
            await appsPage.clickOperate(clusterName);
            await operateHomePage.clickProcessesTab();
            await operateProcessesPage.clickProcessCompletedCheckbox();
            await operateProcessesPage.clickProcessInstanceLink(processName);
            await operateProcessInstancePage.assertProcessCompleteStatusWithRetry();
            await (0, test_1.expect)(operateProcessInstancePage.variablesList).toBeVisible({
                timeout: 60000,
            });
            await (0, test_1.expect)(operateProcessInstancePage.connectorResultVariableName('message')).toBeVisible({ timeout: 60000 });
            await (0, test_1.expect)(operateProcessInstancePage.messageVariable.getByText('"Message from Mock!"')).toBeVisible({ timeout: 60000 });
        });
    });
});
