"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const test_1 = require("@playwright/test");
const SM_8_6_1 = require("../../fixtures/SM-8.6");
const _setup_1 = require("../../test-setup.js");
const UtlitiesPage_1 = require("../../pages/SM-8.6/UtlitiesPage");
SM_8_6_1.test.describe('RBA Enabled User Flows Test', () => {
    SM_8_6_1.test.beforeEach(async ({ navigationPage }, testInfo) => {
        await navigationPage.goToModeler((testInfo.workerIndex + 1) * 1000);
    });
    SM_8_6_1.test.afterEach(async ({ page }, testInfo) => {
        await (0, _setup_1.captureScreenshot)(page, testInfo);
        await (0, _setup_1.captureFailureVideo)(page, testInfo);
    });
    (0, SM_8_6_1.test)('RBA On User Flow - No User Permission', async ({ page, identityPage, modelerHomePage, modelerCreatePage, taskPanelPage, taskProcessesPage, operateHomePage, navigationPage, }) => {
        if (process.env.IS_RBA !== 'true') {
            SM_8_6_1.test.skip(true, 'Skipping test because test environment does not have RBA enabled');
        }
        SM_8_6_1.test.slow();
        const randomString = await (0, _setup_1.generateRandomStringAsync)(3);
        const processName = 'RBA_NO_PERM' + randomString;
        await SM_8_6_1.test.step('Open Cross Component Test Project', async () => {
            await modelerHomePage.clickCrossComponentProjectFolder();
        });
        await SM_8_6_1.test.step('Create Two BPMN Diagrams with User Task and Start Process Instance', async () => {
            await (0, UtlitiesPage_1.runMultipleProcesses)(page, modelerHomePage, modelerCreatePage, 2, processName);
        });
        await SM_8_6_1.test.step('Navigate back to Identity and assert RBA is Enabled and No Authorized Resources Are Created', async () => {
            await navigationPage.goToIdentity();
            await identityPage.clickUsersLink();
            await identityPage.clickDemoUser();
            await (0, test_1.expect)(identityPage.authorizationsTab).toBeVisible({
                timeout: 60000,
            });
            await identityPage.clickAuthorizationsTab();
            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_6_1.test.step('Navigate to Tasklist and Make Sure that the Two Deployed Processes Are Not Accessible', async () => {
            await navigationPage.goToTasklist();
            await taskPanelPage.clickProcessesTab();
            await taskProcessesPage.clickpopupContinueButton();
            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_6_1.test.step('Navigate to Operate and Make Sure that the Two Deployed Processes Are Not Accessible', async () => {
            await navigationPage.goToOperate();
            await (0, test_1.expect)(operateHomePage.operateBanner).toBeVisible({
                timeout: 120000,
            });
            await operateHomePage.clickProcessesTab();
            await page.reload();
            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,
            });
        });
    });
    (0, SM_8_6_1.test)('RBA On User Flow - Permission for One Process', async ({ page, modelerHomePage, modelerCreatePage, taskPanelPage, taskProcessesPage, operateHomePage, identityUsersPage, loginPage, navigationPage, identityPage, settingsPage, }) => {
        if (process.env.IS_RBA !== 'true') {
            SM_8_6_1.test.skip(true, 'Skipping test because test environment does not have RBA enabled');
        }
        SM_8_6_1.test.slow();
        const randomString = await (0, _setup_1.generateRandomStringAsync)(3);
        const processName = 'RBA_ONE_PERM' + randomString;
        await SM_8_6_1.test.step('Navigate back to Identity and assert RBA is Enabled', async () => {
            await navigationPage.goToIdentity();
            await identityPage.clickUsersLink();
            await identityPage.clickDemoUser();
            await (0, test_1.expect)(identityPage.authorizationsTab).toBeVisible({
                timeout: 60000,
            });
        });
        await SM_8_6_1.test.step('Navigate to Web Modeler', async () => {
            await navigationPage.goToModeler();
        });
        await SM_8_6_1.test.step('Open Cross Component Test Project', async () => {
            await modelerHomePage.clickCrossComponentProjectFolder();
        });
        await SM_8_6_1.test.step('Create Two BPMN Diagrams with User Task and Start Process Instance', async () => {
            await (0, UtlitiesPage_1.runMultipleProcesses)(page, modelerHomePage, modelerCreatePage, 2, processName, processName);
        });
        await SM_8_6_1.test.step('Navigate to Users and Create Authorized Resource For Process 1', async () => {
            await navigationPage.goToIdentity();
            await identityPage.clickUsersLink();
            await identityPage.clickDemoUser();
            await identityPage.clickAuthorizationsTab();
            await (0, test_1.expect)(page.getByText(`${processName}1`).last()).not.toBeVisible({
                timeout: 120000,
            });
            await identityUsersPage.createResourceAuthorization(`${processName}1`);
        });
        await SM_8_6_1.test.step('Navigate to Operate and Only First Process Is Accessible', async () => {
            await navigationPage.goToOperate();
            await (0, test_1.expect)(operateHomePage.operateBanner).toBeVisible({
                timeout: 120000,
            });
            await operateHomePage.clickProcessesTab();
            await page.reload();
            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_6_1.test.step('Navigate to Tasklist and Only First Process Is Accessible', async () => {
            await navigationPage.goToTasklist();
            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()).not.toBeVisible({
                timeout: 120000,
            });
        });
        await SM_8_6_1.test.step('Logout and Login with "bart" User', async () => {
            await settingsPage.clickOpenSettingsButton();
            await settingsPage.clickLogoutButton();
            await loginPage.fillUsername('bart');
            await (0, test_1.expect)(loginPage.usernameInput).toHaveValue('bart');
            await loginPage.fillPassword(process.env.DISTRO_QA_E2E_TESTS_IDENTITY_THIRDUSER_PASSWORD);
            await loginPage.clickLoginButton();
            await (0, test_1.expect)(taskPanelPage.tasklistBanner).toBeVisible({ timeout: 120000 });
        });
        await SM_8_6_1.test.step('Navigate to Tasklist and Check Processes Are Not Accessible', async () => {
            await navigationPage.goToTasklist();
            await taskPanelPage.clickProcessesTab();
            await taskProcessesPage.clickpopupContinueButton();
            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_6_1.test.step('Navigate to Operate and Check Processes Are Not Accessible', async () => {
            await navigationPage.goToOperate();
            await (0, test_1.expect)(operateHomePage.operateBanner).toBeVisible({
                timeout: 120000,
            });
            await operateHomePage.clickProcessesTab();
            await page.reload();
            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,
            });
        });
    });
    (0, SM_8_6_1.test)('RBA On User Flow - Permission for All Processes', async ({ page, modelerHomePage, modelerCreatePage, taskPanelPage, taskProcessesPage, operateHomePage, identityUsersPage, navigationPage, identityPage, }) => {
        if (process.env.IS_RBA !== 'true') {
            SM_8_6_1.test.skip(true, 'Skipping test because test environment does not have RBA enabled');
        }
        SM_8_6_1.test.slow();
        const randomString = await (0, _setup_1.generateRandomStringAsync)(3);
        const processName = 'RBA_ALL_PERM' + randomString;
        await SM_8_6_1.test.step('Navigate back to Identity and assert RBA is Enabled', async () => {
            await navigationPage.goToIdentity();
            await identityPage.clickUsersLink();
            await identityPage.clickDemoUser();
            await (0, test_1.expect)(identityPage.authorizationsTab).toBeVisible({
                timeout: 60000,
            });
        });
        await SM_8_6_1.test.step('Navigate to Web Modeler', async () => {
            await navigationPage.goToModeler();
        });
        await SM_8_6_1.test.step('Open Cross Component Test Project', async () => {
            await modelerHomePage.clickCrossComponentProjectFolder();
        });
        await SM_8_6_1.test.step('Create Two BPMN Diagrams with User Task and Start Process Instance', async () => {
            await (0, UtlitiesPage_1.runMultipleProcesses)(page, modelerHomePage, modelerCreatePage, 2, processName, processName);
        });
        await SM_8_6_1.test.step('Navigate to Users and Create Authorized Resource For Both Processes', async () => {
            await navigationPage.goToIdentity();
            await identityPage.clickUsersLink();
            await identityPage.clickDemoUser();
            await identityPage.clickAuthorizationsTab();
            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 identityUsersPage.createResourceAuthorization(`${processName}1`);
            await identityUsersPage.createResourceAuthorization(`${processName}2`);
        });
        await SM_8_6_1.test.step('Navigate to Tasklist and Only First Process Is Accessible', async () => {
            await navigationPage.goToTasklist();
            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_6_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`);
            //Start first process
            await taskPanelPage.clickProcessesTab();
            await taskProcessesPage.startProcess(`${processName}1`);
            const updatedFirstProcessTaskCount = await taskPanelPage.taskCount(`${processName}1`);
            (0, test_1.expect)(updatedFirstProcessTaskCount).toBe(firstProcessTaskCount + 1);
            //Start second process
            await taskPanelPage.clickProcessesTab();
            await taskProcessesPage.startProcess(`${processName}2`);
            const updatedSecondProcessTaskCount = await taskPanelPage.taskCount(`${processName}2`);
            (0, test_1.expect)(updatedSecondProcessTaskCount).toBe(secondProcessTaskCount + 1);
        });
        await SM_8_6_1.test.step('Navigate to Operate and Check Processes Are Not Accessible', async () => {
            await navigationPage.goToOperate();
            await (0, test_1.expect)(operateHomePage.operateBanner).toBeVisible({
                timeout: 120000,
            });
            await operateHomePage.clickProcessesTab();
            await page.reload();
            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,
            });
        });
    });
});
