"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const test_1 = require("@playwright/test");
const _8_9_1 = require("../../fixtures/8.9");
const _setup_1 = require("../../test-setup.js");
const UtilitiesPage_1 = require("../../pages/8.9/UtilitiesPage");
const sleep_1 = require("../../utils/sleep");
const fileUpload_1 = require("../../utils/fileUpload");
const UtilitiesPage_2 = require("../../pages/8.9/UtilitiesPage");
const users_1 = require("../../utils/users");
const testUser = (0, users_1.getTestUser)('fifteenthUser');
_8_9_1.test.describe.configure({ mode: 'parallel' });
_8_9_1.test.describe('AWS Cluster User Flows Test', () => {
    const clusterName = 'AWS Cluster';
    _8_9_1.test.beforeEach(async ({ page, loginPage }, testInfo) => {
        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)('Document Handling HTO User Flow - AWS', async ({ modelerHomePage, appsPage, formJsPage, modelerCreatePage, taskPanelPage, taskDetailsPage, operateHomePage, operateProcessInstancePage, operateProcessesPage, homePage, page, }) => {
        _8_9_1.test.slow();
        const randomName = await (0, _setup_1.generateRandomStringAsync)(3);
        const processName = 'HTO_Document_Handling_Process' + randomName;
        const formNameFilePicker = 'File Picker Form ' + randomName;
        const formNameDocumentPreview = 'Document Preview Form ' + randomName;
        await _8_9_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_9_1.test.step('Open Cross Component Test Project', async () => {
            await modelerHomePage.clickCrossComponentProjectFolder();
        });
        await _8_9_1.test.step('Create a Form with a File Picker Field', async () => {
            await modelerHomePage.clickDiagramTypeDropdown();
            await modelerHomePage.clickFormOption();
            await modelerHomePage.enterFormName(formNameFilePicker);
            await (0, sleep_1.sleep)(10000);
            await formJsPage.dragAndDrop(formJsPage.filePicker, formJsPage.formEditor);
            await formJsPage.clickGeneralPropertiesPanel();
            await formJsPage.fillKeyInput('Upload_Files');
            await formJsPage.enableUploadMultipleFiles();
            await (0, sleep_1.sleep)(10000);
            await formJsPage.deployForm(clusterName);
            await (0, sleep_1.sleep)(5000);
        });
        await _8_9_1.test.step('Create a Form with a Document Preview Field', async () => {
            await modelerHomePage.clickProjectBreadcrumb();
            await modelerHomePage.clickDiagramTypeDropdown();
            await modelerHomePage.clickFormOption();
            await modelerHomePage.enterFormName(formNameDocumentPreview);
            await (0, sleep_1.sleep)(10000);
            await formJsPage.dragAndDrop(formJsPage.documentPreview, formJsPage.formEditor);
            await formJsPage.clickGeneralPropertiesPanel();
            await formJsPage.filldocumentReferenceInput('Upload_Files');
            await (0, sleep_1.sleep)(10000);
            await formJsPage.deployForm(clusterName);
            await (0, sleep_1.sleep)(5000);
        });
        await _8_9_1.test.step('Add A BPMN Template To The Project', async () => {
            await modelerHomePage.clickProjectBreadcrumb();
            await modelerHomePage.clickDiagramTypeDropdown();
            await modelerHomePage.clickBpmnTemplateOption();
        });
        await _8_9_1.test.step('Create a BPMN Diagram with Two User Tasks and Linked Forms', async () => {
            await (0, test_1.expect)(modelerCreatePage.generalPanel).toBeVisible({
                timeout: 120000,
            });
            await modelerCreatePage.enterDiagramName(processName);
            await (0, sleep_1.sleep)(20000);
            await modelerCreatePage.clickAppendElementButton();
            await modelerCreatePage.clickAppendTaskButton();
            await modelerCreatePage.clickChangeTypeButton();
            await modelerCreatePage.clickUserTaskOption();
            await modelerCreatePage.assertImplementationOption('zeebeUserTask');
            await modelerCreatePage.embedForm(formNameFilePicker);
            await modelerCreatePage.clickAppendElementButton();
            await modelerCreatePage.clickAppendTaskButton();
            await modelerCreatePage.clickChangeTypeButton();
            await modelerCreatePage.clickUserTaskOption();
            await modelerCreatePage.assertImplementationOption('zeebeUserTask');
            await modelerCreatePage.embedForm(formNameDocumentPreview);
            await modelerCreatePage.clickAppendElementButton();
            await modelerCreatePage.clickAppendEndEventButton();
            await (0, sleep_1.sleep)(20000);
            await modelerCreatePage.runProcessInstance(clusterName);
        });
        await _8_9_1.test.step('Navigate to Tasklist and Assert Document Upload And Preview', async () => {
            await appsPage.clickCamundaApps();
            await appsPage.clickTasklist(clusterName);
            await (0, test_1.expect)(taskPanelPage.taskListPageBanner).toBeVisible({
                timeout: 120000,
            });
            await taskPanelPage.openTask(processName);
            await taskDetailsPage.clickAssignToMeButton();
            await (0, fileUpload_1.uploadFile)(page, [
                'simple_text.txt',
                'simple_pdf.pdf',
                'camunda.png',
            ]);
            await taskDetailsPage.clickCompleteTaskButton();
            await (0, sleep_1.sleep)(10000);
            await page.reload();
            await taskPanelPage.openTask(processName);
            await taskDetailsPage.clickAssignToMeButton();
            await taskDetailsPage.assertLoadedImage('camunda.png');
            await taskDetailsPage.assertDocumentDownloadButton('camunda.png');
            await (0, test_1.expect)(taskDetailsPage.noPreviewContainer).toContainText('simple_text.txt', { timeout: 60000 });
            await taskDetailsPage.assertDocumentDownloadButton('simple_text.txt');
            await (0, test_1.expect)(taskDetailsPage.previewContainer).toHaveCount(2);
            await taskDetailsPage.assertPdfPreviewViewerExists();
            await taskDetailsPage.clickCompleteTaskButton();
        });
        await _8_9_1.test.step('Navigate to Operate and Assert Documents And StoreId', async () => {
            await appsPage.clickCamundaApps();
            await appsPage.clickOperate(clusterName);
            await operateHomePage.clickProcessesTab();
            await operateProcessesPage.clickProcessCompletedCheckbox();
            await operateProcessesPage.clickProcessInstanceLink(processName);
            await operateProcessInstancePage.assertProcessCompleteStatusWithRetry(40000);
            await operateProcessInstancePage.assertProcessVariableContainsText('Upload_Files', 'camunda.png');
            await operateProcessInstancePage.assertProcessVariableContainsText('Upload_Files', 'simple_pdf.pdf');
            await operateProcessInstancePage.assertProcessVariableContainsText('Upload_Files', 'simple_text.txt');
            await operateProcessInstancePage.assertProcessVariableContainsText('Upload_Files', 'aws');
        });
    });
    (0, _8_9_1.test)('Document Handling Connectors User Flow - AWS @tasklistV2', async ({ page, homePage, modelerHomePage, appsPage, modelerCreatePage, clusterPage, clusterDetailsPage, connectorMarketplacePage, operateHomePage, operateProcessesPage, operateProcessInstancePage, }) => {
        const apiClientName = await (0, _setup_1.generateRandomStringAsync)(6);
        const processName = 'Document_Handling_Connectors_User_Flow_AWS_Process' +
            (await (0, _setup_1.generateRandomStringAsync)(3));
        let credentials = {};
        await _8_9_1.test.step('Create Zeebe API Client', async () => {
            await homePage.clickClusters();
            await clusterPage.clickClusterLink(clusterName);
            await clusterDetailsPage.clickAPITab();
            credentials = await clusterDetailsPage.createAPIClientAndReturnVariables(apiClientName, false);
            await clusterDetailsPage.clickCloseModalButton();
        });
        await _8_9_1.test.step('Navigate to Web Modeler', async () => {
            await appsPage.clickCamundaApps();
            await appsPage.clickModeler();
            await (0, test_1.expect)(modelerHomePage.modelerPageBanner).toBeVisible({
                timeout: 120000,
            });
        });
        await _8_9_1.test.step('Open Cross Component Test Project and Create a REST Connector Document Handling Flow', async () => {
            await (0, UtilitiesPage_2.modelAndRunConnectorsDocHandlingDiagram)(modelerCreatePage, modelerHomePage, processName, page, connectorMarketplacePage, clusterName, `"${credentials.zeebeUrl}"`, `"${credentials.zeebeClientId}"`, `"${credentials.zeebeClientSecret}"`);
        });
        await _8_9_1.test.step('View Process Instance in Operate, assert it completes and assert variable values are correct', async () => {
            await appsPage.clickCamundaApps();
            await appsPage.clickOperate(clusterName);
            await (0, test_1.expect)(operateHomePage.operateBanner).toBeVisible({
                timeout: 60000,
            });
            await operateHomePage.clickProcessesTab();
            await operateProcessesPage.clickProcessCompletedCheckbox();
            await operateProcessesPage.clickProcessInstanceLink(processName);
            await operateProcessInstancePage.assertProcessCompleteStatusWithRetry();
            await operateProcessInstancePage.assertProcessVariableContainsText('doc', 'aws');
            await operateProcessInstancePage.assertProcessVariableContainsText('doc', 'b4946b81fed5c91a7de5f77c350241bc5ece49152708c61bd6c2208836d8415e');
            await operateProcessInstancePage.assertProcessVariableContainsText('doc', '19456');
            await operateProcessInstancePage.assertProcessVariableContainsText('doc', 'image/jpeg');
            await operateProcessInstancePage.assertProcessVariableContainsText('doc2', 'aws');
            await operateProcessInstancePage.assertProcessVariableContainsText('doc2', 'b4946b81fed5c91a7de5f77c350241bc5ece49152708c61bd6c2208836d8415e');
            await operateProcessInstancePage.assertProcessVariableContainsText('doc2', '19456');
            await operateProcessInstancePage.assertProcessVariableContainsText('doc2', 'image/jpeg');
            await operateProcessInstancePage.assertProcessVariableContainsText('uploadBatch', 'aws');
            await operateProcessInstancePage.assertProcessVariableContainsText('uploadBatch', '201');
            await operateProcessInstancePage.assertProcessVariableContainsText('uploadDoc2', 'aws');
            await operateProcessInstancePage.assertProcessVariableContainsText('uploadDoc2', '201');
            await operateProcessInstancePage.assertProcessVariableContainsText('uploadDoc2', 'aws');
            await operateProcessInstancePage.assertProcessVariableContainsText('GetDocUpload', '200');
        });
    });
});
