"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const _8_10_1 = require("../../../fixtures/8.10");
const UtilitiesPage_1 = require("../../../pages/8.10/UtilitiesPage");
const _setup_1 = require("../../../test-setup.js");
const apiHelpers_1 = require("../../../utils/apiHelpers");
const users_1 = require("../../../utils/users");
const test_1 = require("@playwright/test");
const testUser = (0, users_1.getTestUser)('fourteenthUser');
let authToken;
let instanceKey;
_8_10_1.test.describe.configure({ mode: 'parallel' });
_8_10_1.test.describe('Orchestration Cluster MCP Server - Cluster Tools @tasklistV2', () => {
    const clusterName = 'Agentic Orchestration Cluster';
    _8_10_1.test.beforeAll(async () => {
        authToken = await (0, apiHelpers_1.authSaasAPI)(undefined, 'agentic_cluster');
        const processDefinitionKey = await (0, apiHelpers_1.deployProcess)('./resources/mcp_server_saas/mcp_cluster_tools.bpmn', authToken, 'saas', 'agentic_cluster');
        if (processDefinitionKey == null) {
            throw new Error('Failed to deploy cluster tools process');
        }
        instanceKey = await (0, apiHelpers_1.createProcessInstance)(String(processDefinitionKey), authToken, 'saas', 'agentic_cluster');
    });
    _8_10_1.test.beforeEach(async ({ page, loginPage }, testInfo) => {
        await (0, UtilitiesPage_1.loginWithRetry)(page, loginPage, testUser, (testInfo.workerIndex + 1) * 1000);
    });
    _8_10_1.test.afterEach(async ({ page }, testInfo) => {
        await (0, _setup_1.captureScreenshot)(page, testInfo);
        await (0, _setup_1.captureFailureVideo)(page, testInfo);
    });
    const clusterToolTests = [
        {
            name: 'getClusterStatus - returns cluster health status',
            variable: 'mcpResultClusterStatus',
            assertions: [
                {
                    text: 'HEALTHY',
                    description: 'cluster status response contains healthy field',
                },
            ],
        },
        {
            name: 'getTopology - returns cluster topology information',
            variable: 'mcpResultTopology',
            assertions: [
                { text: 'brokers', description: 'topology response contains brokers' },
                {
                    text: 'partitionsCount',
                    description: 'topology response contains partitions count',
                },
            ],
        },
    ];
    for (const testCase of clusterToolTests) {
        (0, _8_10_1.test)(testCase.name, async ({ homePage, appsPage, operateHomePage, operateProcessesPage, operateProcessInstancePage, }) => {
            _8_10_1.test.slow();
            await _8_10_1.test.step('Navigate to completed process in Operate', async () => {
                await homePage.clickClusters();
                await appsPage.clickOperate(clusterName);
                await (0, test_1.expect)(operateHomePage.operateBanner).toBeVisible({
                    timeout: 60000,
                });
                await operateHomePage.clickProcessesTab();
                await operateProcessesPage.clickProcessCompletedCheckbox();
                await operateProcessesPage.applyMoreFilters('Process Instance Key(s)', String(instanceKey));
                await operateProcessesPage.clickProcessInstanceLink('MCP Cluster tools');
                await operateProcessInstancePage.assertProcessCompleteStatusWithRetry();
            });
            for (const assertion of testCase.assertions) {
                await _8_10_1.test.step(`Verify ${assertion.description}`, async () => {
                    await operateProcessInstancePage.assertProcessVariableContainsText(testCase.variable, assertion.text);
                });
            }
        });
    }
});
