"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const test_1 = require("@playwright/test");
const _8_6_1 = require("../../fixtures/8.6");
const _setup_1 = require("../../test-setup.js");
const UtilitiesPage_1 = require("../../pages/8.6/UtilitiesPage");
const sleep_1 = require("../../utils/sleep");
const resetSession_1 = require("../../utils/resetSession");
const users_1 = require("../../utils/users");
const mainUser = (0, users_1.getTestUser)('twentyFifthUser');
_8_6_1.test.describe.configure({ mode: 'parallel' });
_8_6_1.test.describe('RBA Enabled User Flows Test', () => {
    const clusterNames = {
        'RBA On User Flow - No User Permission': 'First RBA Cluster',
        'RBA On User Flow - Permission for One Process': 'Second RBA Cluster',
        'RBA On User Flow - Permission for All Processes': 'Third RBA Cluster',
    };
    _8_6_1.test.beforeEach(async ({ page, homePage, clusterPage, loginPage }, testInfo) => {
        await (0, UtilitiesPage_1.loginWithRetry)(page, loginPage, mainUser, (testInfo.workerIndex + 1) * 1000);
        await (0, test_1.expect)(homePage.clusterTab).toBeVisible({ timeout: 120000 });
        await homePage.clickClusters();
        (0, test_1.expect)(clusterNames[testInfo.title]).toBeTruthy();
        await clusterPage.createClusterIfNotExists(clusterNames[testInfo.title]);
    });
    _8_6_1.test.afterEach(async ({ page, homePage, clusterPage, clusterDetailsPage, appsPage }, testInfo) => {
        await (0, _setup_1.captureScreenshot)(page, testInfo);
        await (0, _setup_1.captureFailureVideo)(page, testInfo);
        (0, test_1.expect)(clusterNames[testInfo.title]).toBeTruthy();
        await (0, UtilitiesPage_1.disableRBA)(clusterNames[testInfo.title], homePage, clusterPage, clusterDetailsPage, appsPage);
    });
    (0, _8_6_1.test)('RBA On User Flow - No User Permission', async ({ page, homePage, modelerHomePage, appsPage, modelerCreatePage, clusterPage, clusterDetailsPage, taskPanelPage, taskProcessesPage, operateHomePage, consoleOrganizationsPage, }) => {
        _8_6_1.test.slow();
        const clusterName = clusterNames['RBA On User Flow - No User Permission'];
        const randomString = await (0, _setup_1.generateRandomStringAsync)(3);
        const processName = 'BEFORERBANOPERM' + randomString;
        const processName1 = processName + '1';
        const processName2 = processName + '2';
        const processId1 = processName + '1';
        const processId2 = processName + '2';
        await _8_6_1.test.step('Navigate to Console and Ensure RBA is Disabled', async () => {
            await (0, UtilitiesPage_1.disableRBA)(clusterName, homePage, clusterPage, clusterDetailsPage, appsPage);
        });
        await _8_6_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_6_1.test.step('Navigate to Cross Component Test Project', async () => {
            await modelerHomePage.clickCrossComponentProjectFolder();
        });
        await _8_6_1.test.step('Create Two BPMN Diagrams with User Task and Start Process Instance', async () => {
            await (0, UtilitiesPage_1.runMultipleProcesses)(clusterName, page, modelerHomePage, modelerCreatePage, {
                processName: processName,
                uploadFromFile: 'Camunda_Simple_User_Task_3',
            });
        });
        await _8_6_1.test.step('Navigate back to Console and Enable RBA', async () => {
            await (0, UtilitiesPage_1.enableRBA)(clusterName, homePage, clusterPage, clusterDetailsPage, appsPage);
            await (0, sleep_1.sleep)(30000);
        });
        await _8_6_1.test.step('Navigate to Users and Make Sure that No Authorized Resources Are Created', async () => {
            await homePage.clickOrganization();
            await consoleOrganizationsPage.clickUsersTab();
            await consoleOrganizationsPage.clickMainUser(mainUser.username);
            await consoleOrganizationsPage.clickAuthorizations();
            await (0, test_1.expect)(page.getByText(processId1, { exact: true })).not.toBeVisible({
                timeout: 120000,
            });
            await (0, test_1.expect)(page.getByText(processId2, { exact: true })).not.toBeVisible({
                timeout: 120000,
            });
        });
        await _8_6_1.test.step('Navigate to Tasklist and Make Sure that the Two Deployed Processes Are Not Accessible', async () => {
            await appsPage.clickCamundaApps();
            await appsPage.clickTasklist(clusterName);
            await (0, test_1.expect)(taskPanelPage.taskListPageBanner).toBeVisible({
                timeout: 120000,
            });
            await taskPanelPage.clickProcessesTab();
            await taskProcessesPage.clickpopupContinueButton();
            await (0, test_1.expect)(page.getByText(processName1)).not.toBeVisible({
                timeout: 120000,
            });
            await (0, test_1.expect)(page.getByText(processName2)).not.toBeVisible({
                timeout: 120000,
            });
        });
        await _8_6_1.test.step('Navigate to Operate and Make Sure that the Two Deployed Processes Are Not Accessible', async () => {
            await appsPage.clickCamundaApps();
            await appsPage.clickOperate(clusterName);
            await (0, test_1.expect)(operateHomePage.operateBanner).toBeVisible({
                timeout: 120000,
            });
            await operateHomePage.clickProcessesTab();
            await page.reload();
            await (0, test_1.expect)(page.getByText(processName1)).not.toBeVisible({
                timeout: 120000,
            });
            await (0, test_1.expect)(page.getByText(processName2)).not.toBeVisible({
                timeout: 120000,
            });
        });
    });
    (0, _8_6_1.test)('RBA On User Flow - Permission for One Process', async ({ page, homePage, modelerHomePage, appsPage, modelerCreatePage, clusterPage, clusterDetailsPage, taskPanelPage, taskProcessesPage, operateHomePage, consoleOrganizationsPage, browser, loginPage, }) => {
        _8_6_1.test.slow();
        const clusterName = clusterNames['RBA On User Flow - Permission for One Process'];
        const randomString = await (0, _setup_1.generateRandomStringAsync)(3);
        const processName = 'BEFORERBA' + randomString;
        const processName1 = processName + '1';
        const processName2 = processName + '2';
        const processId1 = processName + '1';
        await _8_6_1.test.step('Navigate to Console and Ensure RBA is Disabled', async () => {
            await (0, UtilitiesPage_1.disableRBA)(clusterName, homePage, clusterPage, clusterDetailsPage, appsPage);
        });
        await _8_6_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_6_1.test.step('Navigate to Cross Component Test Project', async () => {
            await modelerHomePage.clickCrossComponentProjectFolder();
        });
        await _8_6_1.test.step('Create Two BPMN Diagrams with User Task and Start Process Instance', async () => {
            await (0, UtilitiesPage_1.runMultipleProcesses)(clusterName, page, modelerHomePage, modelerCreatePage, {
                processName: processName,
                uploadFromFile: 'Camunda_Simple_User_Task_2',
            });
        });
        await _8_6_1.test.step('Navigate back to Console and Enable RBA', async () => {
            await (0, UtilitiesPage_1.enableRBA)(clusterName, homePage, clusterPage, clusterDetailsPage, appsPage);
            await (0, sleep_1.sleep)(60000);
        });
        await _8_6_1.test.step('Navigate to Users and Create Authorized Resource For Process 1', async () => {
            await homePage.clickOrganization();
            await consoleOrganizationsPage.clickUsersTab();
            await consoleOrganizationsPage.clickMainUser(mainUser.username);
            await consoleOrganizationsPage.clickAuthorizations();
            await (0, test_1.expect)(page.getByText(processId1, { exact: true })).not.toBeVisible({
                timeout: 60000,
            });
            await consoleOrganizationsPage.clickCreateResourceAuthorizationButton();
            await (0, test_1.expect)(consoleOrganizationsPage.createResourceAuthorizationDialog).toBeVisible({ timeout: 60000 });
            await consoleOrganizationsPage.clickNextButton();
            await consoleOrganizationsPage.clickProcessIdInput();
            await consoleOrganizationsPage.fillProcessIdInput(processId1);
            await consoleOrganizationsPage.clickNextButton();
            await consoleOrganizationsPage.checkReadPermissionCheckbox();
            await consoleOrganizationsPage.checkStartInstancePermissionCheckbox();
            await consoleOrganizationsPage.clickCreateAuthorizedResourceButton();
            await consoleOrganizationsPage.processIdResourceAssertion(processId1);
        });
        await _8_6_1.test.step('Navigate to Tasklist and Only First Process Is Accessible', async () => {
            await appsPage.clickCamundaApps();
            await appsPage.clickTasklist(clusterName);
            await (0, test_1.expect)(taskPanelPage.taskListPageBanner).toBeVisible({
                timeout: 120000,
            });
            await taskPanelPage.clickProcessesTab();
            await taskProcessesPage.clickpopupContinueButton();
            await (0, UtilitiesPage_1.assertPageTextWithRetry)(page, processName1, false, 30000);
            await (0, test_1.expect)(page.getByText(processName2)).not.toBeVisible({
                timeout: 120000,
            });
        });
        await _8_6_1.test.step('Navigate to Operate and Only First Process Is Accessible', async () => {
            await appsPage.clickCamundaApps();
            await appsPage.clickOperate(clusterName);
            await (0, test_1.expect)(operateHomePage.operateBanner).toBeVisible({
                timeout: 120000,
            });
            await operateHomePage.clickProcessesTab();
            await (0, UtilitiesPage_1.assertPageTextWithRetry)(page, processName1, false, 30000);
            await (0, test_1.expect)(page.getByText(processName2)).not.toBeVisible({
                timeout: 120000,
            });
        });
        await _8_6_1.test.step('Clear cookies and reset session', async () => {
            await (0, resetSession_1.resetSession)(browser, page);
        });
        await _8_6_1.test.step('Login as Test User', async () => {
            await loginPage.loginWithTestUser({
                username: process.env.C8_USERNAME_TEST_2,
                password: process.env.C8_PASSWORD_TEST_2,
            });
        });
        await _8_6_1.test.step('Navigate to Operate and Check Processes Are Not Accessible', async () => {
            await appsPage.clickCamundaApps();
            await appsPage.clickOperate(clusterName);
            await (0, test_1.expect)(operateHomePage.operateBanner).toBeVisible({
                timeout: 120000,
            });
            await operateHomePage.clickProcessesTab();
            await (0, UtilitiesPage_1.assertPageTextWithRetry)(page, processName1, true, 30000);
            await (0, UtilitiesPage_1.assertPageTextWithRetry)(page, processName2, true, 30000);
        });
        await _8_6_1.test.step('Navigate to Tasklist and Check Processes Are Not Accessible', async () => {
            await appsPage.clickCamundaApps();
            await appsPage.clickTasklist(clusterName);
            await (0, test_1.expect)(taskPanelPage.taskListPageBanner).toBeVisible({
                timeout: 120000,
            });
            await taskPanelPage.clickProcessesTab();
            await taskProcessesPage.clickpopupContinueButton();
            await (0, UtilitiesPage_1.assertPageTextWithRetry)(page, processName1, true, 30000);
            await (0, UtilitiesPage_1.assertPageTextWithRetry)(page, processName2, true, 30000);
        });
    });
    (0, _8_6_1.test)('RBA On User Flow - Permission for All Processes', async ({ page, homePage, modelerHomePage, appsPage, modelerCreatePage, clusterPage, clusterDetailsPage, taskPanelPage, taskProcessesPage, operateHomePage, consoleOrganizationsPage, }) => {
        _8_6_1.test.slow();
        const clusterName = clusterNames['RBA On User Flow - Permission for All Processes'];
        const randomString = await (0, _setup_1.generateRandomStringAsync)(3);
        const processName = 'AFTER_RBA' + randomString;
        const processName1 = processName + '1';
        const processName2 = processName + '2';
        const processId1 = processName + '1';
        const processId2 = processName + '2';
        await _8_6_1.test.step('Navigate to Console and Enable RBA', async () => {
            await (0, UtilitiesPage_1.enableRBA)(clusterName, homePage, clusterPage, clusterDetailsPage, appsPage);
            await (0, sleep_1.sleep)(90000);
        });
        await _8_6_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_6_1.test.step('Navigate to Cross Component Test Project', async () => {
            await modelerHomePage.clickCrossComponentProjectFolder();
        });
        await _8_6_1.test.step('Create Two BPMN Diagrams with User Task and Start Process Instance', async () => {
            await (0, UtilitiesPage_1.runMultipleProcesses)(clusterName, page, modelerHomePage, modelerCreatePage, {
                processName: processName,
                uploadFromFile: 'Camunda_Simple_User_Task_1',
            });
        });
        await _8_6_1.test.step('Navigate to Users and Assert Authorized Resources Are Created For Both Processes', async () => {
            await appsPage.clickCamundaApps();
            await appsPage.clickConsoleLink();
            await homePage.clickOrganization();
            await consoleOrganizationsPage.clickUsersTab();
            await consoleOrganizationsPage.clickMainUser(mainUser.username);
            await consoleOrganizationsPage.clickAuthorizations();
            await consoleOrganizationsPage.authorizedResourceAssertion(processId1);
            await consoleOrganizationsPage.authorizedResourceAssertion(processId2);
        });
        await _8_6_1.test.step('Navigate to Tasklist and Assert Both Processes Are Accessible', async () => {
            await appsPage.clickCamundaApps();
            await appsPage.clickTasklist(clusterName);
            await (0, test_1.expect)(taskPanelPage.taskListPageBanner).toBeVisible({
                timeout: 120000,
            });
            await taskPanelPage.clickProcessesTab();
            await taskProcessesPage.clickpopupContinueButton();
            await (0, UtilitiesPage_1.assertPageTextWithRetry)(page, processName1, false, 30000);
            await (0, UtilitiesPage_1.assertPageTextWithRetry)(page, processName2, false, 30000);
        });
        await _8_6_1.test.step('Assert Processes Can Be Started From Tasklist', async () => {
            await taskPanelPage.clickTasksTab();
            const firstProcessTaskCount = await taskPanelPage.taskCount(processName1);
            const secondProcessTaskCount = await taskPanelPage.taskCount(processName2);
            //Start first process
            await taskPanelPage.clickProcessesTab();
            await taskProcessesPage.startProcess(processName1);
            const updatedFirstProcessTaskCount = await taskPanelPage.taskCount(processName1);
            (0, test_1.expect)(updatedFirstProcessTaskCount).toBe(firstProcessTaskCount + 1);
            //Start second process
            await taskPanelPage.clickProcessesTab();
            await taskProcessesPage.startProcess(processName2);
            const updatedSecondProcessTaskCount = await taskPanelPage.taskCount(processName2);
            (0, test_1.expect)(updatedSecondProcessTaskCount).toBe(secondProcessTaskCount + 1);
        });
        await _8_6_1.test.step('Navigate to Operate and Assert Both Processes Are Accessible', async () => {
            await appsPage.clickCamundaApps();
            await appsPage.clickOperate(clusterName);
            await (0, test_1.expect)(operateHomePage.operateBanner).toBeVisible({
                timeout: 120000,
            });
            await operateHomePage.clickProcessesTab();
            await (0, UtilitiesPage_1.assertPageTextWithRetry)(page, processName1, false, 30000);
            await (0, UtilitiesPage_1.assertPageTextWithRetry)(page, processName2, false, 30000);
        });
    });
});
