"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 sleep_1 = require("../../utils/sleep");
const UtlitiesPage_1 = require("../../pages/SM-8.6/UtlitiesPage");
const env_1 = require("../../utils/env");
SM_8_6_1.test.describe('SM Setup Tests', () => {
    SM_8_6_1.test.beforeEach(async ({ navigationPage }) => {
        await navigationPage.goToModeler();
    });
    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)('Create Project Folder', async ({ page, modelerHomePage }) => {
        if (process.env.IS_SMOKE === 'true') {
            SM_8_6_1.test.skip(true, 'Skipping test because test not required in this test environment');
        }
        await SM_8_6_1.test.step('Create Cross Component Project Folder', async () => {
            await modelerHomePage.createCrossComponentProjectFolder();
            await modelerHomePage.clickHomeBreadcrumb();
            await (0, UtlitiesPage_1.assertLocatorVisibleWithRetry)(page, modelerHomePage.crossComponentProjectFolder, 'Cross component project folder', 30000);
        });
    });
    (0, SM_8_6_1.test)('User Roles User Flow', async ({ page, navigationPage, taskPanelPage, operateHomePage, optimizeHomePage, identityPage, modelerHomePage, consoleHomePage, }) => {
        if (process.env.IS_RBA === 'true' ||
            process.env.IS_MT === 'true' ||
            process.env.IS_LICENSE_KEY === 'true' ||
            process.env.IS_SMOKE === 'true') {
            SM_8_6_1.test.skip(true, 'Skipping test because test not required in this test environment');
        }
        SM_8_6_1.test.slow();
        await SM_8_6_1.test.step('Navigate to Identity', async () => {
            await navigationPage.goToIdentity();
        });
        await SM_8_6_1.test.step('Remove Access from Operate,Optimize, Tasklist, Web Modeler and Console from Main User', async () => {
            await identityPage.clickUsersLink();
            await identityPage.clickDemoUser();
            await identityPage.clickAssignedRolesTab();
            await identityPage.clickDeleteAccessButton('Grants full access to Operate');
            await identityPage.clickConfirmDeleteButton();
            if (!env_1.isOpenSearch) {
                await identityPage.clickDeleteAccessButton('Grants full access to Optimize');
                await identityPage.clickConfirmDeleteButton();
            }
            await identityPage.clickDeleteAccessButton('Grants full access to Tasklist');
            await identityPage.clickConfirmDeleteButton();
            await identityPage.clickDeleteAccessButton('Grants full access to Web Modeler');
            await identityPage.clickConfirmDeleteButton();
            await identityPage.clickDeleteAccessButton('Grants elevated access to Web Modeler');
            await identityPage.clickConfirmDeleteButton();
            await identityPage.clickDeleteAccessButton('Grants full access to Console');
            await identityPage.clickConfirmDeleteButton();
            await (0, sleep_1.sleep)(50000);
        });
        await SM_8_6_1.test.step('Ensure Apps are not Accessible', async () => {
            if (!env_1.isOpenSearch) {
                //No permission for Optimize
                await page.goto('/optimize');
                await (0, test_1.expect)(page.getByText('User has no authorization to access Optimize. Please check your Identity configuration')).toBeVisible({ timeout: 120000 });
                await (0, test_1.expect)(optimizeHomePage.optimizeBanner).not.toBeVisible({
                    timeout: 60000,
                });
            }
            //No permission for Tasklist
            await page.goto('/tasklist');
            await (0, test_1.expect)(page.getByText('No permission for Tasklist - Please check your configuration.')).toBeVisible({
                timeout: 120000,
            });
            await (0, test_1.expect)(taskPanelPage.tasklistBanner).not.toBeVisible({
                timeout: 60000,
            });
            //No permission for Operate
            await page.goto('/operate');
            await (0, test_1.expect)(page.getByText('Something went wrong')).toBeVisible({
                timeout: 120000,
            });
            await (0, test_1.expect)(operateHomePage.operateBanner).not.toBeVisible({
                timeout: 60000,
            });
            //No permission for Console
            await page.goto('/');
            await (0, test_1.expect)(page.getByText('Something went wrong')).toBeVisible({
                timeout: 60000,
            });
            await (0, test_1.expect)(consoleHomePage.consoleBanner).not.toBeVisible({
                timeout: 60000,
            });
            //No permission for Modeler
            await page.goto('/modeler');
            await (0, test_1.expect)(modelerHomePage.modelerPageBanner).not.toBeVisible({
                timeout: 60000,
            });
        });
        await SM_8_6_1.test.step('Grant Apps Permission to Main User', async () => {
            await navigationPage.goToIdentity();
            await identityPage.clickUsersLink();
            await identityPage.clickDemoUser();
            await identityPage.clickAssignedRolesTab();
            await identityPage.clickAssignRolesButton();
            await identityPage.clickOperateCheckbox();
            await identityPage.clickTasklistCheckbox();
            if (!env_1.isOpenSearch) {
                await identityPage.clickOptimizeCheckbox();
            }
            await identityPage.clickModelerCheckbox();
            await identityPage.clickConsoleCheckbox();
            await identityPage.clickAddButton();
            await (0, sleep_1.sleep)(60000);
        });
        await SM_8_6_1.test.step('Ensure Apps are Accessible', async () => {
            await navigationPage.goToOperate();
            await (0, test_1.expect)(operateHomePage.operateBanner).toBeVisible({
                timeout: 180000,
            });
            await navigationPage.goToTasklist();
            await (0, test_1.expect)(taskPanelPage.tasklistBanner).toBeVisible({ timeout: 180000 });
            await navigationPage.goToOptimize();
            await (0, test_1.expect)(optimizeHomePage.optimizeBanner).toBeVisible({
                timeout: 180000,
            });
            await navigationPage.goToModeler();
            await (0, test_1.expect)(modelerHomePage.modelerPageBanner).toBeVisible({
                timeout: 180000,
            });
            await navigationPage.goToConsole();
            await (0, test_1.expect)(consoleHomePage.consoleBanner).toBeVisible({
                timeout: 180000,
            });
        });
    });
});
