"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const test_1 = require("@playwright/test");
const _8_10_1 = require("../../fixtures/8.10");
const _setup_1 = require("../../test-setup.js");
const connectorSecrets_1 = require("../../utils/connectorSecrets");
const mcpSecrets_1 = require("../../utils/mcpSecrets");
const UtilitiesPage_1 = require("../../pages/8.10/UtilitiesPage");
const users_1 = require("../../utils/users");
_8_10_1.test.describe.configure({ mode: 'parallel' });
_8_10_1.test.describe('Cluster Setup Tests', () => {
    _8_10_1.test.afterEach(async ({ page }, testInfo) => {
        await (0, _setup_1.captureScreenshot)(page, testInfo);
        await (0, _setup_1.captureFailureVideo)(page, testInfo);
    });
    (0, _8_10_1.test)('Enable Alpha Features', async ({ page, loginPage, consoleOrganizationsPage, homePage, }, testInfo) => {
        _8_10_1.test.skip(process.env.IS_PROD === 'true', 'Skipping test because not required on PROD test org');
        _8_10_1.test.skip(process.env.IS_AG === 'true', 'Skipping test because not required when IS_AG is true');
        await (0, UtilitiesPage_1.loginWithRetry)(page, loginPage, users_1.testUsers.mainUser, (testInfo.workerIndex + 1) * 1000);
        await homePage.clickOrganization();
        await (0, UtilitiesPage_1.assertLocatorVisibleWithRetry)(page, consoleOrganizationsPage.settingsTab, 'settings tab', 60000, false, 2);
        await consoleOrganizationsPage.enableAlphaFeature('AI-powered features');
    });
    (0, _8_10_1.test)('Create Default Cluster', async ({ page, loginPage, homePage, clusterPage, clusterDetailsPage, clusterSecretsPage, }, testInfo) => {
        _8_10_1.test.slow();
        const clusterName = 'Test Cluster';
        const apiClientName = 'Test_API_Client' + (await (0, _setup_1.generateRandomStringAsync)(3));
        await (0, UtilitiesPage_1.loginWithRetry)(page, loginPage, users_1.testUsers.mainUser, (testInfo.workerIndex + 1) * 1000);
        await homePage.clickClusters();
        await clusterPage.createCluster(clusterName);
        await clusterPage.assertClusterHealthyStatusWithRetry(clusterName);
        await clusterPage.clickClusterLink(clusterName);
        await clusterDetailsPage.assertComponentsHealth();
        if (process.env.IS_AG !== 'true') {
            await clusterDetailsPage.clickAPITab();
            await clusterDetailsPage.createAPIClientAndReturnVariables(apiClientName);
            await clusterDetailsPage.clickCloseModalButton();
            await clusterPage.clickConnectorSecretsTab(clusterName);
            await clusterSecretsPage.createSetOfSecrets(clusterName, connectorSecrets_1.awsSecretsValues);
            await clusterSecretsPage.createSetOfSecrets(clusterName, connectorSecrets_1.openAiSecretsValues);
            await clusterSecretsPage.createSetOfSecrets(clusterName, connectorSecrets_1.gcpSecretsValues);
            await clusterSecretsPage.createSetOfSecrets(clusterName, connectorSecrets_1.azureSecretsValues);
            await clusterSecretsPage.createSetOfSecrets(clusterName, connectorSecrets_1.connectorSecretsValues);
            await clusterSecretsPage.createSetOfSecrets(clusterName, connectorSecrets_1.bedrockKbSecretsValues);
            await clusterSecretsPage.createSetOfSecrets(clusterName, connectorSecrets_1.agentcoreSecretsValues);
            await clusterSecretsPage.createSetOfSecrets(clusterName, connectorSecrets_1.agentcoreLtmSecretsValues);
            await clusterSecretsPage.createSetOfSecrets(clusterName, connectorSecrets_1.bedrockCodeInterpreterSecretsValues);
        }
    });
    (0, _8_10_1.test)('Create Agentic Orchestration Cluster', async ({ page, loginPage, homePage, clusterPage, clusterDetailsPage, clusterSecretsPage, }, testInfo) => {
        _8_10_1.test.skip(process.env.IS_PROD === 'true', 'Skipping test because not required on PROD test org');
        _8_10_1.test.skip(process.env.IS_AG === 'true', 'Skipping test because not required when IS_AG is true');
        _8_10_1.test.slow();
        const clusterName = 'Agentic Orchestration Cluster';
        const apiClientName = 'Test_API_Client' + (await (0, _setup_1.generateRandomStringAsync)(3));
        const mcpClientName = 'MCP_Test_API_Client' + (await (0, _setup_1.generateRandomStringAsync)(3));
        await (0, UtilitiesPage_1.loginWithRetry)(page, loginPage, users_1.testUsers.mainUser, (testInfo.workerIndex + 1) * 1000);
        await homePage.clickClusters();
        await clusterPage.createCluster(clusterName);
        await clusterPage.assertClusterHealthyStatusWithRetry(clusterName);
        await clusterPage.clickClusterLink(clusterName);
        await clusterDetailsPage.assertComponentsHealth();
        await clusterDetailsPage.clickSettingsTab();
        await clusterDetailsPage.checkMcpSupportToggle();
        await homePage.clickClusters();
        await clusterPage.assertClusterHealthyStatusWithRetry(clusterName);
        await clusterPage.clickClusterLink(clusterName);
        await clusterDetailsPage.clickAPITab();
        await clusterDetailsPage.createAPIClientAndReturnVariables(apiClientName, true, 'agentic_cluster');
        await clusterDetailsPage.clickCloseModalButton();
        const mcpCredentials = await clusterDetailsPage.createMCPClientAndReturnVariables(mcpClientName);
        await clusterDetailsPage.clickCloseModalButton();
        await clusterPage.clickConnectorSecretsTab(clusterName);
        await clusterSecretsPage.createSetOfSecrets(clusterName, (0, mcpSecrets_1.mcpSecretsValues)(mcpCredentials));
    });
    (0, _8_10_1.test)('Create AWS Cluster', async ({ page, loginPage, homePage, clusterPage, clusterDetailsPage, clusterSecretsPage, }, testInfo) => {
        _8_10_1.test.slow();
        const clusterName = 'AWS Cluster';
        await (0, UtilitiesPage_1.loginWithRetry)(page, loginPage, users_1.testUsers.mainUser, (testInfo.workerIndex + 1) * 1000);
        await homePage.clickClusters();
        await clusterPage.createCluster(clusterName, 'AWS');
        await clusterPage.assertClusterHealthyStatusWithRetry(clusterName, 300000);
        await clusterPage.clickClusterLink(clusterName);
        await clusterDetailsPage.assertComponentsHealth();
        if (process.env.IS_AG !== 'true') {
            await clusterPage.clickConnectorSecretsTab(clusterName);
            await clusterSecretsPage.createSetOfSecrets(clusterName, connectorSecrets_1.connectorSecretsValues);
        }
    });
    for (const [index, user] of (0, users_1.getTestUsers)().entries()) {
        (0, _8_10_1.test)(`Create Project Folder for User ${index + 1}`, async ({ page, loginPage, homePage, appsPage, modelerHomePage, }, testInfo) => {
            await _8_10_1.test.step('Log in', async () => {
                await (0, UtilitiesPage_1.loginWithRetry)(page, loginPage, user, (testInfo.workerIndex + 1) * 1000);
            });
            await _8_10_1.test.step('Navigate to Web Modeler', async () => {
                await (0, test_1.expect)(homePage.camundaComponentsButton).toBeVisible({
                    timeout: 120000,
                });
                await appsPage.clickCamundaApps();
                await appsPage.clickModeler();
                await (0, test_1.expect)(modelerHomePage.modelerPageBanner).toBeVisible({
                    timeout: 180000,
                });
            });
            await _8_10_1.test.step('Create Cross Component Project Folder', async () => {
                await homePage.clickSkipCustomization();
                await modelerHomePage.createCrossComponentProjectFolder();
                await modelerHomePage.clickHomeBreadcrumb();
                await (0, test_1.expect)(modelerHomePage.crossComponentProjectFolder).toBeVisible({
                    timeout: 60000,
                });
            });
        });
    }
});
