"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const test_1 = require("@playwright/test");
const SM_8_10_1 = require("../../fixtures/SM-8.10");
const _setup_1 = require("../../test-setup.js");
const UtilitiesPage_1 = require("../../pages/SM-8.10/UtilitiesPage");
const node_process_1 = __importDefault(require("node:process"));
const resetSession_1 = require("../../utils/resetSession");
const sleep_1 = require("../../utils/sleep");
if (node_process_1.default.env.IS_RBA === 'true') {
    SM_8_10_1.test.describe.configure({ mode: 'parallel' });
    SM_8_10_1.test.describe('RBA Enabled User Flows Test', () => {
        const idsToBeDeleted = {};
        // eslint-disable-next-line no-empty-pattern
        SM_8_10_1.test.beforeEach(async ({}, testInfo) => {
            idsToBeDeleted[testInfo.title] = { roleIds: [], mappingIds: [] };
        });
        SM_8_10_1.test.afterEach(async ({ page, navigationPage, ocIdentityHomePage, ocIdentityRolesPage, ocIdentityMappingRulesPage, browser, }, testInfo) => {
            await (0, _setup_1.captureScreenshot)(page, testInfo);
            await (0, _setup_1.captureFailureVideo)(page, testInfo);
            await (0, resetSession_1.resetSession)(browser, page);
            await navigationPage.goToOCAdmin();
            const ids = idsToBeDeleted[testInfo.title];
            if (ids['mappingIds'].length > 0) {
                for (const id of ids['mappingIds']) {
                    await ocIdentityMappingRulesPage.deleteMappingRule(id);
                }
            }
            if (ids['roleIds'].length > 0) {
                await ocIdentityHomePage.clickRolesTab();
                for (const id of ids['roleIds']) {
                    await ocIdentityRolesPage.deleteRole(id, { throwError: false });
                }
            }
        });
        (0, SM_8_10_1.test)('RBA On User Flow - No User Permission @tasklistV1', async ({ page, modelerHomePage, modelerCreatePage, taskPanelPage, taskProcessesPage, operateHomePage, navigationPage, managementIdentityPage, keycloakLoginPage, keycloakAdminPage, ocIdentityHomePage, ocIdentityMappingRulesPage, ocIdentityRolesPage, ocIdentityAuthorizationsPage, browser, }, testInfo) => {
            SM_8_10_1.test.slow();
            const processName = 'RBA_NO_PERM' + (await (0, _setup_1.generateRandomStringAsync)(3));
            const testUser = (await (0, _setup_1.generateRandomStringAsync)(6)).toLowerCase();
            const password = node_process_1.default.env.DISTRO_QA_E2E_TESTS_IDENTITY_FIRSTUSER_PASSWORD;
            const credentials = {
                username: testUser,
                password: password,
            };
            const role = `roleNoPerm${testUser}`;
            await SM_8_10_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, role, idsToBeDeleted[testInfo.title]);
            });
            await SM_8_10_1.test.step('Create Resource Authorization', async () => {
                await navigationPage.goToOCAdmin();
                await ocIdentityHomePage.clickAuthorizationsTab();
                await ocIdentityAuthorizationsPage.clickResourceTab();
                await ocIdentityAuthorizationsPage.createAuthorization({
                    ownerType: 'ROLE',
                    ownerId: role,
                    resourceType: 'RESOURCE',
                    resourceId: '*',
                    accessPermissions: ['CREATE'],
                });
            });
            await SM_8_10_1.test.step('Create Process Definition Authorizations For Both Processes', async () => {
                await ocIdentityAuthorizationsPage.clickProcessDefinitionTab();
                await ocIdentityAuthorizationsPage.createAuthorization({
                    ownerType: 'ROLE',
                    ownerId: role,
                    resourceType: 'PROCESS_DEFINITION',
                    resourceId: `${processName}1`,
                    accessPermissions: ['CREATE_PROCESS_INSTANCE'],
                });
                await ocIdentityAuthorizationsPage.clickProcessDefinitionTab();
                await ocIdentityAuthorizationsPage.createAuthorization({
                    ownerType: 'ROLE',
                    ownerId: role,
                    resourceType: 'PROCESS_DEFINITION',
                    resourceId: `${processName}2`,
                    accessPermissions: ['CREATE_PROCESS_INSTANCE'],
                });
            });
            await SM_8_10_1.test.step('Create COMPONENT Authorization', async () => {
                await ocIdentityAuthorizationsPage.clickComponentTab();
                await ocIdentityAuthorizationsPage.createAuthorization({
                    ownerType: 'ROLE',
                    ownerId: role,
                    resourceType: 'COMPONENT',
                    resourceId: '*',
                    accessPermissions: ['ACCESS'],
                });
            });
            await SM_8_10_1.test.step('Create Authorization Authorization', async () => {
                await ocIdentityAuthorizationsPage.clickAuthorizationTab();
                await ocIdentityAuthorizationsPage.createAuthorization({
                    ownerType: 'ROLE',
                    ownerId: role,
                    resourceType: 'AUTHORIZATION',
                    resourceId: '*',
                    accessPermissions: ['CREATE', 'READ', 'UPDATE', 'DELETE'],
                });
            });
            await SM_8_10_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_10_1.test.step('Navigate to Web Modeler', async () => {
                await navigationPage.goToModeler(undefined, credentials);
            });
            await SM_8_10_1.test.step('Open Cross Component Test Project', async () => {
                await modelerHomePage.createCrossComponentProjectFolder();
            });
            await SM_8_10_1.test.step('Create Two BPMN Diagrams with User Task and Start Process Instance', async () => {
                await (0, UtilitiesPage_1.runMultipleProcesses)(page, modelerHomePage, modelerCreatePage, 2, processName, processName);
            });
            await SM_8_10_1.test.step('Navigate back to Identity and Ensure User Has Only Create Authorization Permission', async () => {
                await navigationPage.goToOCAdmin(undefined, credentials);
                await ocIdentityHomePage.clickAuthorizationsTab();
                await ocIdentityAuthorizationsPage.clickProcessDefinitionTab();
                await (0, test_1.expect)(page.getByRole('row').filter({
                    hasText: `${role}${processName}1CREATE_PROCESS_INSTANCE`,
                })).toBeVisible({
                    timeout: 30000,
                });
                await (0, test_1.expect)(page.getByRole('row').filter({
                    hasText: `${role}${processName}2CREATE_PROCESS_INSTANCE`,
                })).toBeVisible({
                    timeout: 30000,
                });
            });
            await SM_8_10_1.test.step('Navigate to Operate and Make Sure that the Two Deployed Processes Are Not Accessible', async () => {
                await navigationPage.goToOperate(undefined, credentials);
                await (0, test_1.expect)(operateHomePage.operateBanner).toBeVisible({
                    timeout: 120000,
                });
                await operateHomePage.clickProcessesTab();
                await (0, test_1.expect)(page.getByText(`${processName}1`).last()).not.toBeVisible({
                    timeout: 120000,
                });
                await (0, test_1.expect)(page.getByText(`${processName}2`).last()).not.toBeVisible({
                    timeout: 120000,
                });
            });
            await SM_8_10_1.test.step('Navigate to Tasklist and Make Sure that the Two Deployed Processes Are Accessible', async () => {
                await navigationPage.goToTasklist(undefined, credentials);
                await taskPanelPage.clickProcessesTab();
                await taskProcessesPage.clickpopupContinueButton();
                await (0, test_1.expect)(page.getByText(`${processName}1`).last()).toBeVisible({
                    timeout: 120000,
                });
                await (0, test_1.expect)(page.getByText(`${processName}2`).last()).toBeVisible({
                    timeout: 120000,
                });
            });
            await SM_8_10_1.test.step('Navigate back to Identity and Remove Create Authorization Permission From Both Process', async () => {
                await navigationPage.goToOCAdmin(undefined, credentials);
                await ocIdentityHomePage.clickAuthorizationsTab();
                await ocIdentityAuthorizationsPage.clickProcessDefinitionTab();
                await ocIdentityAuthorizationsPage.deleteAuthorization(`${processName}1`, 'PROCESS_DEFINITION');
                await ocIdentityAuthorizationsPage.clickProcessDefinitionTab();
                await ocIdentityAuthorizationsPage.deleteAuthorization(`${processName}2`, 'PROCESS_DEFINITION');
                await (0, sleep_1.sleep)(10000);
            });
            await SM_8_10_1.test.step('Navigate to Tasklist and Make Sure that the Two Deployed Processes Are Not Accessible', async () => {
                await navigationPage.goToTasklist(undefined, credentials);
                await taskPanelPage.clickProcessesTab();
                await taskProcessesPage.clickpopupContinueButton();
                await (0, UtilitiesPage_1.assertLocatorVisibleWithRetry)(page, page.getByText(`${processName}1`), `${processName}1`, 20000, true);
                await (0, UtilitiesPage_1.assertLocatorVisibleWithRetry)(page, page.getByText(`${processName}2`), `${processName}2`, 20000, true);
            });
        });
        (0, SM_8_10_1.test)('RBA On User Flow - No User Permission @tasklistV2', async ({ page, modelerHomePage, modelerCreatePage, taskPanelPage, taskProcessesPage, operateHomePage, navigationPage, managementIdentityPage, keycloakLoginPage, keycloakAdminPage, ocIdentityHomePage, ocIdentityMappingRulesPage, ocIdentityRolesPage, ocIdentityAuthorizationsPage, browser, }, testInfo) => {
            SM_8_10_1.test.slow();
            const processName = 'RBA_NO_PERM' + (await (0, _setup_1.generateRandomStringAsync)(3));
            const testUser = (await (0, _setup_1.generateRandomStringAsync)(6)).toLowerCase();
            const password = node_process_1.default.env.DISTRO_QA_E2E_TESTS_IDENTITY_FIRSTUSER_PASSWORD;
            const credentials = {
                username: testUser,
                password: password,
            };
            const role = `roleNoPerm${testUser}`;
            await SM_8_10_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, role, idsToBeDeleted[testInfo.title]);
            });
            await SM_8_10_1.test.step('Create Resource Authorization', async () => {
                await navigationPage.goToOCAdmin();
                await ocIdentityHomePage.clickAuthorizationsTab();
                await ocIdentityAuthorizationsPage.clickResourceTab();
                await ocIdentityAuthorizationsPage.createAuthorization({
                    ownerType: 'ROLE',
                    ownerId: role,
                    resourceType: 'RESOURCE',
                    resourceId: '*',
                    accessPermissions: ['CREATE'],
                });
            });
            await SM_8_10_1.test.step('Create Process Definition Authorizations For Both Processes', async () => {
                await ocIdentityAuthorizationsPage.clickProcessDefinitionTab();
                await ocIdentityAuthorizationsPage.createAuthorization({
                    ownerType: 'ROLE',
                    ownerId: role,
                    resourceType: 'PROCESS_DEFINITION',
                    resourceId: `${processName}1`,
                    accessPermissions: [
                        'CREATE_PROCESS_INSTANCE',
                        'READ_PROCESS_DEFINITION',
                    ],
                });
                await ocIdentityAuthorizationsPage.clickProcessDefinitionTab();
                await ocIdentityAuthorizationsPage.createAuthorization({
                    ownerType: 'ROLE',
                    ownerId: role,
                    resourceType: 'PROCESS_DEFINITION',
                    resourceId: `${processName}2`,
                    accessPermissions: [
                        'CREATE_PROCESS_INSTANCE',
                        'READ_PROCESS_DEFINITION',
                    ],
                });
            });
            await SM_8_10_1.test.step('Create COMPONENT Authorization', async () => {
                await ocIdentityAuthorizationsPage.clickComponentTab();
                await ocIdentityAuthorizationsPage.createAuthorization({
                    ownerType: 'ROLE',
                    ownerId: role,
                    resourceType: 'COMPONENT',
                    resourceId: '*',
                    accessPermissions: ['ACCESS'],
                });
            });
            await SM_8_10_1.test.step('Create Authorization Authorization', async () => {
                await ocIdentityAuthorizationsPage.clickAuthorizationTab();
                await ocIdentityAuthorizationsPage.createAuthorization({
                    ownerType: 'ROLE',
                    ownerId: role,
                    resourceType: 'AUTHORIZATION',
                    resourceId: '*',
                    accessPermissions: ['CREATE', 'READ', 'UPDATE', 'DELETE'],
                });
            });
            await SM_8_10_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_10_1.test.step('Navigate to Web Modeler', async () => {
                await navigationPage.goToModeler(undefined, credentials);
            });
            await SM_8_10_1.test.step('Open Cross Component Test Project', async () => {
                await modelerHomePage.createCrossComponentProjectFolder();
            });
            await SM_8_10_1.test.step('Create Two BPMN Diagrams with User Task and Start Process Instance', async () => {
                await (0, UtilitiesPage_1.runMultipleProcesses)(page, modelerHomePage, modelerCreatePage, 2, processName, processName);
            });
            await SM_8_10_1.test.step('Navigate back to Identity and Ensure User Has Only Create Authorization Permission', async () => {
                await navigationPage.goToOCAdmin(undefined, credentials);
                await ocIdentityHomePage.clickAuthorizationsTab();
                await ocIdentityAuthorizationsPage.clickProcessDefinitionTab();
                await (0, test_1.expect)(page.getByRole('row').filter({
                    hasText: `${role}${processName}1CREATE_PROCESS_INSTANCE`,
                })).toBeVisible({
                    timeout: 30000,
                });
                await (0, test_1.expect)(page.getByRole('row').filter({
                    hasText: `${role}${processName}2CREATE_PROCESS_INSTANCE`,
                })).toBeVisible({
                    timeout: 30000,
                });
            });
            await SM_8_10_1.test.step('Navigate to Operate and Make Sure that the Two Deployed Processes Are Not Accessible', async () => {
                await navigationPage.goToOperate(undefined, credentials);
                await (0, test_1.expect)(operateHomePage.operateBanner).toBeVisible({
                    timeout: 120000,
                });
                await operateHomePage.clickProcessesTab();
                await (0, test_1.expect)(page.getByText(`${processName}1`).last()).not.toBeVisible({
                    timeout: 120000,
                });
                await (0, test_1.expect)(page.getByText(`${processName}2`).last()).not.toBeVisible({
                    timeout: 120000,
                });
            });
            await SM_8_10_1.test.step('Navigate to Tasklist and Make Sure that the Two Deployed Processes Are Accessible', async () => {
                await navigationPage.goToTasklist(undefined, credentials);
                await taskPanelPage.clickProcessesTab();
                await taskProcessesPage.clickpopupContinueButton();
                await (0, UtilitiesPage_1.expectTextWithPagination)(page, processName + '1', true, 120000);
                await (0, UtilitiesPage_1.expectTextWithPagination)(page, processName + '2', true, 120000);
            });
            await SM_8_10_1.test.step('Navigate back to Identity and Remove Create Authorization Permission From Both Process', async () => {
                await navigationPage.goToOCAdmin(undefined, credentials);
                await ocIdentityHomePage.clickAuthorizationsTab();
                await ocIdentityAuthorizationsPage.clickProcessDefinitionTab();
                await ocIdentityAuthorizationsPage.deleteAuthorization(`${processName}1`, 'PROCESS_DEFINITION');
                await ocIdentityAuthorizationsPage.clickProcessDefinitionTab();
                await ocIdentityAuthorizationsPage.deleteAuthorization(`${processName}2`, 'PROCESS_DEFINITION');
                await (0, sleep_1.sleep)(30000);
            });
            await SM_8_10_1.test.step('Navigate to Tasklist and Make Sure that the Two Deployed Processes Are Not Accessible', async () => {
                await navigationPage.goToTasklist(undefined, credentials);
                await taskPanelPage.clickProcessesTab();
                await taskProcessesPage.clickpopupContinueButton();
                await (0, UtilitiesPage_1.assertLocatorVisibleWithRetry)(page, page.getByText(`${processName}1`), `${processName}1`, 30000, true);
                await (0, UtilitiesPage_1.assertLocatorVisibleWithRetry)(page, page.getByText(`${processName}2`), `${processName}2`, 30000, true);
            });
        });
        (0, SM_8_10_1.test)('RBA On User Flow - Permission for One Process @tasklistV1', async ({ page, modelerHomePage, modelerCreatePage, taskPanelPage, taskProcessesPage, operateHomePage, navigationPage, managementIdentityPage, keycloakLoginPage, keycloakAdminPage, ocIdentityHomePage, ocIdentityMappingRulesPage, ocIdentityRolesPage, ocIdentityAuthorizationsPage, browser, }, testInfo) => {
            SM_8_10_1.test.slow();
            const randomString = await (0, _setup_1.generateRandomStringAsync)(3);
            const processName = 'RBA_ONE_PERM' + randomString;
            const testUser = (await (0, _setup_1.generateRandomStringAsync)(6)).toLowerCase();
            const password = node_process_1.default.env.DISTRO_QA_E2E_TESTS_IDENTITY_FIRSTUSER_PASSWORD;
            const credentials = {
                username: testUser,
                password: password,
            };
            const role1 = `rbaOnePerm${testUser}1`;
            const role2 = `rbaOnePerm${testUser}2`;
            await SM_8_10_1.test.step('Create new Test User And Assign the User to Two Roles', async () => {
                await (0, UtilitiesPage_1.createUserAndAssignToRole)(page, navigationPage, managementIdentityPage, keycloakLoginPage, keycloakAdminPage, ocIdentityHomePage, ocIdentityMappingRulesPage, ocIdentityRolesPage, testUser, password, role1, idsToBeDeleted[testInfo.title]);
                await (0, UtilitiesPage_1.assignMappingToRole)(page, ocIdentityHomePage, ocIdentityRolesPage, role2, `${testUser}-user-mapping`, idsToBeDeleted[testInfo.title]);
            });
            await SM_8_10_1.test.step('Navigate to Authorizations', async () => {
                await navigationPage.goToOCAdmin();
                await ocIdentityHomePage.clickAuthorizationsTab();
            });
            await SM_8_10_1.test.step('Grant CRUD Process Definition Authorization For First Process', async () => {
                await ocIdentityAuthorizationsPage.clickProcessDefinitionTab();
                await ocIdentityAuthorizationsPage.createAuthorization({
                    ownerType: 'ROLE',
                    ownerId: role1,
                    resourceType: 'PROCESS_DEFINITION',
                    resourceId: `${processName}1`,
                    accessPermissions: [
                        'CREATE_PROCESS_INSTANCE',
                        'READ_PROCESS_INSTANCE',
                        'READ_USER_TASK',
                    ],
                });
            });
            await SM_8_10_1.test.step('Grant Only Create Process Definition Authorization For Second Process', async () => {
                await ocIdentityAuthorizationsPage.clickProcessDefinitionTab();
                await ocIdentityAuthorizationsPage.createAuthorization({
                    ownerType: 'ROLE',
                    ownerId: role1,
                    resourceType: 'PROCESS_DEFINITION',
                    resourceId: `${processName}2`,
                    accessPermissions: ['CREATE_PROCESS_INSTANCE'],
                });
            });
            await SM_8_10_1.test.step('Grant Resource Authorization', async () => {
                await ocIdentityAuthorizationsPage.clickResourceTab();
                await ocIdentityAuthorizationsPage.createAuthorization({
                    ownerType: 'ROLE',
                    ownerId: role1,
                    resourceType: 'RESOURCE',
                    resourceId: '*',
                    accessPermissions: ['CREATE'],
                });
            });
            await SM_8_10_1.test.step('Grant COMPONENT Authorization', async () => {
                await ocIdentityAuthorizationsPage.clickComponentTab();
                await ocIdentityAuthorizationsPage.createAuthorization({
                    ownerType: 'ROLE',
                    ownerId: role1,
                    resourceType: 'COMPONENT',
                    resourceId: '*',
                    accessPermissions: ['ACCESS'],
                });
                await ocIdentityAuthorizationsPage.createAuthorization({
                    ownerType: 'ROLE',
                    ownerId: role2,
                    resourceType: 'COMPONENT',
                    resourceId: '*',
                    accessPermissions: ['ACCESS'],
                });
            });
            await SM_8_10_1.test.step('Grant Authorization Authorization', async () => {
                await ocIdentityAuthorizationsPage.clickAuthorizationTab();
                await ocIdentityAuthorizationsPage.createAuthorization({
                    ownerType: 'ROLE',
                    ownerId: role1,
                    resourceType: 'AUTHORIZATION',
                    resourceId: '*',
                    accessPermissions: ['CREATE', 'READ', 'UPDATE', 'DELETE'],
                });
            });
            await SM_8_10_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_10_1.test.step('Navigate to Web Modeler', async () => {
                await navigationPage.goToModeler(undefined, credentials);
            });
            await SM_8_10_1.test.step('Open Cross Component Test Project', async () => {
                await modelerHomePage.createCrossComponentProjectFolder();
            });
            await SM_8_10_1.test.step('Create Two BPMN Diagrams with User Task and Start Process Instance', async () => {
                await (0, UtilitiesPage_1.runMultipleProcesses)(page, modelerHomePage, modelerCreatePage, 2, processName, processName);
            });
            await SM_8_10_1.test.step('Navigate to Operate and Only First Process Is Accessible', async () => {
                await navigationPage.goToOperate(undefined, credentials);
                await (0, test_1.expect)(operateHomePage.operateBanner).toBeVisible({
                    timeout: 120000,
                });
                await operateHomePage.clickProcessesTab();
                await (0, test_1.expect)(page.getByText(`${processName}1`).last()).toBeVisible({
                    timeout: 120000,
                });
                await (0, test_1.expect)(page.getByText(`${processName}2`).last()).not.toBeVisible({
                    timeout: 120000,
                });
            });
            await SM_8_10_1.test.step('Navigate to Tasklist and Both Processes Are Accessible', async () => {
                await navigationPage.goToTasklist(undefined, credentials);
                await taskPanelPage.clickProcessesTab();
                await taskProcessesPage.clickpopupContinueButton();
                await (0, UtilitiesPage_1.expectTextWithPagination)(page, processName + '1', true, 120000);
                await (0, UtilitiesPage_1.expectTextWithPagination)(page, processName + '2', true, 120000);
            });
            await SM_8_10_1.test.step('Navigate to Roles and Delete First Role', async () => {
                await (0, resetSession_1.resetSession)(browser, page);
                await navigationPage.goToOCAdmin();
                await ocIdentityHomePage.clickRolesTab();
                await ocIdentityRolesPage.deleteRole(role1);
            });
            await SM_8_10_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_10_1.test.step('Navigate to Operate and Check Processes Are Not Accessible', async () => {
                await navigationPage.goToOperate(undefined, credentials);
                await (0, test_1.expect)(operateHomePage.operateBanner).toBeVisible({
                    timeout: 120000,
                });
                await (0, test_1.expect)(page.getByText(`${processName}1`).last()).not.toBeVisible({
                    timeout: 120000,
                });
                await (0, test_1.expect)(page.getByText(`${processName}2`).last()).not.toBeVisible({
                    timeout: 120000,
                });
            });
            await SM_8_10_1.test.step('Navigate to Tasklist and Check Processes Are Not Accessible', async () => {
                await navigationPage.goToTasklist(undefined, credentials);
                await taskPanelPage.clickProcessesTab();
                await taskProcessesPage.clickpopupContinueButton();
                await (0, UtilitiesPage_1.assertLocatorVisibleWithRetry)(page, page.getByText(`${processName}1`), `${processName}1`, 20000, true);
                await (0, UtilitiesPage_1.assertLocatorVisibleWithRetry)(page, page.getByText(`${processName}2`), `${processName}2`, 20000, true);
            });
        });
        (0, SM_8_10_1.test)('RBA On User Flow - Permission for One Process @tasklistV2', async ({ page, modelerHomePage, modelerCreatePage, taskPanelPage, taskProcessesPage, operateHomePage, navigationPage, managementIdentityPage, keycloakLoginPage, keycloakAdminPage, ocIdentityHomePage, ocIdentityMappingRulesPage, ocIdentityRolesPage, ocIdentityAuthorizationsPage, browser, }, testInfo) => {
            SM_8_10_1.test.slow();
            const randomString = await (0, _setup_1.generateRandomStringAsync)(3);
            const processName = 'RBA_ONE_PERM' + randomString;
            const testUser = (await (0, _setup_1.generateRandomStringAsync)(6)).toLowerCase();
            const password = node_process_1.default.env.DISTRO_QA_E2E_TESTS_IDENTITY_FIRSTUSER_PASSWORD;
            const credentials = {
                username: testUser,
                password: password,
            };
            const role1 = `rbaOnePerm${testUser}1`;
            const role2 = `rbaOnePerm${testUser}2`;
            await SM_8_10_1.test.step('Create new Test User And Assign the User to Two Roles', async () => {
                await (0, UtilitiesPage_1.createUserAndAssignToRole)(page, navigationPage, managementIdentityPage, keycloakLoginPage, keycloakAdminPage, ocIdentityHomePage, ocIdentityMappingRulesPage, ocIdentityRolesPage, testUser, password, role1, idsToBeDeleted[testInfo.title]);
                await (0, UtilitiesPage_1.assignMappingToRole)(page, ocIdentityHomePage, ocIdentityRolesPage, role2, `${testUser}-user-mapping`, idsToBeDeleted[testInfo.title]);
            });
            await SM_8_10_1.test.step('Navigate to Authorizations', async () => {
                await navigationPage.goToOCAdmin();
                await ocIdentityHomePage.clickAuthorizationsTab();
            });
            await SM_8_10_1.test.step('Grant CRUD Process Definition Authorization For First Process', async () => {
                await ocIdentityAuthorizationsPage.clickProcessDefinitionTab();
                await ocIdentityAuthorizationsPage.createAuthorization({
                    ownerType: 'ROLE',
                    ownerId: role1,
                    resourceType: 'PROCESS_DEFINITION',
                    resourceId: `${processName}1`,
                    accessPermissions: [
                        'CREATE_PROCESS_INSTANCE',
                        'READ_PROCESS_DEFINITION',
                        'READ_PROCESS_INSTANCE',
                        'READ_USER_TASK',
                    ],
                });
            });
            await SM_8_10_1.test.step('Grant Only Create Process Definition Authorization For Second Process', async () => {
                await ocIdentityAuthorizationsPage.clickProcessDefinitionTab();
                await ocIdentityAuthorizationsPage.createAuthorization({
                    ownerType: 'ROLE',
                    ownerId: role1,
                    resourceType: 'PROCESS_DEFINITION',
                    resourceId: `${processName}2`,
                    accessPermissions: [
                        'CREATE_PROCESS_INSTANCE',
                        'READ_PROCESS_DEFINITION',
                    ],
                });
            });
            await SM_8_10_1.test.step('Grant Resource Authorization', async () => {
                await ocIdentityAuthorizationsPage.clickResourceTab();
                await ocIdentityAuthorizationsPage.createAuthorization({
                    ownerType: 'ROLE',
                    ownerId: role1,
                    resourceType: 'RESOURCE',
                    resourceId: '*',
                    accessPermissions: ['CREATE'],
                });
            });
            await SM_8_10_1.test.step('Grant COMPONENT Authorization', async () => {
                await ocIdentityAuthorizationsPage.clickComponentTab();
                await ocIdentityAuthorizationsPage.createAuthorization({
                    ownerType: 'ROLE',
                    ownerId: role1,
                    resourceType: 'COMPONENT',
                    resourceId: '*',
                    accessPermissions: ['ACCESS'],
                });
                await ocIdentityAuthorizationsPage.createAuthorization({
                    ownerType: 'ROLE',
                    ownerId: role2,
                    resourceType: 'COMPONENT',
                    resourceId: '*',
                    accessPermissions: ['ACCESS'],
                });
            });
            await SM_8_10_1.test.step('Grant Authorization Authorization', async () => {
                await ocIdentityAuthorizationsPage.clickAuthorizationTab();
                await ocIdentityAuthorizationsPage.createAuthorization({
                    ownerType: 'ROLE',
                    ownerId: role1,
                    resourceType: 'AUTHORIZATION',
                    resourceId: '*',
                    accessPermissions: ['CREATE', 'READ', 'UPDATE', 'DELETE'],
                });
            });
            await SM_8_10_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_10_1.test.step('Navigate to Web Modeler', async () => {
                await navigationPage.goToModeler(undefined, credentials);
            });
            await SM_8_10_1.test.step('Open Cross Component Test Project', async () => {
                await modelerHomePage.createCrossComponentProjectFolder();
            });
            await SM_8_10_1.test.step('Create Two BPMN Diagrams with User Task and Start Process Instance', async () => {
                await (0, UtilitiesPage_1.runMultipleProcesses)(page, modelerHomePage, modelerCreatePage, 2, processName, processName);
            });
            await SM_8_10_1.test.step('Navigate to Operate and Only First Process Is Accessible', async () => {
                await navigationPage.goToOperate(undefined, credentials);
                await (0, test_1.expect)(operateHomePage.operateBanner).toBeVisible({
                    timeout: 120000,
                });
                await operateHomePage.clickProcessesTab();
                await (0, test_1.expect)(page.getByText(`${processName}1`).last()).toBeVisible({
                    timeout: 120000,
                });
                await (0, test_1.expect)(page.getByText(`${processName}2`).last()).not.toBeVisible({
                    timeout: 120000,
                });
            });
            await SM_8_10_1.test.step('Navigate to Tasklist and Both Processes Are Accessible', async () => {
                await navigationPage.goToTasklist(undefined, credentials);
                await taskPanelPage.clickProcessesTab();
                await taskProcessesPage.clickpopupContinueButton();
                await (0, UtilitiesPage_1.expectTextWithPagination)(page, processName + '1', true, 120000);
                await (0, UtilitiesPage_1.expectTextWithPagination)(page, processName + '2', true, 120000);
            });
            await SM_8_10_1.test.step('Navigate to Roles and Delete First Role', async () => {
                await (0, resetSession_1.resetSession)(browser, page);
                await navigationPage.goToOCAdmin();
                await ocIdentityHomePage.clickRolesTab();
                await ocIdentityRolesPage.deleteRole(role1);
            });
            await SM_8_10_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_10_1.test.step('Navigate to Operate and Check Processes Are Not Accessible', async () => {
                await navigationPage.goToOperate(undefined, credentials);
                await (0, test_1.expect)(operateHomePage.operateBanner).toBeVisible({
                    timeout: 120000,
                });
                await (0, test_1.expect)(page.getByText(`${processName}1`).last()).not.toBeVisible({
                    timeout: 120000,
                });
                await (0, test_1.expect)(page.getByText(`${processName}2`).last()).not.toBeVisible({
                    timeout: 120000,
                });
            });
            await SM_8_10_1.test.step('Navigate to Tasklist and Check Processes Are Not Accessible', async () => {
                await navigationPage.goToTasklist(undefined, credentials);
                await taskPanelPage.clickProcessesTab();
                await taskProcessesPage.clickpopupContinueButton();
                await (0, UtilitiesPage_1.assertLocatorVisibleWithRetry)(page, page.getByText(`${processName}1`), `${processName}1`, 30000, true);
                await (0, UtilitiesPage_1.assertLocatorVisibleWithRetry)(page, page.getByText(`${processName}2`), `${processName}2`, 30000, true);
            });
        });
        (0, SM_8_10_1.test)('RBA On User Flow - Permission for All Processes', async ({ page, modelerHomePage, modelerCreatePage, taskPanelPage, taskProcessesPage, operateHomePage, navigationPage, managementIdentityPage, keycloakLoginPage, keycloakAdminPage, ocIdentityHomePage, ocIdentityMappingRulesPage, ocIdentityRolesPage, ocIdentityAuthorizationsPage, browser, }, testInfo) => {
            SM_8_10_1.test.slow();
            const processName = 'RBA_ALL_PERM' + (await (0, _setup_1.generateRandomStringAsync)(3));
            const testUser = (await (0, _setup_1.generateRandomStringAsync)(6)).toLowerCase();
            const password = node_process_1.default.env.DISTRO_QA_E2E_TESTS_IDENTITY_FIRSTUSER_PASSWORD;
            const credentials = {
                username: testUser,
                password: password,
            };
            const role = `role${testUser}`;
            await SM_8_10_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, role, idsToBeDeleted[testInfo.title]);
            });
            await SM_8_10_1.test.step('Navigate to Authorizations', async () => {
                await navigationPage.goToOCAdmin();
                await ocIdentityHomePage.clickAuthorizationsTab();
            });
            await SM_8_10_1.test.step('Create Process Definition Authorizations For Both Processes', async () => {
                await ocIdentityAuthorizationsPage.clickProcessDefinitionTab();
                await ocIdentityAuthorizationsPage.createAuthorization({
                    ownerType: 'ROLE',
                    ownerId: role,
                    resourceType: 'PROCESS_DEFINITION',
                    resourceId: '*',
                    accessPermissions: [
                        'CREATE_PROCESS_INSTANCE',
                        'READ_PROCESS_DEFINITION',
                        'READ_USER_TASK',
                        'UPDATE_USER_TASK',
                        'READ_PROCESS_INSTANCE',
                    ],
                });
            });
            await SM_8_10_1.test.step('Create Resource Authorization', async () => {
                await ocIdentityAuthorizationsPage.clickResourceTab();
                await ocIdentityAuthorizationsPage.createAuthorization({
                    ownerType: 'ROLE',
                    ownerId: role,
                    resourceType: 'RESOURCE',
                    resourceId: '*',
                    accessPermissions: ['CREATE'],
                });
            });
            await SM_8_10_1.test.step('Create COMPONENT Authorization', async () => {
                await ocIdentityAuthorizationsPage.clickComponentTab();
                await ocIdentityAuthorizationsPage.createAuthorization({
                    ownerType: 'ROLE',
                    ownerId: role,
                    resourceType: 'COMPONENT',
                    resourceId: '*',
                    accessPermissions: ['ACCESS'],
                });
            });
            await SM_8_10_1.test.step('Create Authorization Authorization', async () => {
                await ocIdentityAuthorizationsPage.clickAuthorizationTab();
                await ocIdentityAuthorizationsPage.createAuthorization({
                    ownerType: 'ROLE',
                    ownerId: role,
                    resourceType: 'AUTHORIZATION',
                    resourceId: '*',
                    accessPermissions: ['CREATE', 'READ', 'UPDATE', 'DELETE'],
                });
            });
            await SM_8_10_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_10_1.test.step('Navigate to Web Modeler', async () => {
                await navigationPage.goToModeler(undefined, credentials);
            });
            await SM_8_10_1.test.step('Open Cross Component Test Project', async () => {
                await modelerHomePage.createCrossComponentProjectFolder();
            });
            await SM_8_10_1.test.step('Create Two BPMN Diagrams with User Task and Start Process Instance', async () => {
                await (0, UtilitiesPage_1.runMultipleProcesses)(page, modelerHomePage, modelerCreatePage, 2, processName, processName);
                await (0, sleep_1.sleep)(60000);
            });
            await SM_8_10_1.test.step('Navigate to Operate and All Processes Are Accessible', async () => {
                await navigationPage.goToOperate(undefined, credentials);
                await (0, test_1.expect)(operateHomePage.operateBanner).toBeVisible({
                    timeout: 120000,
                });
                await operateHomePage.clickProcessesTab();
                await (0, test_1.expect)(page.getByText(`${processName}1`).last()).toBeVisible({
                    timeout: 120000,
                });
                await (0, test_1.expect)(page.getByText(`${processName}2`).last()).toBeVisible({
                    timeout: 120000,
                });
            });
            await SM_8_10_1.test.step('Navigate to Tasklist and All Processes Are Accessible', async () => {
                await navigationPage.goToTasklist(undefined, credentials);
                await taskPanelPage.clickProcessesTab();
                await taskProcessesPage.clickpopupContinueButton();
                await (0, UtilitiesPage_1.expectTextWithPagination)(page, processName + '1', true, 180000);
                await (0, UtilitiesPage_1.expectTextWithPagination)(page, processName + '2', true, 180000);
            });
            await SM_8_10_1.test.step('Assert Processes Can Be Started From Tasklist', async () => {
                await taskPanelPage.clickTasksTab();
                const firstProcessTaskCount = await taskPanelPage.taskCount(`${processName}1`);
                const secondProcessTaskCount = await taskPanelPage.taskCount(`${processName}2`);
                await taskPanelPage.clickProcessesTab();
                await taskProcessesPage.startProcess(`${processName}1`);
                await (0, test_1.expect)(taskPanelPage.filterOptions).toBeVisible({
                    timeout: 120000,
                });
                const updatedFirstProcessTaskCount = await taskPanelPage.taskCount(`${processName}1`);
                (0, test_1.expect)(updatedFirstProcessTaskCount).toBe(firstProcessTaskCount + 1);
                await taskPanelPage.clickProcessesTab();
                await taskProcessesPage.startProcess(`${processName}2`);
                await (0, test_1.expect)(taskPanelPage.filterOptions).toBeVisible({
                    timeout: 120000,
                });
                const updatedSecondProcessTaskCount = await taskPanelPage.taskCount(`${processName}2`);
                (0, test_1.expect)(updatedSecondProcessTaskCount).toBe(secondProcessTaskCount + 1);
            });
        });
    });
}
