"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const test_1 = require("@playwright/test");
const _8_8_1 = require("../../fixtures/8.8");
const _setup_1 = require("../../test-setup.js");
const UtilitiesPage_1 = require("../../pages/8.8/UtilitiesPage");
const sleep_1 = require("../../utils/sleep");
const LoginPage_1 = require("../../pages/8.8/LoginPage");
const expectTextWithRetry_1 = require("../../utils/assertionHelpers/expectTextWithRetry");
const users_1 = require("../../utils/users");
const expectLocatorWithRetry_1 = require("../../utils/assertionHelpers/expectLocatorWithRetry");
const mainUser = (0, users_1.getTestUser)('twelfthUser');
_8_8_1.test.describe.parallel('UTR Enabled User Flows Test @tasklistV1', () => {
    const clusterName = 'Test Cluster';
    _8_8_1.test.beforeEach(async ({ page, loginPage }, testInfo) => {
        await (0, UtilitiesPage_1.loginWithRetry)(page, loginPage, mainUser, (testInfo.workerIndex + 1) * 1000);
    });
    _8_8_1.test.afterEach(async ({ page }, testInfo) => {
        await (0, _setup_1.captureScreenshot)(page, testInfo);
        await (0, _setup_1.captureFailureVideo)(page, testInfo);
    });
    (0, _8_8_1.test)('User Task Restrictions Enabled Flow - Candidate User', async ({ page, modelerHomePage, appsPage, modelerCreatePage, taskPanelPage, }) => {
        _8_8_1.test.slow();
        const randomName = await (0, _setup_1.generateRandomStringAsync)(3);
        const processName = 'User_Task_Process_Candidate_User' + randomName;
        const taskName1 = 'candidateUserTask' + randomName + '1';
        const taskName2 = 'candidateUserTask' + randomName + '2';
        const taskName3 = 'candidateUserTask' + randomName + '3';
        const testUser = {
            username: process.env.C8_USERNAME_TEST_2,
            password: process.env.C8_PASSWORD_TEST_2,
        };
        await _8_8_1.test.step('Navigate to Web Modeler', async () => {
            await appsPage.clickCamundaApps();
            await appsPage.clickModeler();
            await (0, test_1.expect)(modelerHomePage.modelerPageBanner).toBeVisible({
                timeout: 60000,
            });
        });
        await _8_8_1.test.step('Navigate to Cross Component Test Project', async () => {
            await modelerHomePage.clickCrossComponentProjectFolder();
        });
        await _8_8_1.test.step('Create BPMN Diagram with Multiple User Tasks', async () => {
            await (0, UtilitiesPage_1.modelDiagramFromFile)(page, modelerHomePage, modelerCreatePage, processName, 'Candidate_User_Process_Three_Tasks', 3, 'candidateUserTask' + randomName);
        });
        await _8_8_1.test.step('Assign First Task to Test User as Candidate and Admin as Assignee', async () => {
            await modelerCreatePage.assignToCandidateUser(taskName1, testUser.username, mainUser.username);
        });
        await _8_8_1.test.step('Assign Second Task to Admin as Candidate', async () => {
            await modelerCreatePage.assignToCandidateUser(taskName2, mainUser.username);
        });
        await _8_8_1.test.step('Assign Third Task to Test User as Candidate', async () => {
            await modelerCreatePage.assignToCandidateUser(taskName3, testUser.username);
        });
        await _8_8_1.test.step('Start Process Instance', async () => {
            await (0, sleep_1.sleep)(10000);
            await modelerCreatePage.runProcessInstance(clusterName);
        });
        await _8_8_1.test.step('View User Tasks in Tasklist', async () => {
            await appsPage.clickCamundaApps();
            await appsPage.clickTasklist(clusterName);
            await (0, test_1.expect)(taskPanelPage.taskListPageBanner).toBeVisible({
                timeout: 60000,
            });
            await (0, expectTextWithRetry_1.expectTextWithRetry)(page, taskName1);
            await (0, expectLocatorWithRetry_1.expectLocatorWithRetry)(page, page.getByText(taskName2).first().or(page.getByText(taskName2).last()), {
                totalTimeout: 120000,
                maxRetries: 5,
                postAction: async () => {
                    await page.reload();
                },
            });
            await (0, expectTextWithRetry_1.expectTextWithRetry)(page, taskName3, { shouldBeVisible: false });
        });
        await _8_8_1.test.step('Clear cookies and reset session', async () => {
            await page.context().clearCookies();
            await page.evaluate(() => {
                localStorage.clear();
                sessionStorage.clear();
            });
            await page.goto('/');
        });
        await _8_8_1.test.step('Login with Test User and Check Tasks in Tasklist ', async () => {
            const loginPage = new LoginPage_1.LoginPage(page);
            await loginPage.loginWithTestUser(testUser);
            await appsPage.clickCamundaApps();
            await appsPage.clickTasklist(clusterName);
            await (0, test_1.expect)(taskPanelPage.taskListPageBanner).toBeVisible({
                timeout: 60000,
            });
            await (0, expectTextWithRetry_1.expectTextWithRetry)(page, taskName1, {
                totalTimeout: 120000,
                maxRetries: 5,
            });
            await (0, expectTextWithRetry_1.expectTextWithRetry)(page, taskName2, {
                shouldBeVisible: false,
                totalTimeout: 120000,
                maxRetries: 5,
            });
            await (0, expectTextWithRetry_1.expectTextWithRetry)(page, taskName3, {
                totalTimeout: 180000,
                maxRetries: 7,
            });
        });
    });
    (0, _8_8_1.test)('User Task Restrictions Enabled Flow - Candidate Group', async ({ page, modelerHomePage, appsPage, modelerCreatePage, taskPanelPage, ocIdentityGroupsPage, ocIdentityHomePage, }) => {
        _8_8_1.test.slow();
        const randomName = await (0, _setup_1.generateRandomStringAsync)(3);
        const processName = 'User_Task_Process_Candidate_Group' + randomName;
        const groupNameSingle = await (0, _setup_1.generateRandomStringAsync)(4);
        const groupNameMultiple = await (0, _setup_1.generateRandomStringAsync)(4);
        const taskName1 = 'candidateGroupTask' + randomName + '1';
        const taskName2 = 'candidateGroupTask' + randomName + '2';
        const testUser1 = {
            username: process.env.C8_USERNAME_TEST,
            password: process.env.C8_PASSWORD_TEST,
        };
        const testUser2 = {
            username: process.env.C8_USERNAME_TEST_2,
            password: process.env.C8_PASSWORD_TEST_2,
        };
        await _8_8_1.test.step('Navigate to Identity', async () => {
            await appsPage.clickCamundaApps();
            await appsPage.clickIdentity(clusterName);
        });
        await _8_8_1.test.step('Create Two User Groups in Identity', async () => {
            await ocIdentityHomePage.clickGroupsTab();
            await ocIdentityGroupsPage.createGroup(groupNameSingle, groupNameSingle);
            await ocIdentityGroupsPage.createGroup(groupNameMultiple, groupNameMultiple);
        });
        await _8_8_1.test.step('Assign Users to the Created Groups in Identity', async () => {
            await ocIdentityHomePage.clickGroupsTab();
            await ocIdentityGroupsPage.clickGroupId(groupNameSingle);
            await ocIdentityGroupsPage.assignUserToGroup(mainUser.username);
            await ocIdentityHomePage.clickGroupsTab();
            await ocIdentityGroupsPage.clickGroupId(groupNameMultiple);
            await ocIdentityGroupsPage.assignUserToGroup(testUser1.username);
            await ocIdentityHomePage.clickGroupsTab();
            await ocIdentityGroupsPage.clickGroupId(groupNameMultiple);
            await ocIdentityGroupsPage.assignUserToGroup(testUser2.username);
        });
        await _8_8_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_8_1.test.step('Navigate to Cross Component Test Project', async () => {
            await modelerHomePage.clickCrossComponentProjectFolder();
        });
        await _8_8_1.test.step('Create BPMN Diagram with Multiple User Tasks', async () => {
            await (0, UtilitiesPage_1.modelDiagramFromFile)(page, modelerHomePage, modelerCreatePage, processName, 'Candidate_User_Process_Two_Tasks', 2, 'candidateGroupTask' + randomName);
        });
        await _8_8_1.test.step('Assign First Task to Single Group as Candidate and Test User 1 as Assignee', async () => {
            await modelerCreatePage.assignToCandidateGroup(taskName1, groupNameSingle, testUser1.username);
        });
        await _8_8_1.test.step('Assign Second Task to Multiple Group as Candidate', async () => {
            await modelerCreatePage.assignToCandidateGroup(taskName2, groupNameMultiple);
        });
        await _8_8_1.test.step('Start Process Instance', async () => {
            await (0, sleep_1.sleep)(10000);
            await modelerCreatePage.runProcessInstance(clusterName);
        });
        await _8_8_1.test.step('View User Tasks in Tasklist', async () => {
            await appsPage.clickCamundaApps();
            await appsPage.clickTasklist(clusterName);
            await (0, expectLocatorWithRetry_1.expectLocatorWithRetry)(page, taskPanelPage.taskListPageBanner, {
                visibilityTimeout: 20000,
                postAction: async () => {
                    await page.reload();
                },
            });
            await (0, expectTextWithRetry_1.expectTextWithRetry)(page, taskName1);
            await (0, expectTextWithRetry_1.expectTextWithRetry)(page, taskName2, { shouldBeVisible: false });
        });
        await _8_8_1.test.step('Clear cookies and reset session', async () => {
            await page.context().clearCookies();
            await page.evaluate(() => {
                localStorage.clear();
                sessionStorage.clear();
            });
            await page.goto('/');
        });
        await _8_8_1.test.step('Login with Test User and Check Tasks in Tasklist ', async () => {
            const loginPage = new LoginPage_1.LoginPage(page);
            await loginPage.loginWithTestUser(testUser1);
            await appsPage.clickCamundaApps();
            await appsPage.clickTasklist(clusterName);
            await (0, test_1.expect)(taskPanelPage.taskListPageBanner).toBeVisible({
                timeout: 120000,
            });
            await (0, expectTextWithRetry_1.expectTextWithRetry)(page, taskName1);
            await (0, expectLocatorWithRetry_1.expectLocatorWithRetry)(page, page.getByText(taskName2).first().or(page.getByText(taskName2).last()), {
                totalTimeout: 180000,
                maxRetries: 8,
                postAction: async () => {
                    await page.reload();
                },
            });
        });
        await _8_8_1.test.step('Clear cookies and reset session', async () => {
            await page.context().clearCookies();
            await page.evaluate(() => {
                localStorage.clear();
                sessionStorage.clear();
            });
            await page.goto('/');
        });
        await _8_8_1.test.step('Login with Second Test User and Check Tasks in Tasklist ', async () => {
            const loginPage = new LoginPage_1.LoginPage(page);
            await loginPage.loginWithTestUser(testUser2);
            await appsPage.clickCamundaApps();
            await appsPage.clickTasklist(clusterName);
            await (0, test_1.expect)(taskPanelPage.taskListPageBanner).toBeVisible({
                timeout: 120000,
            });
            await (0, expectTextWithRetry_1.expectTextWithRetry)(page, taskName1, { shouldBeVisible: false });
            await (0, expectLocatorWithRetry_1.expectLocatorWithRetry)(page, page.getByText(taskName2).first().or(page.getByText(taskName2).last()), {
                totalTimeout: 120000,
                maxRetries: 5,
                postAction: async () => {
                    await page.reload();
                },
            });
        });
    });
});
