"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const test_1 = require("@playwright/test");
const _8_7_1 = require("../../fixtures/8.7");
const TaskPanelPage_1 = require("../../pages/8.7/TaskPanelPage");
const TaskDetailsPage_1 = require("../../pages/8.7/TaskDetailsPage");
const AppsPage_1 = require("../../pages/8.7/AppsPage");
const OperateProcessInstancePage_1 = require("../../pages/8.7/OperateProcessInstancePage");
const _setup_1 = require("../../test-setup.js");
const UtilitiesPage_1 = require("../../pages/8.7/UtilitiesPage");
const deleteOrg_1 = require("../../utils/deleteOrg");
const sleep_1 = require("../../utils/sleep");
const mailSlurpClient_1 = require("../../utils/mailSlurpClient");
const resetSession_1 = require("../../utils/resetSession");
const users_1 = require("../../utils/users");
const node_crypto_1 = require("node:crypto");
const testUser = (0, users_1.getTestUser)('eleventhUser');
_8_7_1.test.describe.configure({ mode: 'parallel' });
_8_7_1.test.describe('Web Modeler User Flow Tests', () => {
    const clusterName = 'Test Cluster';
    const inboxes = {
        'Invite New C8 User To Web Modeler Flow': '',
        'Invite Existing C8 member to Web Modeler flow': '',
    };
    _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);
        if (testInfo.title.includes('Invite New C8 User') ||
            testInfo.title.includes('Invite Existing C8 member')) {
            await (0, mailSlurpClient_1.deleteInbox)(inboxes[testInfo.title]);
        }
    });
    (0, _8_7_1.test)('Form.js Integration with User Task and AI Generated Form', async ({ page, homePage, modelerHomePage, appsPage, modelerCreatePage, formJsPage, }) => {
        _8_7_1.test.slow();
        const randomString = await (0, _setup_1.generateRandomStringAsync)(3);
        const processName = 'User_Task_Process_With_AI_Form' + randomString;
        const formName = 'New form' + randomString;
        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: 180000,
            });
        });
        await _8_7_1.test.step('Open Cross Component Test Project', async () => {
            await modelerHomePage.clickCrossComponentProjectFolder();
        });
        await _8_7_1.test.step('Create an AI Generated Form', async () => {
            await modelerHomePage.createForm(formName);
            await formJsPage.generateAIForm();
            await formJsPage.deployForm(clusterName);
        });
        await _8_7_1.test.step('Add A BPMN Template To The Project', async () => {
            await modelerHomePage.clickProjectBreadcrumb();
            await modelerHomePage.clickDiagramTypeDropdown();
            await modelerHomePage.clickBpmnTemplateOption();
        });
        await _8_7_1.test.step('Create BPMN Diagram with a User Task with an embedded AI Generated Form and Start Process Instance', async () => {
            await modelerCreatePage.modelCamundaUserTaskDiagram(processName, '', formName);
            await modelerCreatePage.runProcessInstance(clusterName);
        });
        await _8_7_1.test.step('View Process Instance in Operate and complete User Task in Tasklist', async () => {
            await (0, test_1.expect)(modelerCreatePage.viewProcessInstanceLink).toBeVisible({
                timeout: 180000,
            });
            await modelerCreatePage.clickViewProcessInstanceLink();
            const operateTab = await page.waitForEvent('popup', { timeout: 60000 });
            const operateTabAppsPage = new AppsPage_1.AppsPage(operateTab);
            const operateTabOperateProcessInstancePage = new OperateProcessInstancePage_1.OperateProcessInstancePage(operateTab);
            const operateTabTaskPanelPage = new TaskPanelPage_1.TaskPanelPage(operateTab);
            const operateTabTaskDetailsPage = new TaskDetailsPage_1.TaskDetailsPage(operateTab);
            await (0, test_1.expect)(operateTabOperateProcessInstancePage.activeIcon).toBeVisible({ timeout: 180000 });
            await operateTabAppsPage.clickCamundaApps();
            await operateTabAppsPage.clickTasklist(clusterName);
            await operateTabTaskPanelPage.openTask(processName);
            await operateTabTaskDetailsPage.clickAssignToMeButton();
            await (0, test_1.expect)(operateTabTaskDetailsPage.assignedToMeText).toBeVisible({
                timeout: 60000,
            });
            await operateTabTaskDetailsPage.fillName('test user');
            await operateTabTaskDetailsPage.checkCheckbox();
            await operateTabTaskDetailsPage.fillDate('11/11/1999');
            await operateTabTaskDetailsPage.fillNumber('10');
            await operateTabTaskDetailsPage.clickCompleteTaskButton();
            await (0, test_1.expect)(operateTab.getByText('Task completed')).toBeVisible({
                timeout: 200000,
            });
        });
    });
    (0, _8_7_1.test)('User Roles User Flow', async ({ page, modelerHomePage, appsPage, consoleOrganizationsPage, settingsPage, loginPage, homePage, modelerCreatePage, }) => {
        _8_7_1.test.slow();
        const randomString = await (0, _setup_1.generateRandomStringAsync)(3);
        const processName = 'User Roles User Flow' + randomString;
        await _8_7_1.test.step('Navigate to Web Modeler', async () => {
            await appsPage.clickCamundaApps();
            await appsPage.clickModeler();
            await (0, test_1.expect)(modelerHomePage.modelerPageBanner).toBeVisible({
                timeout: 180000,
            });
            await modelerHomePage.clickMessageBanner();
        });
        await _8_7_1.test.step('Change User Roles and Assert This Updates in Web Modeler', async () => {
            await (0, test_1.expect)(modelerHomePage.openOrganizationsButton).toBeVisible({
                timeout: 120000,
            });
            await modelerHomePage.clickOpenOrganizationsButton();
            await modelerHomePage.clickManageButton();
            await consoleOrganizationsPage.clickUsersTab();
            await consoleOrganizationsPage.filterTable([
                process.env.C8_USERNAME_TEST_3,
            ]);
            await consoleOrganizationsPage.clickOptionsButton();
            await consoleOrganizationsPage.clickEditUserMenuItem();
            await consoleOrganizationsPage.checkAnalystCheckbox();
            await consoleOrganizationsPage.uncheckDeveloperCheckbox();
            await consoleOrganizationsPage.clickConfirmButton();
            await (0, test_1.expect)(page.getByText('Updating...')).not.toBeVisible({
                timeout: 90000,
            });
            await settingsPage.clickOpenSettingsButton();
            await settingsPage.clickLogoutButton();
            await loginPage.loginWithTestUser({
                username: process.env.C8_USERNAME_TEST_3,
                password: process.env.C8_PASSWORD_TEST_3,
            });
            await (0, test_1.expect)(homePage.camundaComponentsButton).toBeVisible({
                timeout: 60000,
            });
            await (0, sleep_1.sleep)(30000);
            await appsPage.clickCamundaApps();
            await (0, test_1.expect)(appsPage.modelerLink).toBeVisible({
                timeout: 30000,
            });
            await (0, test_1.expect)(appsPage.consoleLink).toBeVisible();
            await (0, test_1.expect)(appsPage.operateLink).not.toBeVisible();
            await (0, test_1.expect)(appsPage.tasklistLink).not.toBeVisible();
            await (0, test_1.expect)(appsPage.modelerLink).toBeVisible();
            await appsPage.clickModeler();
            await homePage.clickSkipCustomization();
            await modelerHomePage.createCrossComponentProjectFolder();
            await modelerHomePage.clickDiagramTypeDropdown();
            await modelerHomePage.clickBpmnTemplateOption();
            await (0, test_1.expect)(modelerCreatePage.generalPanel).toBeVisible({
                timeout: 90000,
            });
            await modelerCreatePage.enterDiagramName(processName);
            await (0, sleep_1.sleep)(10000);
            await modelerCreatePage.clickAppendElementButton();
            await modelerCreatePage.clickAppendTaskButton();
            await modelerCreatePage.clickAppendElementButton();
            await modelerCreatePage.clickAppendEndEventButton();
            await (0, sleep_1.sleep)(20000);
            await modelerCreatePage.clickSecondDeployButton();
            await (0, test_1.expect)(page.getByText(`You do not have the permissions needed to deploy`)).toBeVisible({ timeout: 60000 });
            await modelerCreatePage.clickCancelButton();
            await (0, test_1.expect)(settingsPage.openSettingsButton).toBeVisible({
                timeout: 60000,
            });
            await settingsPage.clickOpenSettingsButton();
            await settingsPage.clickLogoutButton();
            await (0, UtilitiesPage_1.loginWithRetry)(page, loginPage, testUser, 1000);
            await (0, sleep_1.sleep)(30000);
            await appsPage.clickCamundaApps();
            await appsPage.clickModeler();
            await (0, test_1.expect)(modelerHomePage.modelerPageBanner).toBeVisible({
                timeout: 90000,
            });
            await modelerHomePage.clickMessageBanner();
            await (0, test_1.expect)(modelerHomePage.openOrganizationsButton).toBeVisible({
                timeout: 120000,
            });
            await modelerHomePage.clickOpenOrganizationsButton();
            await modelerHomePage.clickManageButton();
            await consoleOrganizationsPage.clickUsersTab();
            await consoleOrganizationsPage.filterTable([
                process.env.C8_USERNAME_TEST_3,
            ]);
            await consoleOrganizationsPage.clickOptionsButton();
            await consoleOrganizationsPage.clickEditUserMenuItem();
            await consoleOrganizationsPage.uncheckAnalystCheckbox();
            await consoleOrganizationsPage.checkDeveloperCheckbox();
            await consoleOrganizationsPage.clickConfirmButton();
            await (0, test_1.expect)(page.getByText('Updating...')).not.toBeVisible({
                timeout: 90000,
            });
            await (0, test_1.expect)(settingsPage.openSettingsButton).toBeVisible({
                timeout: 120000,
            });
            await settingsPage.clickOpenSettingsButton();
            await settingsPage.clickLogoutButton();
            await loginPage.loginWithTestUser({
                username: process.env.C8_USERNAME_TEST_3,
                password: process.env.C8_PASSWORD_TEST_3,
            });
            await (0, test_1.expect)(homePage.camundaComponentsButton).toBeVisible({
                timeout: 120000,
            });
            await (0, sleep_1.sleep)(30000);
            await appsPage.clickCamundaApps();
            await (0, test_1.expect)(appsPage.consoleLink).toBeVisible({
                timeout: 30000,
            });
            await appsPage.assertOperatePresent();
            await appsPage.assertTasklistPresent();
            await (0, test_1.expect)(appsPage.modelerLink).toBeVisible();
            await appsPage.assertOptimizePresent(false);
            await appsPage.clickModeler();
            await modelerHomePage.clickCrossComponentProjectFolder();
            await modelerHomePage.clickProcessDiagram(processName);
            await modelerCreatePage.runProcessInstance(clusterName);
            await (0, test_1.expect)(page
                .getByText(`You do not have the permissions needed to deploy to ${clusterName}`)
                .first()).not.toBeVisible({ timeout: 60000 });
            await (0, test_1.expect)(modelerCreatePage.viewProcessInstanceLink).toBeVisible({
                timeout: 60000,
            });
            await (0, test_1.expect)(settingsPage.openSettingsButton).toBeVisible({
                timeout: 60000,
            });
            await settingsPage.clickOpenSettingsButton();
            await settingsPage.clickLogoutButton();
            await (0, UtilitiesPage_1.loginWithRetry)(page, loginPage, testUser, 1000);
            await (0, sleep_1.sleep)(20000);
            await appsPage.clickCamundaApps();
            await appsPage.clickModeler();
            await (0, test_1.expect)(modelerHomePage.modelerPageBanner).toBeVisible({
                timeout: 90000,
            });
            await modelerHomePage.clickMessageBanner();
            await (0, test_1.expect)(modelerHomePage.openOrganizationsButton).toBeVisible({
                timeout: 60000,
            });
            await modelerHomePage.clickOpenOrganizationsButton();
            await modelerHomePage.clickManageButton();
            await consoleOrganizationsPage.clickUsersTab();
            await consoleOrganizationsPage.filterTable([
                process.env.C8_USERNAME_TEST_3,
            ]);
            await consoleOrganizationsPage.clickOptionsButton();
            await consoleOrganizationsPage.clickEditUserMenuItem();
            await consoleOrganizationsPage.checkAnalystCheckbox();
            await consoleOrganizationsPage.clickConfirmButton();
            await (0, test_1.expect)(page.getByText('Updating...')).not.toBeVisible({
                timeout: 90000,
            });
            await (0, test_1.expect)(settingsPage.openSettingsButton).toBeVisible({
                timeout: 60000,
            });
            await settingsPage.clickOpenSettingsButton();
            await settingsPage.clickLogoutButton();
            await loginPage.loginWithTestUser({
                username: process.env.C8_USERNAME_TEST_3,
                password: process.env.C8_PASSWORD_TEST_3,
            });
            await (0, test_1.expect)(homePage.camundaComponentsButton).toBeVisible({
                timeout: 120000,
            });
            await (0, sleep_1.sleep)(30000);
            await appsPage.clickCamundaApps();
            await (0, test_1.expect)(appsPage.consoleLink).toBeVisible({
                timeout: 20000,
            });
            await appsPage.assertOptimizePresent();
            await appsPage.assertOperatePresent();
            await appsPage.assertTasklistPresent();
            await (0, test_1.expect)(appsPage.modelerLink).toBeVisible();
            await appsPage.clickModeler();
            await modelerHomePage.clickCrossComponentProjectFolder();
            await modelerHomePage.clickProcessDiagram(processName);
            await modelerCreatePage.runProcessInstance(clusterName);
            await (0, test_1.expect)(page.getByText(`You do not have the permissions needed to deploy to ${clusterName}`)).not.toBeVisible({ timeout: 60000 });
            await (0, test_1.expect)(modelerCreatePage.viewProcessInstanceLink).toBeVisible({
                timeout: 60000,
            });
        });
    });
    (0, _8_7_1.test)('Form.js Integration with AI generated Start form', async ({ page, homePage, modelerHomePage, appsPage, modelerCreatePage, formJsPage, }) => {
        _8_7_1.test.slow();
        const randomString = await (0, _setup_1.generateRandomStringAsync)(3);
        const processName = 'AI-generated-Start-form' + randomString;
        const formName = 'New form' + randomString;
        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: 180000,
            });
        });
        await _8_7_1.test.step('Open Cross Component Test Project', async () => {
            await modelerHomePage.clickCrossComponentProjectFolder();
        });
        await _8_7_1.test.step('Create an AI Generated Form', async () => {
            await modelerHomePage.createForm(formName);
            await formJsPage.generateAIForm();
            await formJsPage.deployForm(clusterName);
        });
        await _8_7_1.test.step('Add A BPMN Template To The Project', async () => {
            await modelerHomePage.clickProjectBreadcrumb();
            await modelerHomePage.clickDiagramTypeDropdown();
            await modelerHomePage.clickBpmnTemplateOption();
        });
        await _8_7_1.test.step('Create BPMN Diagram with a AI generated Start Form and Start Process Instance', async () => {
            await (0, test_1.expect)(modelerCreatePage.generalPanel).toBeVisible({
                timeout: 90000,
            });
            await modelerCreatePage.enterDiagramName(processName);
            await (0, sleep_1.sleep)(10000);
            await modelerCreatePage.clickEmbedFormButton();
            await modelerCreatePage.clickForm(formName);
            await modelerCreatePage.clickEmbedButton();
            await modelerCreatePage.clickAppendElementButton();
            await modelerCreatePage.clickAppendEndEventButton();
            await (0, sleep_1.sleep)(20000);
            await modelerCreatePage.runProcessInstance(clusterName, '', {
                formName: 'test user',
                checkbox: 'true',
                startDate: '11/11/1999',
                startNumber: '10',
            });
        });
        await _8_7_1.test.step('View Process Instance in Operate and check if process is complete', async () => {
            await (0, test_1.expect)(modelerCreatePage.viewProcessInstanceLink).toBeVisible({
                timeout: 180000,
            });
            await modelerCreatePage.clickViewProcessInstanceLink();
            const operateTab = await page.waitForEvent('popup', { timeout: 90000 });
            const operateTabOperateProcessInstancePage = new OperateProcessInstancePage_1.OperateProcessInstancePage(operateTab);
            await operateTab.reload();
            await (0, test_1.expect)(operateTabOperateProcessInstancePage.completedIcon).toBeVisible({
                timeout: 1800000,
            });
        });
    });
    //Skipped due to bug 4677: https://github.com/camunda/web-modeler/issues/4677
    _8_7_1.test.skip('Invite New C8 User To Web Modeler Flow', async ({ page, homePage, appsPage, modelerHomePage, signUpPage, modelerUserInvitePage, loginPage, }, testInfo) => {
        _8_7_1.test.slow();
        const inbox = await (0, mailSlurpClient_1.createInbox)();
        const id = inbox.id;
        const emailAddress = inbox.emailAddress;
        inboxes[testInfo.title] = id;
        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 modelerUserInvitePage.clickAddUser();
            await modelerUserInvitePage.clickUserEmailInput();
        });
        await _8_7_1.test.step('Add collaborator to Cross Component Test Project', async () => {
            await modelerUserInvitePage.fillUserEmailInput(emailAddress);
            await modelerUserInvitePage.clickSendInviteButton();
            await (0, sleep_1.sleep)(30000);
            await modelerUserInvitePage.checkPendingInviteText(emailAddress);
            await modelerUserInvitePage.clickSettings();
            await modelerUserInvitePage.clickLogout();
            await (0, sleep_1.sleep)(60000);
            await (0, UtilitiesPage_1.clickInvitationLinkInEmail)(page, id);
        });
        await _8_7_1.test.step('Signup new collaborator to Cross Component Test Project', async () => {
            await signUpPage.clickFirstNameInput();
            await signUpPage.fillFirstNameInput('QA');
            await signUpPage.clickLastNameInput();
            await signUpPage.fillLastNameInput('Camunda');
            await signUpPage.clickPasswordInputInvitedUser();
            await signUpPage.fillPasswordInputInvitedUser(process.env.C8_PASSWORD);
            await signUpPage.clickSignupButton();
            await (0, sleep_1.sleep)(60000); //a workaround for https://github.com/camunda/web-modeler/issues/4677
            await loginPage.login({
                username: emailAddress,
                password: process.env.C8_PASSWORD,
            });
            await (0, test_1.expect)(page.getByText('Personalize your experience')).toBeVisible({
                timeout: 180000,
            });
            await modelerUserInvitePage.clickSkipCustomization();
            await modelerUserInvitePage.clickCloseHelpCenter();
            await modelerHomePage.clickMessageBanner();
        });
        await _8_7_1.test.step('Navigate to Cross Component Test project as Collaborator', async () => {
            await (0, UtilitiesPage_1.assertLocatorVisibleWithRetry)(modelerHomePage, modelerHomePage.crossComponentProjectFolder, 'Cross Component Test Project', 90000);
            await modelerUserInvitePage.clickSettings();
            await modelerUserInvitePage.clickLogout();
        });
        await _8_7_1.test.step('Login as Project Admin', async () => {
            await (0, test_1.expect)(loginPage.loginMessage).toBeVisible({
                timeout: 60000,
            });
            await page.goto('/');
            await loginPage.login(testUser);
        });
        await _8_7_1.test.step('Navigate to Web Modeler as Project Admin', 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('Assert Collaborator presence as Project Admin', async () => {
            await modelerHomePage.clickCrossComponentProjectFolder();
            await (0, UtilitiesPage_1.assertPageTextWithRetry)(page, emailAddress, false, 60000);
        });
    });
    (0, _8_7_1.test)('Invite Existing C8 member to Web Modeler flow', async ({ page, loginPage, signUpPage, homePage, modelerUserInvitePage, appsPage, modelerHomePage, settingsPage, }, testInfo) => {
        _8_7_1.test.slow();
        const { id, emailAddress } = await (0, mailSlurpClient_1.createInbox)();
        inboxes[testInfo.title] = id;
        let newOrganizationUuid = '';
        const password = (await (0, _setup_1.generateRandomStringAsync)(5)) +
            (0, node_crypto_1.randomInt)(10000000, 90000000) +
            '*';
        await _8_7_1.test.step('Sign up new user to C8', async () => {
            await signUpPage.signupToC8(emailAddress, password);
        });
        await _8_7_1.test.step('Log in to C8 as New User', async () => {
            await (0, UtilitiesPage_1.clickInvitationLinkInEmail)(page, id);
            // The OAuth redirect chain after the invitation link can stall and
            // never resolve to the Modeler banner within a single wait window.
            // Reload the page once and try again before giving up.
            try {
                await (0, test_1.expect)(modelerHomePage.modelerPageBanner).toBeVisible({
                    timeout: 90000,
                });
            }
            catch {
                await page.reload();
                await (0, test_1.expect)(modelerHomePage.modelerPageBanner).toBeVisible({
                    timeout: 180000,
                });
            }
            await modelerHomePage.clickMessageBanner();
            await settingsPage.clickOpenSettingsButton();
            await settingsPage.clickLogoutButton();
            await loginPage.loginWithoutOrgAssertion({
                username: emailAddress,
                password: password,
            });
            await (0, test_1.expect)(page.getByText('Personalize your experience')).toBeVisible({
                timeout: 180000,
            });
            await homePage.clickSkipCustomization();
        });
        await _8_7_1.test.step('Navigate to Console', async () => {
            // After clickSkipCustomization the browser is already on Console at
            // /org/<uuid>/... – avoid triggering a redundant app-switcher navigation
            // which can cause Auth0 to re-authenticate new users (taking >120 s).
            const alreadyOnOrg = await page
                .waitForURL(/\/org\//, { timeout: 10000 })
                .then(() => true)
                .catch(() => false);
            if (!alreadyOnOrg) {
                await appsPage.clickCamundaApps();
                await appsPage.clickConsoleLink();
            }
            // If Auth0 re-auth was triggered (new-user first Console visit), log back in.
            const onAuth0 = await loginPage.usernameInput
                .waitFor({ state: 'visible', timeout: 10000 })
                .then(() => true)
                .catch(() => false);
            if (onAuth0) {
                await loginPage.fillUsername(emailAddress);
                await loginPage.clickContinueButton();
                await loginPage.fillPassword(password);
                await loginPage.clickLoginButton();
                await page.waitForURL(/\/org\//, { timeout: 90000 });
            }
            await (0, test_1.expect)(homePage.consoleBanner).toBeVisible({
                timeout: 120000,
            });
            newOrganizationUuid = homePage.organizationUuid();
        });
        await _8_7_1.test.step('Login as Project Admin', async () => {
            await settingsPage.clickOpenSettingsButton();
            await settingsPage.clickLogoutButton();
            await loginPage.login(testUser);
        });
        await _8_7_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_7_1.test.step('Navigate to Cross Component Test project and Add Collaborator', async () => {
            await modelerHomePage.clickCrossComponentProjectFolder();
            await modelerUserInvitePage.clickAddUser();
            await modelerUserInvitePage.clickUserEmailInput();
            await modelerUserInvitePage.fillUserEmailInput(emailAddress);
            await modelerUserInvitePage.clickSendInviteButton();
            await modelerUserInvitePage.checkPendingInviteText(emailAddress);
        });
        await _8_7_1.test.step('Log out from Project Admin', async () => {
            await settingsPage.clickOpenSettingsButton();
            await settingsPage.clickLogoutButton();
            await (0, sleep_1.sleep)(60000);
        });
        await _8_7_1.test.step('Log in with Second User and Navigate to Cross Component Test project as Collaborator', async () => {
            await (0, UtilitiesPage_1.clickInvitationLinkInEmail)(page, id);
            await (0, sleep_1.sleep)(60000);
            await modelerHomePage.navigateAfterInvitationLink(loginPage, appsPage, {
                username: emailAddress,
                password: password,
            });
            await (0, UtilitiesPage_1.assertLocatorVisibleWithRetry)(modelerHomePage, modelerHomePage.crossComponentProjectFolder, 'Cross Component Test Project', 90000, 20);
        });
        await _8_7_1.test.step('Log out from Second User', async () => {
            await settingsPage.clickOpenSettingsButton();
            await settingsPage.clickLogoutButton();
        });
        await _8_7_1.test.step('Navigate to Web Modeler as Project Admin', async () => {
            await (0, UtilitiesPage_1.loginWithRetry)(page, loginPage, testUser, 1000);
            await appsPage.clickCamundaApps();
            await appsPage.clickModeler();
            await (0, test_1.expect)(modelerHomePage.modelerPageBanner).toBeVisible({
                timeout: 120000,
            });
            // Assert Collaborator presence
            await modelerHomePage.clickCrossComponentProjectFolder();
            await (0, UtilitiesPage_1.assertPageTextWithRetry)(page, emailAddress, false, 60000);
        });
        await _8_7_1.test.step('Delete Organization', async () => {
            await (0, deleteOrg_1.deleteOrganization)(page, newOrganizationUuid);
        });
    });
    (0, _8_7_1.test)('Form.js Integration with User Task and Embedded Form', async ({ page, homePage, modelerHomePage, appsPage, modelerCreatePage, }) => {
        _8_7_1.test.slow();
        const processName = 'User_Task_Process_With_embedded_form' +
            (await (0, _setup_1.generateRandomStringAsync)(3));
        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 A BPMN Template To The Project', async () => {
            await modelerHomePage.clickDiagramTypeDropdown();
            await modelerHomePage.clickBpmnTemplateOption();
        });
        await _8_7_1.test.step('Create BPMN Diagram with a embedded form and Start Process Instance', async () => {
            await modelerCreatePage.modelJobWorkerDiagram(processName, true);
            await modelerCreatePage.runProcessInstance(clusterName);
        });
        await _8_7_1.test.step('View Process Instance in Operate and check if process is complete', async () => {
            await (0, test_1.expect)(modelerCreatePage.viewProcessInstanceLink).toBeVisible({
                timeout: 180000,
            });
            await modelerCreatePage.clickViewProcessInstanceLink();
            const operateTab = await page.waitForEvent('popup', { timeout: 60000 });
            const operateTabAppsPage = new AppsPage_1.AppsPage(operateTab);
            const operateTabOperateProcessInstancePage = new OperateProcessInstancePage_1.OperateProcessInstancePage(operateTab);
            const operateTabTaskPanelPage = new TaskPanelPage_1.TaskPanelPage(operateTab);
            const operateTabTaskDetailsPage = new TaskDetailsPage_1.TaskDetailsPage(operateTab);
            await (0, test_1.expect)(operateTabOperateProcessInstancePage.activeIcon).toBeVisible({ timeout: 180000 });
            await operateTabAppsPage.clickCamundaApps();
            await operateTabAppsPage.clickTasklist(clusterName);
            await operateTabTaskPanelPage.openTask(processName);
            await operateTabTaskDetailsPage.clickAssignToMeButton();
            await (0, test_1.expect)(operateTabTaskDetailsPage.assignedToMeText).toBeVisible({
                timeout: 60000,
            });
            await operateTabTaskDetailsPage.fillName('test user');
            await operateTabTaskDetailsPage.clickCompleteTaskButton();
            await (0, test_1.expect)(operateTab.getByText('Task completed')).toBeVisible({
                timeout: 200000,
            });
        });
    });
    (0, _8_7_1.test)('Timer Event User Flow', async ({ page, homePage, modelerHomePage, appsPage, modelerCreatePage, operateHomePage, operateProcessInstancePage, operateProcessesPage, }) => {
        const processName = 'Timer_Event_Process' + (await (0, _setup_1.generateRandomStringAsync)(3));
        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: 180000,
            });
        });
        await _8_7_1.test.step('Open Cross Component Test Project and Create a BPMN Diagram Template', async () => {
            await modelerHomePage.clickCrossComponentProjectFolder();
            await modelerHomePage.clickDiagramTypeDropdown();
            await modelerHomePage.clickBpmnTemplateOption();
        });
        await _8_7_1.test.step('Create BPMN Diagram with Timer Event and Deploy Diagram', async () => {
            await (0, test_1.expect)(modelerCreatePage.generalPanel).toBeVisible({
                timeout: 120000,
            });
            await modelerCreatePage.enterDiagramName(processName);
            await (0, sleep_1.sleep)(10000);
            await modelerCreatePage.clickAppendElementButton();
            await modelerCreatePage.clickIntermediateBoundaryEvent();
            await modelerCreatePage.clickChangeTypeButton();
            await modelerCreatePage.clickTimerEventOption();
            await modelerCreatePage.clickTimerEventSettings();
            await modelerCreatePage.selectTimerType('timeDuration');
            await modelerCreatePage.clickTimerValue();
            await modelerCreatePage.fillTimerValue('PT90S');
            await modelerCreatePage.clickAppendElementButton();
            await modelerCreatePage.clickAppendEndEventButton();
            await modelerCreatePage.runProcessInstance(clusterName);
        });
        await _8_7_1.test.step('Assert Diagram Has Successfully Completed in Operate', async () => {
            await appsPage.clickCamundaApps();
            await appsPage.clickOperate(clusterName);
            await (0, test_1.expect)(operateHomePage.processesTab).toBeVisible({ timeout: 120000 });
            await operateHomePage.clickProcessesTab();
            await page.reload();
            await operateProcessesPage.clickProcessCompletedCheckbox();
            await operateProcessesPage.clickProcessInstanceLink(processName);
            await (0, UtilitiesPage_1.assertLocatorVisibleWithRetry)(operateProcessInstancePage, operateProcessInstancePage.activeIcon, 'Active icon', 60000);
            await (0, UtilitiesPage_1.assertLocatorVisibleWithRetry)(operateProcessInstancePage, operateProcessInstancePage.completedIcon, 'Completed icon', 60000);
        });
    });
    (0, _8_7_1.test)('Public Start Form', async ({ page, homePage, modelerHomePage, appsPage, modelerCreatePage, formJsPage, context, taskDetailsPage, loginPage, taskPanelPage, operateHomePage, operateProcessesPage, operateProcessInstancePage, }) => {
        const randomString = await (0, _setup_1.generateRandomStringAsync)(3);
        const processName = 'User_Task_Process_With_Public_Form' + randomString;
        const formName = 'Public form' + randomString;
        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: 180000,
            });
        });
        await _8_7_1.test.step('Open Cross Component Test Project', async () => {
            await modelerHomePage.clickCrossComponentProjectFolder();
        });
        await _8_7_1.test.step('Create a Form with a Text Field', async () => {
            await modelerHomePage.clickDiagramTypeDropdown();
            await modelerHomePage.clickFormOption();
            await modelerHomePage.enterFormName(formName);
            await (0, sleep_1.sleep)(2000);
            await formJsPage.dragAndDrop(formJsPage.textField, formJsPage.formEditor);
            await formJsPage.clickGeneralPropertiesPanel();
            await formJsPage.fillKeyInput('Public_Form_Text_Field');
            await (0, test_1.expect)(formJsPage.textFieldInForm).toBeVisible();
            await (0, sleep_1.sleep)(5000);
            await formJsPage.deployForm(clusterName);
            await (0, sleep_1.sleep)(5000);
        });
        await _8_7_1.test.step('Add A BPMN Template To The Project', async () => {
            await modelerHomePage.clickProjectBreadcrumb();
            await modelerHomePage.clickDiagramTypeDropdown();
            await modelerHomePage.clickBpmnTemplateOption();
        });
        await _8_7_1.test.step('Create BPMN Diagram with a Public Start Form and Deploy the Process', async () => {
            await modelerCreatePage.modelCamundaUserTaskDiagram(processName, processName);
            await modelerCreatePage.linkFormToStartEvent(formName);
            await modelerCreatePage.enablePublicAccessIfDisabled();
            await modelerCreatePage.deployDiagram(clusterName);
            await (0, sleep_1.sleep)(10000);
        });
        let publicFormLink;
        await _8_7_1.test.step('Enable Public Access and Get Publication Link', async () => {
            publicFormLink = await modelerCreatePage.getPublicationLink();
            await (0, sleep_1.sleep)(1000);
        });
        await _8_7_1.test.step('Clear Cookies and Reset Session', async () => {
            await (0, resetSession_1.resetSessionAll)(context, page);
        });
        await _8_7_1.test.step('Access Public Form After Session Reset and Submit the Form', async () => {
            console.log('Navigating to public form:', publicFormLink);
            await page.goto(publicFormLink);
            await (0, test_1.expect)(taskDetailsPage.textInput).toBeVisible({
                timeout: 30000,
            });
            await taskDetailsPage.fillTextInput('Public Form Test Value');
            await taskDetailsPage.clickSubmitButton();
            await (0, test_1.expect)(page.getByRole('heading', { name: 'Success!' })).toBeVisible({
                timeout: 30000,
            });
        });
        await _8_7_1.test.step('Login to Tasklist and Check User Task Has the Correct Input Values and Can Be Completed', async () => {
            await (0, UtilitiesPage_1.loginWithRetry)(page, loginPage, testUser, 5000);
            await appsPage.clickCamundaApps();
            await appsPage.clickTasklist(clusterName);
            await (0, UtilitiesPage_1.assertLocatorVisibleWithRetry)(page, taskPanelPage.taskListPageBanner, 'Tasklist banner');
            await taskPanelPage.openTask(processName);
            await (0, test_1.expect)(page
                .getByRole('row')
                .filter({ hasText: 'Public_Form_Text_Field' })
                .getByText('"Public Form Test Value"')).toBeVisible({ timeout: 30000 });
            await taskDetailsPage.clickAssignToMeButton();
            await taskDetailsPage.clickCompleteTaskButton();
        });
        await _8_7_1.test.step('Assert Process Instance is Completed in Operate', async () => {
            await appsPage.clickCamundaApps();
            await appsPage.clickOperate(clusterName);
            await operateHomePage.clickProcessesTab();
            await operateProcessesPage.clickProcessCompletedCheckbox();
            await operateProcessesPage.clickProcessInstanceLink(processName);
            await operateProcessInstancePage.assertProcessCompleteStatusWithRetry(40000);
        });
    });
});
