"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const _8_10_1 = require("../../fixtures/8.10");
const _setup_1 = require("../../test-setup.js");
const UtilitiesPage_1 = require("../../pages/8.10/UtilitiesPage");
const sleep_1 = require("../../utils/sleep");
const resetSession_1 = require("../../utils/resetSession");
const LoginPage_1 = require("../../pages/8.10/LoginPage");
const test_1 = require("@playwright/test");
const users_1 = require("../../utils/users");
const testUser = (0, users_1.getTestUser)('mainUser');
_8_10_1.test.describe.configure({ mode: 'parallel' });
_8_10_1.test.describe('User Roles User Flow', () => {
    const clusterNames = {
        'Modeler Role User Flow': 'Modeler Role Cluster',
        'Analyst Role User Flow': 'Analyst Role Cluster',
        'Admin Role User Flow': 'Admin Role Cluster',
    };
    _8_10_1.test.beforeEach(async ({ page, homePage, clusterPage, loginPage, clusterDetailsPage, appsPage }, testInfo) => {
        await (0, UtilitiesPage_1.loginWithRetry)(page, loginPage, testUser, (testInfo.workerIndex + 1) * 1000);
        await (0, test_1.expect)(homePage.clusterTab).toBeVisible({ timeout: 120000 });
        await homePage.clickClusters();
        const baseTitle = testInfo.title.split(' @')[0];
        const clusterName = clusterNames[baseTitle];
        (0, test_1.expect)(clusterName, `No cluster mapping for test title: "${testInfo.title}" (normalized: "${baseTitle}")`).toBeTruthy();
        await clusterPage.createClusterIfNotExists(clusterNames[baseTitle]);
        await (0, UtilitiesPage_1.disableRBA)(clusterNames[baseTitle], homePage, clusterPage, clusterDetailsPage, appsPage);
    });
    _8_10_1.test.afterEach(async ({ page }, testInfo) => {
        await (0, _setup_1.captureScreenshot)(page, testInfo);
        await (0, _setup_1.captureFailureVideo)(page, testInfo);
    });
    //Fix will be implemented in  https://github.com/camunda/c8-cross-component-e2e-tests/issues/1236
    _8_10_1.test.skip('Modeler Role User Flow', async ({ page, modelerHomePage, appsPage, homePage, clusterPage, clusterDetailsPage, context, consoleOrganizationsPage, settingsPage, operateHomePage, ocIdentityHomePage, taskPanelPage, optimizeHomePage, modelerCreatePage, }) => {
        _8_10_1.test.slow();
        const randomString = await (0, _setup_1.generateRandomStringAsync)(3);
        const processName = 'User Roles User Flow' + randomString;
        const clusterName = clusterNames['Modeler Role User Flow'];
        await _8_10_1.test.step('Navigate to Console and Enable RBA', async () => {
            await (0, UtilitiesPage_1.enableAuthorizations)(clusterName, homePage, clusterPage, clusterDetailsPage, appsPage);
            await (0, sleep_1.sleep)(15000);
        });
        await _8_10_1.test.step('Change User Role To Modeler', async () => {
            await homePage.clickOrganization();
            await consoleOrganizationsPage.clickUsersTab();
            await consoleOrganizationsPage.selectModelerRole(process.env.C8_USERNAME_TEST_8);
            await settingsPage.clickOpenSettingsButton();
            await settingsPage.clickLogoutButton();
        });
        await _8_10_1.test.step('Clear cookies and reset session', async () => {
            await (0, resetSession_1.resetSessionAll)(context, page);
        });
        await _8_10_1.test.step('Log in as test user', async () => {
            const loginPage = new LoginPage_1.LoginPage(page);
            await loginPage.loginWithTestUser({
                username: process.env.C8_USERNAME_TEST_8,
                password: process.env.C8_PASSWORD_TEST_8,
            });
            await (0, sleep_1.sleep)(600000); //wait for Optimize cache to refresh
        });
        await _8_10_1.test.step('Navigate to Console and Ensure Apps are Available in App Switcher', async () => {
            await appsPage.clickCamundaApps();
            await appsPage.clickConsoleLink();
            await (0, test_1.expect)(homePage.consoleBanner).toBeVisible({
                timeout: 60000,
            });
            await appsPage.clickCamundaApps();
            await appsPage.assertOptimizePresent();
            await appsPage.assertOperatePresent();
            await appsPage.assertTasklistPresent();
            await (0, test_1.expect)(appsPage.modelerLink).toBeVisible();
            await appsPage.clickCamundaApps();
        });
        await _8_10_1.test.step('Navigate to Operate and Ensure Operate is not Accessible', async () => {
            await appsPage.clickCamundaApps();
            await appsPage.clickOperate(clusterName);
            await (0, test_1.expect)(operateHomePage.noPermissionsMessage).toBeVisible({
                timeout: 60000,
            });
        });
        await _8_10_1.test.step('Navigate to Tasklist and Ensure Tasklist is not Accessible', async () => {
            await page.goBack();
            await (0, UtilitiesPage_1.waitForLoadingToFinish)(page);
            await appsPage.clickCamundaApps();
            await appsPage.clickTasklist(clusterName);
            await (0, test_1.expect)(taskPanelPage.noPermissionsMessage).toBeVisible({
                timeout: 60000,
            });
        });
        await _8_10_1.test.step('Navigate to Identity and Ensure Identity is not Accessible', async () => {
            await page.goBack();
            await (0, UtilitiesPage_1.waitForLoadingToFinish)(page);
            await appsPage.clickCamundaApps();
            await appsPage.clickAdmin(clusterName);
            await (0, test_1.expect)(ocIdentityHomePage.noPermissionsMessage).toBeVisible({
                timeout: 60000,
            });
        });
        await _8_10_1.test.step('Navigate to Optimize and Ensure Optimize is Not Accessible', async () => {
            await page.goBack();
            await (0, UtilitiesPage_1.waitForLoadingToFinish)(page);
            await appsPage.clickCamundaApps();
            await appsPage.clickOptimize(clusterName);
            await (0, test_1.expect)(optimizeHomePage.noPermissionsMessage).toBeVisible({
                timeout: 60000,
            });
        });
        await _8_10_1.test.step('Navigate to Modeler and Ensure Diagram Failed To Deploy', async () => {
            await page.goBack();
            await (0, UtilitiesPage_1.waitForLoadingToFinish)(page);
            await appsPage.clickCamundaApps();
            await appsPage.clickModeler();
            await homePage.clickSkipCustomization();
            await modelerHomePage.createCrossComponentProjectFolder();
            await modelerHomePage.clickDiagramTypeDropdown();
            await modelerHomePage.clickBpmnTemplateOption();
            await (0, test_1.expect)(modelerCreatePage.generalPanel).toBeVisible({
                timeout: 90000,
            });
            await modelerCreatePage.enterDiagramName(processName);
            await (0, sleep_1.sleep)(10000);
            await modelerCreatePage.clickAppendElementButton();
            await modelerCreatePage.clickAppendTaskButton();
            await modelerCreatePage.clickAppendElementButton();
            await modelerCreatePage.clickAppendEndEventButton();
            await (0, sleep_1.sleep)(20000);
            await modelerCreatePage.runProcessInstance(clusterName);
            await (0, test_1.expect)(page.getByText('The diagram failed to deploy & run')).toBeVisible({ timeout: 60000 });
            await modelerCreatePage.clickCloseButton();
        });
    });
    //Skipped due to bug 46344: https://github.com/camunda/camunda/issues/46344
    _8_10_1.test.skip('Analyst Role User Flow', async ({ page, modelerHomePage, appsPage, homePage, clusterPage, clusterDetailsPage, browser, consoleOrganizationsPage, settingsPage, operateHomePage, ocIdentityHomePage, taskPanelPage, optimizeHomePage, modelerCreatePage, }) => {
        _8_10_1.test.slow();
        const randomString = await (0, _setup_1.generateRandomStringAsync)(3);
        const processName = 'User Roles User Flow' + randomString;
        const clusterName = clusterNames['Analyst Role User Flow'];
        await _8_10_1.test.step('Navigate to Console and Enable RBA', async () => {
            await (0, UtilitiesPage_1.enableAuthorizations)(clusterName, homePage, clusterPage, clusterDetailsPage, appsPage);
            await (0, sleep_1.sleep)(15000);
        });
        await _8_10_1.test.step('Change User Role To Analyst', async () => {
            await homePage.clickOrganization();
            await consoleOrganizationsPage.clickUsersTab();
            await consoleOrganizationsPage.selectAnalystRole(process.env.C8_USERNAME_TEST_9);
            await settingsPage.clickOpenSettingsButton();
            await settingsPage.clickLogoutButton();
        });
        await _8_10_1.test.step('Clear cookies and reset session', async () => {
            await (0, resetSession_1.resetSession)(browser, page);
        });
        await _8_10_1.test.step('Log in as test user', async () => {
            const loginPage = new LoginPage_1.LoginPage(page);
            await loginPage.loginWithTestUser({
                username: process.env.C8_USERNAME_TEST_9,
                password: process.env.C8_PASSWORD_TEST_9,
            });
            await (0, sleep_1.sleep)(600000); //wait for Optimize cache to refresh
        });
        await _8_10_1.test.step('Navigate to Console and Ensure Apps are Available in App Switcher', async () => {
            await appsPage.clickCamundaApps();
            await appsPage.clickConsoleLink();
            await (0, test_1.expect)(homePage.consoleBanner).toBeVisible({
                timeout: 60000,
            });
            await appsPage.clickCamundaApps();
            await appsPage.assertOptimizePresent();
            await appsPage.assertOperatePresent();
            await appsPage.assertTasklistPresent();
            await (0, test_1.expect)(appsPage.modelerLink).toBeVisible();
            await appsPage.clickCamundaApps();
        });
        await _8_10_1.test.step('Navigate to Operate and Ensure Operate is not Accessible', async () => {
            await appsPage.clickCamundaApps();
            await appsPage.clickOperate(clusterName);
            await (0, UtilitiesPage_1.assertLocatorVisibleWithRetry)(page, operateHomePage.noPermissionsMessage, 'Operate No Permission message');
        });
        await _8_10_1.test.step('Navigate to Tasklist and Ensure Tasklist is not Accessible', async () => {
            await page.goBack();
            await appsPage.clickCamundaApps();
            await appsPage.clickTasklist(clusterName);
            await (0, test_1.expect)(taskPanelPage.noPermissionsMessage).toBeVisible({
                timeout: 60000,
            });
        });
        await _8_10_1.test.step('Navigate to Identity and Ensure Identity is not Accessible', async () => {
            await page.goBack();
            await appsPage.clickCamundaApps();
            await appsPage.clickAdmin(clusterName);
            await (0, test_1.expect)(ocIdentityHomePage.noPermissionsMessage).toBeVisible({
                timeout: 60000,
            });
        });
        await _8_10_1.test.step('Navigate to Optimize and Ensure Optimize is Accessible', async () => {
            await page.goBack();
            await appsPage.clickCamundaApps();
            await appsPage.clickOptimize(clusterName);
            await (0, test_1.expect)(optimizeHomePage.optimizeBanner).toBeVisible({
                timeout: 60000,
            });
        });
        await _8_10_1.test.step('Navigate to Modeler and Ensure Diagram Failed To Deploy', async () => {
            await appsPage.clickCamundaApps();
            await appsPage.clickModeler();
            await homePage.clickSkipCustomization();
            await modelerHomePage.createCrossComponentProjectFolder();
            await modelerHomePage.clickDiagramTypeDropdown();
            await modelerHomePage.clickBpmnTemplateOption();
            await (0, test_1.expect)(modelerCreatePage.generalPanel).toBeVisible({
                timeout: 90000,
            });
            await modelerCreatePage.enterDiagramName(processName);
            await (0, sleep_1.sleep)(10000);
            await modelerCreatePage.clickAppendElementButton();
            await modelerCreatePage.clickAppendTaskButton();
            await modelerCreatePage.clickAppendElementButton();
            await modelerCreatePage.clickAppendEndEventButton();
            await (0, sleep_1.sleep)(20000);
            await modelerCreatePage.runProcessInstance(clusterName, '', {}, '', false);
            await (0, test_1.expect)(page.getByText('The diagram failed to deploy & run')).toBeVisible({ timeout: 60000 });
            await modelerCreatePage.clickCloseButton();
        });
    });
    //Skipped due to bug 46344: https://github.com/camunda/camunda/issues/46344
    _8_10_1.test.skip('Admin Role User Flow', async ({ page, modelerHomePage, appsPage, homePage, clusterPage, clusterDetailsPage, browser, consoleOrganizationsPage, settingsPage, operateHomePage, ocIdentityHomePage, taskPanelPage, optimizeHomePage, modelerCreatePage, }) => {
        _8_10_1.test.slow();
        const randomString = await (0, _setup_1.generateRandomStringAsync)(3);
        const processName = 'User Roles User Flow' + randomString;
        const clusterName = clusterNames['Admin Role User Flow'];
        await _8_10_1.test.step('Navigate to Console and Enable RBA', async () => {
            await (0, UtilitiesPage_1.enableAuthorizations)(clusterName, homePage, clusterPage, clusterDetailsPage, appsPage);
            await (0, sleep_1.sleep)(15000);
        });
        await _8_10_1.test.step('Change User Role To Analyst', async () => {
            await homePage.clickOrganization();
            await consoleOrganizationsPage.clickUsersTab();
            await consoleOrganizationsPage.selectAdminRole(process.env.C8_USERNAME_TEST_10);
            await settingsPage.clickOpenSettingsButton();
            await settingsPage.clickLogoutButton();
        });
        await _8_10_1.test.step('Clear cookies and reset session', async () => {
            await (0, resetSession_1.resetSession)(browser, page);
        });
        await _8_10_1.test.step('Log in as test user', async () => {
            const loginPage = new LoginPage_1.LoginPage(page);
            await loginPage.loginWithTestUser({
                username: process.env.C8_USERNAME_TEST_10,
                password: process.env.C8_PASSWORD_TEST_10,
            });
            await (0, sleep_1.sleep)(600000); //wait for Optimize cache to refresh
        });
        await _8_10_1.test.step('Navigate to Console and Ensure Apps are Available in App Switcher', async () => {
            await appsPage.clickCamundaApps();
            await appsPage.clickConsoleLink();
            await (0, test_1.expect)(homePage.consoleBanner).toBeVisible({
                timeout: 60000,
            });
            await appsPage.clickCamundaApps();
            await appsPage.assertOptimizePresent();
            await appsPage.assertOperatePresent();
            await appsPage.assertTasklistPresent();
            await (0, test_1.expect)(appsPage.modelerLink).toBeVisible();
            await appsPage.clickCamundaApps();
        });
        await _8_10_1.test.step('Navigate to Operate and Ensure Operate is Accessible', async () => {
            await appsPage.clickCamundaApps();
            await appsPage.clickOperate(clusterName);
            await (0, test_1.expect)(operateHomePage.operateBanner).toBeVisible({
                timeout: 60000,
            });
        });
        await _8_10_1.test.step('Navigate to Tasklist and Ensure Tasklist is Accessible', async () => {
            await page.goBack();
            await appsPage.clickCamundaApps();
            await appsPage.clickTasklist(clusterName);
            await (0, test_1.expect)(taskPanelPage.taskListPageBanner).toBeVisible({
                timeout: 60000,
            });
        });
        await _8_10_1.test.step('Navigate to Identity and Ensure Identity is Accessible', async () => {
            await page.goBack();
            await appsPage.clickCamundaApps();
            await appsPage.clickAdmin(clusterName);
            await (0, test_1.expect)(ocIdentityHomePage.adminBanner).toBeVisible({
                timeout: 60000,
            });
            await (0, test_1.expect)(ocIdentityHomePage.noPermissionsMessage).not.toBeVisible({
                timeout: 60000,
            });
        });
        await _8_10_1.test.step('Navigate to Optimize and Ensure Optimize is Accessible', async () => {
            await page.goBack();
            await appsPage.clickCamundaApps();
            await appsPage.clickOptimize(clusterName);
            await (0, test_1.expect)(optimizeHomePage.optimizeBanner).toBeVisible({
                timeout: 60000,
            });
        });
        await _8_10_1.test.step('Navigate to Modeler and Ensure Diagram Can Be Deployed', async () => {
            await appsPage.clickCamundaApps();
            await appsPage.clickModeler();
            await homePage.clickSkipCustomization();
            await modelerHomePage.createCrossComponentProjectFolder();
            await modelerHomePage.clickDiagramTypeDropdown();
            await modelerHomePage.clickBpmnTemplateOption();
            await (0, test_1.expect)(modelerCreatePage.generalPanel).toBeVisible({
                timeout: 90000,
            });
            await modelerCreatePage.enterDiagramName(processName);
            await (0, sleep_1.sleep)(10000);
            await modelerCreatePage.clickAppendElementButton();
            await modelerCreatePage.clickAppendTaskButton();
            await modelerCreatePage.clickAppendElementButton();
            await modelerCreatePage.clickAppendEndEventButton();
            await (0, sleep_1.sleep)(20000);
            await modelerCreatePage.runProcessInstance(clusterName);
            await (0, test_1.expect)(page.getByText('The diagram failed to deploy & run')).not.toBeVisible({ timeout: 60000 });
            await (0, test_1.expect)(modelerCreatePage.viewProcessInstanceLink).toBeVisible({
                timeout: 120000,
            });
        });
    });
});
