"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const test_1 = require("@playwright/test");
const _8_7_1 = require("../../fixtures/8.7");
const _setup_1 = require("../../test-setup.js");
const UtilitiesPage_1 = require("../../pages/8.7/UtilitiesPage");
const randomName_1 = require("../../utils/randomName");
const fileUpload_1 = require("../../utils/fileUpload");
const sleep_1 = require("../../utils/sleep");
const users_1 = require("../../utils/users");
const testUser = (0, users_1.getTestUser)('twentiethUser');
_8_7_1.test.describe.configure({ mode: 'parallel' });
_8_7_1.test.describe('IDP User Flow Tests', () => {
    const clusterName = 'Test Cluster';
    _8_7_1.test.beforeEach(async ({ page, loginPage }, testInfo) => {
        await (0, UtilitiesPage_1.loginWithRetry)(page, loginPage, testUser, (testInfo.workerIndex + 1) * 1000);
    });
    _8_7_1.test.afterEach(async ({ page }, testInfo) => {
        await (0, _setup_1.captureScreenshot)(page, testInfo);
        await (0, _setup_1.captureFailureVideo)(page, testInfo);
    });
    //Skipped due to bug 5858: https://github.com/camunda/connectors/issues/5858
    _8_7_1.test.skip('User creates an idp application with a document extraction template', async ({ page, homePage, modelerHomePage, appsPage, clusterPage, clusterSecretsPage, idpCreatePage, }) => {
        _8_7_1.test.slow();
        const idpApplicationName = await (0, randomName_1.randomNameAgregator)('IDP_Application_Name');
        const idpDocumentExtractionTemplateName = await (0, randomName_1.randomNameAgregator)('IDP_Extraction_Template_Name');
        await _8_7_1.test.step('Navigate to Cluster Secrets', async () => {
            await (0, test_1.expect)(homePage.clusterTab).toBeVisible();
            await homePage.clickClusters();
            await (0, test_1.expect)(page.getByText('Redirecting')).not.toBeVisible({
                timeout: 60000,
            });
            await clusterPage.clickClusterLink(clusterName);
            await (0, sleep_1.sleep)(10000);
            await clusterPage.clickConnectorSecretesTab(clusterName);
        });
        await _8_7_1.test.step('Delete Connector Secrets If Exist', async () => {
            await clusterSecretsPage.deleteConnectorSecretsIfExist();
        });
        await _8_7_1.test.step('Create Cluster Secret', async () => {
            await clusterSecretsPage.clickCreateNewSecretButton(clusterName);
            await clusterSecretsPage.clickKeyInput();
            await clusterSecretsPage.fillKeyInput('IDP_AWS_REGION');
            await clusterSecretsPage.clickValueInput();
            await clusterSecretsPage.fillValueInput(process.env.IDP_AWS_REGION);
            await clusterSecretsPage.clickCreateButton();
            await (0, test_1.expect)(page.getByText('Creating...')).not.toBeVisible({
                timeout: 60000,
            });
            await (0, test_1.expect)(clusterSecretsPage.createNewSecretButton).toBeVisible({
                timeout: 30000,
            });
            await clusterSecretsPage.clickCreateNewSecretButton(clusterName);
            await clusterSecretsPage.clickKeyInput();
            await clusterSecretsPage.fillKeyInput('IDP_AWS_BUCKET_NAME');
            await clusterSecretsPage.clickValueInput();
            await clusterSecretsPage.fillValueInput(process.env.IDP_AWS_BUCKET_NAME);
            await clusterSecretsPage.clickCreateButton();
            await (0, test_1.expect)(page.getByText('Creating...')).not.toBeVisible({
                timeout: 60000,
            });
            await (0, test_1.expect)(clusterSecretsPage.createNewSecretButton).toBeVisible({
                timeout: 30000,
            });
            await clusterSecretsPage.clickCreateNewSecretButton(clusterName);
            await clusterSecretsPage.clickKeyInput();
            await clusterSecretsPage.fillKeyInput('IDP_AWS_SECRETKEY');
            await clusterSecretsPage.clickValueInput();
            await clusterSecretsPage.fillValueInput(process.env.IDP_AWS_SECRETKEY);
            await clusterSecretsPage.clickCreateButton();
            await (0, test_1.expect)(page.getByText('Creating...')).not.toBeVisible({
                timeout: 60000,
            });
            await (0, test_1.expect)(clusterSecretsPage.createNewSecretButton).toBeVisible({
                timeout: 30000,
            });
            await clusterSecretsPage.clickCreateNewSecretButton(clusterName);
            await clusterSecretsPage.clickKeyInput();
            await clusterSecretsPage.fillKeyInput('IDP_AWS_ACCESSKEY');
            await clusterSecretsPage.clickValueInput();
            await clusterSecretsPage.fillValueInput(process.env.IDP_AWS_ACCESSKEY);
            await clusterSecretsPage.clickCreateButton();
            await (0, test_1.expect)(page.getByText('Creating...')).not.toBeVisible({
                timeout: 60000,
            });
        });
        await _8_7_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: 120000,
            });
        });
        await _8_7_1.test.step('Navigate to Cross Component Test Project', async () => {
            await modelerHomePage.clickCrossComponentProjectFolder();
        });
        await _8_7_1.test.step('Add an IDP application to the project', async () => {
            await modelerHomePage.clickDiagramTypeDropdown();
            await modelerHomePage.clickIdpApplicationTemplateOption();
            await modelerHomePage.enterIdpApplicationName(idpApplicationName);
            await modelerHomePage.selectCluster(clusterName);
            await modelerHomePage.clickCreateIdpApplicationButton();
        });
        await _8_7_1.test.step('Creates a document extraction template', async () => {
            await idpCreatePage.clickCreateIdpTemplateButton();
            await idpCreatePage.fillIdpExtractionTemplateName(idpDocumentExtractionTemplateName);
            await idpCreatePage.clickCreateIdpExtractationTemplateButton();
        });
        await _8_7_1.test.step('Upload a file for extraction', async () => {
            await idpCreatePage.clickUploadFilesButton();
            await (0, fileUpload_1.uploadFile)(page, ['idp/idp_sample_bank_statement.pdf']);
            await idpCreatePage.clickExtractButton();
        });
        await _8_7_1.test.step('Add a field for extraction and extract the data', async () => {
            await idpCreatePage.fillExtractFieldName('bank_account_number');
            await idpCreatePage.fillPromptField();
            await idpCreatePage.clickAddExtractionFieldButton();
            await idpCreatePage.selectExtractionModelOption('Claude Sonnet 4');
            await idpCreatePage.clickExtractDocumentButton();
            await (0, test_1.expect)(page.getByText('Extracting...')).not.toBeVisible({
                timeout: 120000,
            });
        });
        await _8_7_1.test.step('Save extracted data as a test case', async () => {
            await idpCreatePage.clickSaveAsTestCaseButton();
            await idpCreatePage.clickCloseToastNotification();
        });
        await _8_7_1.test.step('Validate extraction', async () => {
            await idpCreatePage.clickValidateExtractionTab();
            await idpCreatePage.clickExpandAllRowsButton();
            await idpCreatePage.assertPassTestCaseResultsRow();
        });
        await _8_7_1.test.step('Publish the IDP application to project', async () => {
            await idpCreatePage.clickPublishButton();
            await idpCreatePage.clickPublishToProjecOption();
            await idpCreatePage.fillVersionFieldName(idpApplicationName);
            await idpCreatePage.fillVersionFieldDescription(idpApplicationName);
            await idpCreatePage.clickPublishButtonModal();
            await idpCreatePage.assertIdpSuccessPublishNotification();
        });
    });
});
