"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 UtilitiesPage_1 = require("../../pages/SM-8.9/UtilitiesPage");
const resetSession_1 = require("../../utils/resetSession");
const expectTextWithRetry_1 = require("../../utils/assertionHelpers/expectTextWithRetry");
const expectLocatorWithRetry_1 = require("../../utils/assertionHelpers/expectLocatorWithRetry");
const demoUserEmail = process.env.DEMO_USER_EMAIL || 'demo@example.org';
const demoUserDisplayText = `Demo User${demoUserEmail}`;
if (process.env.IS_MT === 'true') {
    SM_8_9_1.test.describe.configure({ mode: 'parallel' });
    SM_8_9_1.test.describe('MT Enabled User Flows Test', () => {
        SM_8_9_1.test.beforeEach(async ({ navigationPage }, testInfo) => {
            await navigationPage.goToOCIdentity((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)('Main User Can Create & Access Tenant & User Without Access Cannot - User Task Flow', async ({ page, modelerHomePage, modelerCreatePage, taskPanelPage, operateProcessInstancePage, operateProcessesPage, taskDetailsPage, operateHomePage, navigationPage, ocTenantPage, optimizeHomePage, optimizeDashboardPage, browser, ocIdentityHomePage, managementIdentityTenantPage, managementIdentityPage, keycloakAdminPage, keycloakLoginPage, ocIdentityMappingRulesPage, ocIdentityRolesPage, }) => {
            SM_8_9_1.test.slow();
            const randomString = await (0, _setup_1.generateRandomStringAsync)(3);
            const processName = 'Main_User_Task_Flow_' + randomString;
            const tenantName = 'Tenant_Main_' + randomString;
            const testUser = (await (0, _setup_1.generateRandomStringAsync)(6)).toLowerCase();
            const password = process.env.DISTRO_QA_E2E_TESTS_IDENTITY_FIRSTUSER_PASSWORD;
            const credentials = {
                username: testUser,
                password: password,
            };
            await SM_8_9_1.test.step('Create new Test User And Assign to Role', async () => {
                await (0, UtilitiesPage_1.createUserAndAssignToRole)(page, navigationPage, managementIdentityPage, keycloakLoginPage, keycloakAdminPage, ocIdentityHomePage, ocIdentityMappingRulesPage, ocIdentityRolesPage, testUser, password);
            });
            await SM_8_9_1.test.step('Create Tenant And Assign User in OC Identity', async () => {
                await ocIdentityHomePage.clickTenantsTab();
                await ocTenantPage.createTenant(tenantName);
                await ocIdentityHomePage.clickTenantsTab();
                await ocTenantPage.clickTenant(tenantName);
                await ocTenantPage.assignUserToTenant('demo');
            });
            await SM_8_9_1.test.step('Create Tenant And Assign User in Management Identity', async () => {
                await navigationPage.goToManagementIdentity();
                await managementIdentityTenantPage.createTenant(tenantName);
                await managementIdentityTenantPage.assignUserToTenant(tenantName, 'demo', demoUserDisplayText);
                if (process.env.IS_OPTIMIZE !== 'false') {
                    await managementIdentityTenantPage.assignClientToTenant('Optimize');
                }
            });
            await SM_8_9_1.test.step('Open Cross Component Test Project', async () => {
                await navigationPage.goToModeler();
                await modelerHomePage.createCrossComponentProjectFolder();
                await modelerHomePage.clickDiagramTypeDropdown();
                await modelerHomePage.clickBpmnTemplateOption();
            });
            await SM_8_9_1.test.step('Create A Diagram with a User Task and Start Process Instance', async () => {
                await modelerCreatePage.modelCamundaUserTaskDiagram(processName);
                await modelerCreatePage.runProcessInstance('', tenantName); //Identity bug https://github.com/camunda/camunda/issues/35834
            });
            await SM_8_9_1.test.step('View Process Instance in Operate, complete User Task in Tasklist & assert process complete in Operate', async () => {
                await navigationPage.goToOperate();
                await operateHomePage.clickProcessesTab();
                await operateProcessesPage.clickProcessInstanceLink(processName);
                await operateProcessInstancePage.activeIconAssertion();
                await navigationPage.goToTasklist();
                await taskPanelPage.openTask(processName);
                await taskDetailsPage.clickAssignToMeButton();
                await taskDetailsPage.clickCompleteTaskButton();
                await (0, test_1.expect)(page.getByText('Task completed')).toBeVisible({
                    timeout: 200000,
                });
                await navigationPage.goToOperate();
                await operateHomePage.clickProcessesTab();
                await operateProcessesPage.clickProcessInstanceLink(processName, 'completed');
                await operateProcessInstancePage.completedIconAssertion();
                await operateProcessInstancePage.tenantNameAssertion(tenantName);
            });
            if (process.env.IS_OPTIMIZE !== 'false') {
                await SM_8_9_1.test.step('Assert Process has been successfully imported in Optimize', async () => {
                    await navigationPage.goToOptimize();
                    await optimizeHomePage.clickDashboardLink();
                    await (0, test_1.expect)(async () => {
                        await page.reload();
                        await optimizeDashboardPage.clickFilterTable();
                        await optimizeDashboardPage.fillFilterTable(processName);
                        await optimizeDashboardPage.processAssertion(processName);
                    }).toPass({ timeout: 300000, intervals: [15000] });
                });
            }
            await SM_8_9_1.test.step('Clear cookies and reset session', async () => {
                await (0, resetSession_1.resetSession)(browser, page); //a workaround for https://github.com/camunda/camunda/issues/34513
            });
            await SM_8_9_1.test.step('Open Cross Component Test Project', async () => {
                await navigationPage.goToModeler(undefined, credentials);
                await modelerHomePage.createCrossComponentProjectFolder();
                await modelerHomePage.clickDiagramTypeDropdown();
                await modelerHomePage.clickBpmnTemplateOption();
            });
            await SM_8_9_1.test.step('Create A Diagram with a User Task and Assert Cannot Start Process Instance With Tenant', async () => {
                await modelerCreatePage.modelCamundaUserTaskDiagram(processName);
                await modelerCreatePage.clickDeployAndRunMainButton();
                await modelerCreatePage.clickTenantIdInput();
                await modelerCreatePage.fillTenantIdInput(tenantName);
                await modelerCreatePage.clickDeployAndRunSubButton();
                await (0, test_1.expect)(page.getByText('The diagram failed to deploy & run')).toBeVisible({ timeout: 60000 });
            });
            await SM_8_9_1.test.step('Assert "test" user cannot view process in Tasklist, Operate or Optimize', async () => {
                await navigationPage.goToOperate(undefined, credentials);
                await operateHomePage.clickProcessesTab();
                await page.waitForLoadState('networkidle');
                await (0, test_1.expect)(page.getByText(processName)).not.toBeVisible({
                    timeout: 60000,
                });
                await navigationPage.goToTasklist(undefined, credentials);
                await page.waitForLoadState('networkidle');
                await (0, test_1.expect)(page.getByText(processName)).not.toBeVisible({
                    timeout: 60000,
                });
                if (process.env.IS_OPTIMIZE !== 'false') {
                    await navigationPage.goToOptimize(undefined, credentials);
                    await optimizeHomePage.clickDashboardLink();
                    await (0, test_1.expect)(page.getByText(processName)).not.toBeVisible({
                        timeout: 60000,
                    });
                }
            });
        });
        // Skipped due to bug #7716: https://github.com/camunda/connectors/issues/7716
        SM_8_9_1.test.skip('Main User Can Create & Access Tenant - Connectors Flow @tasklistV2', async ({ page, modelerHomePage, modelerCreatePage, operateProcessInstancePage, operateProcessesPage, operateHomePage, navigationPage, managementIdentityTenantPage, connectorSettingsPage, connectorMarketplacePage, optimizeHomePage, optimizeDashboardPage, ocIdentityHomePage, ocTenantPage, }) => {
            SM_8_9_1.test.slow();
            const randomString = await (0, _setup_1.generateRandomStringAsync)(3);
            const processName = 'Main_User_Connectors_Flow_' + randomString;
            const tenantName = 'Tenant_Main_Connectors';
            await SM_8_9_1.test.step('Create Tenant And Assign User in OC Identity', async () => {
                await ocIdentityHomePage.clickTenantsTab();
                await ocTenantPage.createTenant(tenantName);
                await ocIdentityHomePage.clickTenantsTab();
                await ocTenantPage.clickTenant(tenantName);
                await ocTenantPage.assignUserToTenant('demo');
                await ocIdentityHomePage.clickTenantsTab();
                await ocTenantPage.clickTenant(tenantName);
                await ocTenantPage.assignRoleToTenant('connectors', 'connectorsConnectors');
            });
            await SM_8_9_1.test.step('Create Tenant And Assign User in Management Identity', async () => {
                await navigationPage.goToManagementIdentity();
                await managementIdentityTenantPage.createTenant(tenantName);
                await managementIdentityTenantPage.assignUserToTenant(tenantName, 'demo', demoUserDisplayText);
                if (process.env.IS_OPTIMIZE !== 'false') {
                    await managementIdentityTenantPage.assignClientToTenant('Optimize');
                }
            });
            await SM_8_9_1.test.step('Open Cross Component Test Project', async () => {
                await navigationPage.goToModeler();
                await modelerHomePage.createCrossComponentProjectFolder();
                await modelerHomePage.clickDiagramTypeDropdown();
                await modelerHomePage.clickBpmnTemplateOption();
            });
            await SM_8_9_1.test.step('Create A Diagram with a REST Connector and Start Process Instance', async () => {
                await (0, UtilitiesPage_1.modelRestConnector)(modelerCreatePage, connectorSettingsPage, connectorMarketplacePage, processName, 'https://camunda.proxy.beeceptor.com/pre-prod/no-auth-test', 'noAuth', 'body');
                await modelerCreatePage.runProcessInstance('', tenantName); //Identity bug https://github.com/camunda/camunda/issues/35834
            });
            await SM_8_9_1.test.step('View Process Instance in Operate & assert process is complete', async () => {
                await navigationPage.goToOperate();
                await operateHomePage.clickProcessesTab();
                await operateProcessesPage.clickProcessInstanceLink(processName, 'completed');
                await operateProcessInstancePage.completedIconAssertion();
                await operateProcessInstancePage.assertVariablesListVisible();
                await (0, test_1.expect)(page.getByText('"Awesome!"')).toBeVisible({
                    timeout: 60000,
                });
                await operateProcessInstancePage.tenantNameAssertion(tenantName);
            });
            if (process.env.IS_OPTIMIZE !== 'false') {
                await SM_8_9_1.test.step('Assert Process has been successfully imported in Optimize', async () => {
                    await navigationPage.goToOptimize();
                    await optimizeHomePage.clickDashboardLink();
                    await (0, test_1.expect)(async () => {
                        await page.reload();
                        await optimizeDashboardPage.clickFilterTable();
                        await optimizeDashboardPage.fillFilterTable(processName);
                        await optimizeDashboardPage.processAssertion(processName);
                    }).toPass({ timeout: 300000, intervals: [15000] });
                });
            }
        });
        (0, SM_8_9_1.test)('Second User Can Access Tenant Created By Main User - User Task Flow', async ({ page, modelerHomePage, modelerCreatePage, taskPanelPage, operateProcessInstancePage, operateProcessesPage, taskDetailsPage, operateHomePage, navigationPage, managementIdentityTenantPage, optimizeDashboardPage, optimizeHomePage, ocIdentityHomePage, ocTenantPage, managementIdentityPage, keycloakAdminPage, keycloakLoginPage, ocIdentityRolesPage, ocIdentityMappingRulesPage, browser, }) => {
            SM_8_9_1.test.slow();
            const randomString = await (0, _setup_1.generateRandomStringAsync)(3);
            const processName = 'Second_User_User_Task_Flow_' + randomString;
            const tenantName = 'Tenant_Second_User_' + randomString;
            const testUser = (await (0, _setup_1.generateRandomStringAsync)(6)).toLowerCase();
            const password = process.env.DISTRO_QA_E2E_TESTS_IDENTITY_FIRSTUSER_PASSWORD;
            const credentials = {
                username: testUser,
                password: password,
            };
            await SM_8_9_1.test.step('Create new Test User And Assign to Role', async () => {
                await (0, UtilitiesPage_1.createUserAndAssignToRole)(page, navigationPage, managementIdentityPage, keycloakLoginPage, keycloakAdminPage, ocIdentityHomePage, ocIdentityMappingRulesPage, ocIdentityRolesPage, testUser, password);
            });
            await SM_8_9_1.test.step('Create Tenant And Assign User in OC Identity', async () => {
                await ocIdentityHomePage.clickTenantsTab();
                await ocTenantPage.createTenant(tenantName);
                await ocIdentityHomePage.clickTenantsTab();
                await ocTenantPage.clickTenant(tenantName);
                await ocTenantPage.assignUserToTenant(testUser);
            });
            await SM_8_9_1.test.step('Create Tenant And Assign User in Management Identity', async () => {
                await navigationPage.goToManagementIdentity();
                await managementIdentityTenantPage.createTenant(tenantName);
                await managementIdentityTenantPage.assignUserToTenant(tenantName, testUser, `qacamunda+${testUser}@gmail.com`);
                if (process.env.IS_OPTIMIZE !== 'false') {
                    await managementIdentityTenantPage.assignClientToTenant('Optimize');
                }
            });
            await SM_8_9_1.test.step('Clear cookies and reset session', async () => {
                await (0, resetSession_1.resetSession)(browser, page); //a workaround for https://github.com/camunda/camunda/issues/34513
            });
            await SM_8_9_1.test.step('Open Cross Component Test Project', async () => {
                await navigationPage.goToModeler(undefined, credentials);
                await modelerHomePage.createCrossComponentProjectFolder();
                await modelerHomePage.clickDiagramTypeDropdown();
                await modelerHomePage.clickBpmnTemplateOption();
            });
            await SM_8_9_1.test.step('Create A Diagram with a User Task and Start Process Instance', async () => {
                await modelerCreatePage.modelCamundaUserTaskDiagram(processName);
                await modelerCreatePage.runProcessInstance('', tenantName); //Identity bug https://github.com/camunda/camunda/issues/35834
            });
            await SM_8_9_1.test.step('View Process Instance in Operate, complete User Task in Tasklist & assert process complete in Operate', async () => {
                await navigationPage.goToOperate(undefined, credentials);
                await operateHomePage.clickProcessesTab();
                await operateProcessesPage.clickProcessInstanceLink(processName);
                await operateProcessInstancePage.activeIconAssertion();
                await navigationPage.goToTasklist(undefined, credentials);
                await taskPanelPage.openTask(processName);
                await taskDetailsPage.clickAssignToMeButton();
                await taskDetailsPage.clickCompleteTaskButton();
                await (0, test_1.expect)(page.getByText('Task completed')).toBeVisible({
                    timeout: 200000,
                });
                await navigationPage.goToOperate(undefined, credentials);
                await operateHomePage.clickProcessesTab();
                await operateProcessesPage.clickProcessInstanceLink(processName, 'completed');
                await operateProcessInstancePage.completedIconAssertion();
                await operateProcessInstancePage.tenantNameAssertion(tenantName);
            });
            if (process.env.IS_OPTIMIZE !== 'false') {
                await SM_8_9_1.test.step('Assert Process has been successfully imported in Optimize', async () => {
                    await navigationPage.goToOptimize(undefined, credentials);
                    await optimizeHomePage.clickDashboardLink();
                    await (0, test_1.expect)(async () => {
                        await page.reload();
                        await optimizeDashboardPage.clickFilterTable();
                        await optimizeDashboardPage.fillFilterTable(processName);
                        await optimizeDashboardPage.processAssertion(processName);
                    }).toPass({ timeout: 300000, intervals: [15000] });
                });
            }
        });
        // Skipped due to bug #320: https://github.com/camunda/marketplace-api/issues/320
        SM_8_9_1.test.skip('Second User Can Access Tenant Created By Main User - Connectors Flow @tasklistV2', async ({ page, modelerHomePage, modelerCreatePage, operateProcessInstancePage, operateProcessesPage, operateHomePage, navigationPage, managementIdentityTenantPage, connectorSettingsPage, connectorMarketplacePage, optimizeHomePage, optimizeDashboardPage, ocIdentityHomePage, ocTenantPage, managementIdentityPage, keycloakAdminPage, keycloakLoginPage, ocIdentityRolesPage, ocIdentityMappingRulesPage, browser, }) => {
            SM_8_9_1.test.slow();
            const randomString = await (0, _setup_1.generateRandomStringAsync)(3);
            const processName = 'Second_User_Connectors_Flow_' + randomString;
            const tenantName = 'Tenant_Second_Connectors';
            const testUser = (await (0, _setup_1.generateRandomStringAsync)(6)).toLowerCase();
            const password = process.env.DISTRO_QA_E2E_TESTS_IDENTITY_FIRSTUSER_PASSWORD;
            const credentials = {
                username: testUser,
                password: password,
            };
            await SM_8_9_1.test.step('Create new Test User And Assign to Role', async () => {
                await (0, UtilitiesPage_1.createUserAndAssignToRole)(page, navigationPage, managementIdentityPage, keycloakLoginPage, keycloakAdminPage, ocIdentityHomePage, ocIdentityMappingRulesPage, ocIdentityRolesPage, testUser, password);
            });
            await SM_8_9_1.test.step('Create Tenant And Assign User in OC Identity', async () => {
                await ocIdentityHomePage.clickTenantsTab();
                await ocTenantPage.createTenant(tenantName);
                await ocIdentityHomePage.clickTenantsTab();
                await ocTenantPage.clickTenant(tenantName);
                await ocTenantPage.assignUserToTenant(testUser);
                await ocIdentityHomePage.clickTenantsTab();
                await ocTenantPage.clickTenant(tenantName);
                await ocTenantPage.assignRoleToTenant('connectors', 'connectorsConnectors');
            });
            await SM_8_9_1.test.step('Create Tenant And Assign User in Management Identity', async () => {
                await navigationPage.goToManagementIdentity();
                await managementIdentityTenantPage.createTenant(tenantName);
                await managementIdentityTenantPage.assignUserToTenant(tenantName, testUser, `qacamunda+${testUser}@gmail.com`);
                if (process.env.IS_OPTIMIZE !== 'false') {
                    await managementIdentityTenantPage.assignClientToTenant('Optimize');
                }
            });
            await SM_8_9_1.test.step('Clear cookies and reset session', async () => {
                await (0, resetSession_1.resetSession)(browser, page); //a workaround for https://github.com/camunda/camunda/issues/34513
            });
            await SM_8_9_1.test.step('Open Cross Component Test Project', async () => {
                await navigationPage.goToModeler(undefined, credentials);
                await modelerHomePage.createCrossComponentProjectFolder();
                await modelerHomePage.clickDiagramTypeDropdown();
                await modelerHomePage.clickBpmnTemplateOption();
            });
            await SM_8_9_1.test.step('Create A Diagram with a REST Connector and Start Process Instance', async () => {
                await (0, UtilitiesPage_1.modelRestConnector)(modelerCreatePage, connectorSettingsPage, connectorMarketplacePage, processName, 'https://camunda.proxy.beeceptor.com/pre-prod/no-auth-test', 'noAuth', 'body');
                await modelerCreatePage.runProcessInstance('', tenantName); //Identity bug https://github.com/camunda/camunda/issues/35834
            });
            await SM_8_9_1.test.step('View Process Instance in Operate & assert process is complete', async () => {
                await navigationPage.goToOperate(undefined, credentials);
                await operateHomePage.clickProcessesTab();
                await operateProcessesPage.clickProcessInstanceLink(processName, 'completed');
                await operateProcessInstancePage.completedIconAssertion();
                await operateProcessInstancePage.assertVariablesListVisible();
                await (0, test_1.expect)(page.getByText('"Awesome!"')).toBeVisible({
                    timeout: 60000,
                });
                await operateProcessInstancePage.tenantNameAssertion(tenantName);
            });
            if (process.env.IS_OPTIMIZE !== 'false') {
                await SM_8_9_1.test.step('Assert Process has been successfully imported in Optimize', async () => {
                    await navigationPage.goToOptimize(undefined, credentials);
                    await optimizeHomePage.clickDashboardLink();
                    await (0, test_1.expect)(async () => {
                        await page.reload();
                        await optimizeDashboardPage.clickFilterTable();
                        await optimizeDashboardPage.fillFilterTable(processName);
                        await optimizeDashboardPage.processAssertion(processName);
                    }).toPass({ timeout: 300000, intervals: [15000] });
                });
            }
        });
        (0, SM_8_9_1.test)('Default Tenant Is Available And Used When Tenant Not Set In Deployment', async ({ page, modelerHomePage, modelerCreatePage, taskPanelPage, operateProcessInstancePage, operateProcessesPage, taskDetailsPage, operateHomePage, navigationPage, managementIdentityTenantPage, optimizeHomePage, optimizeDashboardPage, ocIdentityHomePage, ocTenantPage, }) => {
            SM_8_9_1.test.slow();
            const randomString = await (0, _setup_1.generateRandomStringAsync)(3);
            const processName = 'Default_Tenant_Flow_' + randomString;
            const tenantName = 'Default';
            await SM_8_9_1.test.step('Assign User To Default Tenant in OC Identity', async () => {
                await ocIdentityHomePage.clickTenantsTab();
                await ocTenantPage.clickTenant(tenantName);
                await ocTenantPage.assignUserToTenant('demo');
            });
            await SM_8_9_1.test.step('Assign User To Default Tenant in Management Identity', async () => {
                await navigationPage.goToManagementIdentity();
                await managementIdentityTenantPage.assignUserToTenant(tenantName, 'demo', demoUserDisplayText);
                if (process.env.IS_OPTIMIZE !== 'false') {
                    await managementIdentityTenantPage.assignClientToTenant('Optimize');
                }
            });
            await SM_8_9_1.test.step('Open Cross Component Test Project', async () => {
                await navigationPage.goToModeler();
                await modelerHomePage.createCrossComponentProjectFolder();
                await modelerHomePage.clickDiagramTypeDropdown();
                await modelerHomePage.clickBpmnTemplateOption();
            });
            await SM_8_9_1.test.step('Create A Diagram with a User Task and Start Process Instance', async () => {
                await modelerCreatePage.modelCamundaUserTaskDiagram(processName);
                await modelerCreatePage.runProcessInstance('', '');
            });
            await SM_8_9_1.test.step('View Process Instance in Operate, complete User Task in Tasklist & assert process complete in Operate', async () => {
                await navigationPage.goToOperate();
                await operateHomePage.clickProcessesTab();
                await operateProcessesPage.clickProcessInstanceLink(processName);
                await operateProcessInstancePage.activeIconAssertion();
                await navigationPage.goToTasklist();
                await taskPanelPage.openTask(processName);
                await taskDetailsPage.clickAssignToMeButton();
                await taskDetailsPage.clickCompleteTaskButton();
                await (0, test_1.expect)(page.getByText('Task completed')).toBeVisible({
                    timeout: 200000,
                });
                await navigationPage.goToOperate();
                await operateHomePage.clickProcessesTab();
                await operateProcessesPage.clickProcessInstanceLink(processName, 'completed');
                await operateProcessInstancePage.completedIconAssertion();
                await operateProcessInstancePage.tenantNameAssertion(tenantName);
            });
            if (process.env.IS_OPTIMIZE !== 'false') {
                await SM_8_9_1.test.step('Assert Process has been successfully imported in Optimize', async () => {
                    await navigationPage.goToOptimize();
                    await optimizeHomePage.clickDashboardLink();
                    await (0, test_1.expect)(async () => {
                        await page.reload();
                        await optimizeDashboardPage.clickFilterTable();
                        await optimizeDashboardPage.fillFilterTable(processName);
                        await optimizeDashboardPage.processAssertion(processName);
                    }).toPass({ timeout: 300000, intervals: [15000] });
                });
            }
        });
        // Skipped due to bug #320: https://github.com/camunda/marketplace-api/issues/320
        SM_8_9_1.test.skip('User Can Be Assigned To Multiple Tenants @tasklistV2', async ({ page, modelerHomePage, modelerCreatePage, operateProcessInstancePage, operateProcessesPage, operateHomePage, navigationPage, managementIdentityTenantPage, connectorSettingsPage, connectorMarketplacePage, ocIdentityHomePage, ocTenantPage, managementIdentityPage, }) => {
            SM_8_9_1.test.slow();
            const randomString = await (0, _setup_1.generateRandomStringAsync)(3);
            const processName1 = 'Multiple_Tenant_Flow_1' + randomString;
            const processName2 = 'Multiple_Tenant_Flow_2' + randomString;
            const tenantName1 = 'Tenant_1_Connectors';
            const tenantName2 = 'Tenant_2_Connectors';
            await SM_8_9_1.test.step('Create Two Tenants And Assign to Demo User', async () => {
                await ocIdentityHomePage.clickTenantsTab();
                await ocTenantPage.createTenant(tenantName1);
                await ocIdentityHomePage.clickTenantsTab();
                await ocTenantPage.clickTenant(tenantName1);
                await ocTenantPage.assignUserToTenant('demo');
                await ocIdentityHomePage.clickTenantsTab();
                await ocTenantPage.clickTenant(tenantName1);
                await ocTenantPage.assignRoleToTenant('connectors', 'connectorsConnectors');
                await ocIdentityHomePage.clickTenantsTab();
                await ocTenantPage.createTenant(tenantName2);
                await ocIdentityHomePage.clickTenantsTab();
                await ocTenantPage.clickTenant(tenantName2);
                await ocTenantPage.assignUserToTenant('demo');
                await ocIdentityHomePage.clickTenantsTab();
                await ocTenantPage.clickTenant(tenantName2);
                await ocTenantPage.assignRoleToTenant('connectors', 'connectorsConnectors');
            });
            await SM_8_9_1.test.step('Create Two Tenants And Assign to Demo User in Management Identity', async () => {
                await navigationPage.goToManagementIdentity();
                await managementIdentityTenantPage.createTenant(tenantName1);
                await managementIdentityTenantPage.assignUserToTenant(tenantName1, 'demo', demoUserDisplayText);
                if (process.env.IS_OPTIMIZE !== 'false') {
                    await managementIdentityTenantPage.assignClientToTenant('Optimize');
                }
                await managementIdentityPage.clickTenantTab();
                await managementIdentityTenantPage.createTenant(tenantName2);
                await managementIdentityTenantPage.assignUserToTenant(tenantName2, 'demo', demoUserDisplayText);
                if (process.env.IS_OPTIMIZE !== 'false') {
                    await managementIdentityTenantPage.assignClientToTenant('Optimize');
                }
            });
            await SM_8_9_1.test.step('Open Cross Component Test Project', async () => {
                await navigationPage.goToModeler();
                await modelerHomePage.createCrossComponentProjectFolder();
                await modelerHomePage.clickDiagramTypeDropdown();
                await modelerHomePage.clickBpmnTemplateOption();
            });
            await SM_8_9_1.test.step('Create A Diagram with a REST Connector and Start Process Instance With Tenant 1', async () => {
                await (0, UtilitiesPage_1.modelRestConnector)(modelerCreatePage, connectorSettingsPage, connectorMarketplacePage, processName1, 'https://camunda.proxy.beeceptor.com/pre-prod/no-auth-test', 'noAuth', 'body');
                await modelerCreatePage.runProcessInstance('', tenantName1); //Identity bug https://github.com/camunda/camunda/issues/35834
            });
            await SM_8_9_1.test.step('Create A Diagram with a REST Connector and Start Process Instance With Tenant 2', async () => {
                await modelerHomePage.clickProjectBreadcrumb();
                await modelerHomePage.clickDiagramTypeDropdown();
                await modelerHomePage.clickBpmnTemplateOption();
                await (0, UtilitiesPage_1.modelRestConnector)(modelerCreatePage, connectorSettingsPage, connectorMarketplacePage, processName2, 'https://camunda.proxy.beeceptor.com/pre-prod/no-auth-test', 'noAuth', 'body');
                await modelerCreatePage.runProcessInstance('', tenantName2);
            });
            await SM_8_9_1.test.step('View Process Instances in Operate, and Assert Process Complete in Operate with Correct Tenant', async () => {
                await navigationPage.goToOperate();
                await operateHomePage.clickProcessesTab();
                await operateProcessesPage.clickProcessInstanceLink(processName1, 'completed');
                await operateProcessInstancePage.completedIconAssertion();
                await (0, expectTextWithRetry_1.expectTextWithRetry)(page, '"Awesome!"', {
                    postAction: async () => {
                        await page.reload();
                    },
                });
                await operateProcessInstancePage.tenantNameAssertion(tenantName1);
                await operateHomePage.clickProcessesTab();
                await operateProcessesPage.clickProcessInstanceLink(processName2, 'completed');
                await operateProcessInstancePage.completedIconAssertion();
                await (0, expectTextWithRetry_1.expectTextWithRetry)(page, '"Awesome!"', {
                    postAction: async () => {
                        await page.reload();
                    },
                });
                await operateProcessInstancePage.tenantNameAssertion(tenantName2);
            });
        });
        (0, SM_8_9_1.test)('Revoking Tenant Access User Flow', async ({ page, modelerHomePage, modelerCreatePage, taskPanelPage, operateProcessInstancePage, operateProcessesPage, taskDetailsPage, operateHomePage, navigationPage, managementIdentityTenantPage, optimizeHomePage, optimizeDashboardPage, ocIdentityHomePage, ocTenantPage, }) => {
            SM_8_9_1.test.slow();
            const randomString = await (0, _setup_1.generateRandomStringAsync)(3);
            const processName1 = 'Revoke_Tenant_Flow_1' + randomString;
            const processName2 = 'Revoke_Tenant_Flow_2' + randomString;
            const tenantName = 'Revoke_' + randomString;
            await SM_8_9_1.test.step('Create Tenant And Assign User in OC Identity', async () => {
                await ocIdentityHomePage.clickTenantsTab();
                await ocTenantPage.createTenant(tenantName);
                await ocIdentityHomePage.clickTenantsTab();
                await ocTenantPage.clickTenant(tenantName);
                await ocTenantPage.assignUserToTenant('demo');
            });
            await SM_8_9_1.test.step('Create Tenant And Assign User in Management Identity', async () => {
                await navigationPage.goToManagementIdentity();
                await managementIdentityTenantPage.createTenant(tenantName);
                await managementIdentityTenantPage.assignUserToTenant(tenantName, 'demo', demoUserDisplayText);
                if (process.env.IS_OPTIMIZE !== 'false') {
                    await managementIdentityTenantPage.assignClientToTenant('Optimize');
                }
            });
            await SM_8_9_1.test.step('Open Cross Component Test Project', async () => {
                await navigationPage.goToModeler();
                await modelerHomePage.createCrossComponentProjectFolder();
                await modelerHomePage.clickDiagramTypeDropdown();
                await modelerHomePage.clickBpmnTemplateOption();
            });
            await SM_8_9_1.test.step('Create A Diagram with a User Task and Start Process Instance', async () => {
                await modelerCreatePage.modelCamundaUserTaskDiagram(processName1);
                await modelerCreatePage.runProcessInstance('', tenantName); //Identity bug https://github.com/camunda/camunda/issues/35834
            });
            await SM_8_9_1.test.step('View Process Instance in Operate, complete User Task in Tasklist & assert process complete in Operate', async () => {
                await navigationPage.goToOperate();
                await operateHomePage.clickProcessesTab();
                await operateProcessesPage.clickProcessActiveCheckbox();
                await operateProcessesPage.clickProcessInstanceLink(processName1);
                await operateProcessInstancePage.activeIconAssertion();
                await navigationPage.goToTasklist();
                await taskPanelPage.openTask(processName1);
                await taskDetailsPage.clickAssignToMeButton();
                await taskDetailsPage.clickCompleteTaskButton();
                await (0, test_1.expect)(page.getByText('Task completed')).toBeVisible({
                    timeout: 200000,
                });
                await navigationPage.goToOperate();
                await operateHomePage.clickProcessesTab();
                await operateProcessesPage.clickProcessInstanceLink(processName1, 'completed');
                await operateProcessInstancePage.completedIconAssertion();
                await operateProcessInstancePage.tenantNameAssertion(tenantName);
            });
            if (process.env.IS_OPTIMIZE !== 'false') {
                await SM_8_9_1.test.step('Assert Process has been successfully imported in Optimize', async () => {
                    await navigationPage.goToOptimize();
                    await optimizeHomePage.clickDashboardLink();
                    await (0, test_1.expect)(async () => {
                        await page.reload();
                        await optimizeDashboardPage.clickFilterTable();
                        await optimizeDashboardPage.fillFilterTable(processName1);
                        await optimizeDashboardPage.processAssertion(processName1);
                    }).toPass({ timeout: 300000, intervals: [15000] });
                });
            }
            await SM_8_9_1.test.step('Delete Tenant Access For Demo User OC', async () => {
                await navigationPage.goToOCIdentity();
                await (0, expectLocatorWithRetry_1.expectLocatorWithRetry)(page, ocIdentityHomePage.tenantsTab, {
                    postAction: async () => {
                        await navigationPage.goToOCIdentity();
                    },
                });
                await ocIdentityHomePage.clickTenantsTab();
                await ocTenantPage.removeUserFromTenant(tenantName);
            });
            await SM_8_9_1.test.step('Delete Tenant Access For Demo User', async () => {
                await navigationPage.goToManagementIdentity();
                await managementIdentityTenantPage.removeUserFromTenant(tenantName);
            });
            await SM_8_9_1.test.step('Open Cross Component Test Project', async () => {
                await navigationPage.goToModeler();
                await modelerHomePage.createCrossComponentProjectFolder();
                await modelerHomePage.clickDiagramTypeDropdown();
                await modelerHomePage.clickBpmnTemplateOption();
            });
            await SM_8_9_1.test.step('Create A Diagram with a User Task and Assert Cannot Start Process Instance With Tenant', async () => {
                await modelerCreatePage.modelCamundaUserTaskDiagram(processName2);
                await modelerCreatePage.clickDeployAndRunMainButton();
                await modelerCreatePage.clickTenantIdInput();
                await modelerCreatePage.fillTenantIdInput(tenantName);
                await modelerCreatePage.clickDeployAndRunSubButton();
                await (0, test_1.expect)(page.getByText('The diagram failed to deploy & run')).toBeVisible({ timeout: 60000 });
            });
            await SM_8_9_1.test.step('Assert "demo" user cannot view process in Tasklist, Operate or Optimize', async () => {
                await navigationPage.goToOperate();
                await operateHomePage.clickProcessesTab();
                await page.waitForLoadState('networkidle');
                await (0, test_1.expect)(page.getByText(processName1)).not.toBeVisible({
                    timeout: 60000,
                });
                await (0, test_1.expect)(page.getByText(processName2)).not.toBeVisible({
                    timeout: 60000,
                });
                await navigationPage.goToTasklist();
                await page.waitForLoadState('networkidle');
                await (0, test_1.expect)(page.getByText(processName1)).not.toBeVisible({
                    timeout: 60000,
                });
                await (0, test_1.expect)(page.getByText(processName2)).not.toBeVisible({
                    timeout: 60000,
                });
                if (process.env.IS_OPTIMIZE !== 'false') {
                    await navigationPage.goToOptimize();
                    await optimizeHomePage.clickDashboardLink();
                    await optimizeDashboardPage.processAssertion(processName1, {
                        not: true,
                        timeout: 300000,
                    });
                    await optimizeDashboardPage.processAssertion(processName2, {
                        not: true,
                    });
                }
            });
        });
    });
}
