"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const test_1 = require("@playwright/test");
const SM_8_9_1 = require("../../fixtures/SM-8.9");
const _setup_1 = require("../../test-setup.js");
const sleep_1 = require("../../utils/sleep");
const fileUpload_1 = require("../../utils/fileUpload");
const UtilitiesPage_1 = require("../../pages/SM-8.9/UtilitiesPage");
if (process.env.IS_DS === 'true') {
    SM_8_9_1.test.describe.configure({ mode: 'parallel' });
    SM_8_9_1.test.describe('AWS Document Handling User Flows Test', () => {
        SM_8_9_1.test.beforeEach(async ({ navigationPage }, testInfo) => {
            await navigationPage.goToModeler((testInfo.workerIndex + 1) * 1000);
        });
        SM_8_9_1.test.afterEach(async ({ page }, testInfo) => {
            await (0, _setup_1.captureScreenshot)(page, testInfo);
            await (0, _setup_1.captureFailureVideo)(page, testInfo);
        });
        (0, SM_8_9_1.test)('Document Handling HTO User Flow - AWS', async ({ modelerHomePage, formJsPage, modelerCreatePage, taskPanelPage, taskDetailsPage, operateHomePage, operateProcessInstancePage, operateProcessesPage, navigationPage, page, }) => {
            SM_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 SM_8_9_1.test.step('Open Cross Component Test Project', async () => {
                await modelerHomePage.clickCrossComponentProjectFolder();
            });
            await SM_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();
            });
            await SM_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();
            });
            await SM_8_9_1.test.step('Add A BPMN Template To The Project', async () => {
                await modelerHomePage.clickProjectBreadcrumb();
                await modelerHomePage.clickDiagramTypeDropdown();
                await modelerHomePage.clickBpmnTemplateOption();
            });
            await SM_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)(1000);
                await modelerCreatePage.clickCanvas();
                await modelerCreatePage.clickGeneralPropertiesPanel();
                await modelerCreatePage.clickIdInput();
                await modelerCreatePage.fillIdInput(processName);
                await modelerCreatePage.assertNameInput(processName);
                await (0, sleep_1.sleep)(1000);
                await modelerCreatePage.clickStartEventElement();
                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)(5000);
                await modelerCreatePage.runProcessInstance();
            });
            await SM_8_9_1.test.step('Navigate to Tasklist and Assert Document Upload And Preview', async () => {
                await navigationPage.goToTasklist();
                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 SM_8_9_1.test.step('Navigate to Operate and Assert Documents And StoreId', async () => {
                await navigationPage.goToOperate();
                await operateHomePage.clickProcessesTab();
                await operateProcessesPage.clickProcessInstanceLink(processName, 'completed');
                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, SM_8_9_1.test)('Document Handling Connectors User Flow - AWS @tasklistV2', async ({ page, navigationPage, modelerHomePage, modelerCreatePage, operateHomePage, operateProcessesPage, connectorMarketplacePage, operateProcessInstancePage, ocIdentityHomePage, ocIdentityRolesPage, }) => {
            const processName = 'Document_Handling_Connectors_User_Flow_AWS_Process' +
                (await (0, _setup_1.generateRandomStringAsync)(3));
            const baseURL = process.env.PLAYWRIGHT_BASE_URL ||
                `https://eks-${process.env.BASE_URL}.qa.aws.camunda.cloud`;
            const clientSecret = process.env.DISTRO_QA_E2E_TESTS_KEYCLOAK_CLIENTS_SECRET;
            const endpoint = `${baseURL}/auth/realms/camunda-platform/protocol/openid-connect/token`;
            await SM_8_9_1.test.step('Grant client admin access', async () => {
                await navigationPage.goToOCIdentity();
                await ocIdentityHomePage.clickRolesTab();
                await ocIdentityRolesPage.clickRole('admin');
                await ocIdentityRolesPage.addClientToRole('test');
            });
            await SM_8_9_1.test.step('Open Cross Component Test Project and Create a REST Connector Document Handling Flow', async () => {
                await navigationPage.goToModeler();
                await (0, UtilitiesPage_1.modelAndRunConnectorsDocHandlingDiagram)(modelerCreatePage, modelerHomePage, processName, page, connectorMarketplacePage, `"${baseURL}/orchestration"`, `"test"`, `"${clientSecret}"`, endpoint);
            });
            await SM_8_9_1.test.step('View Process Instance in Operate, assert it completes and assert variable values are correct', async () => {
                await navigationPage.goToOperate();
                await operateHomePage.clickProcessesTab();
                await operateProcessesPage.clickProcessInstanceLink(processName, 'completed');
                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');
            });
        });
    });
}
