"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const test_1 = require("@playwright/test");
const _8_10_1 = require("../../fixtures/8.10");
const _setup_1 = require("../../test-setup.js");
const UtilitiesPage_1 = require("../../pages/8.10/UtilitiesPage");
const LoginPage_1 = require("../../pages/8.10/LoginPage");
const HomePage_1 = require("../../pages/8.10/HomePage");
const ClusterPage_1 = require("../../pages/8.10/ClusterPage");
const ClusterDetailsPage_1 = require("../../pages/8.10/ClusterDetailsPage");
const DataFiltersPage_1 = require("../../pages/8.10/DataFiltersPage");
const users_1 = require("../../utils/users");
const testUser = (0, users_1.getTestUser)('twentyFourthUser');
const readOnlyUser = (0, users_1.getTestUser)('twentyFifthUser');
const clusterName = 'Test Cluster';
let dataFiltersAvailable = false;
const skipIfUnavailable = () => {
    _8_10_1.test.skip(!dataFiltersAvailable, 'Data Filters section is not available on this cluster (feature not yet enabled)');
};
_8_10_1.test.describe.configure({ mode: 'serial' });
_8_10_1.test.describe('Optimize Data Filters UI @tasklistV2', () => {
    _8_10_1.test.slow();
    _8_10_1.test.beforeAll(async ({ browser }) => {
        const context = await browser.newContext();
        const page = await context.newPage();
        try {
            const loginPage = new LoginPage_1.LoginPage(page);
            await (0, UtilitiesPage_1.loginWithRetry)(page, loginPage, testUser, 1000);
            const homePage = new HomePage_1.HomePage(page);
            const clusterPage = new ClusterPage_1.ClusterPage(page);
            const clusterDetailsPage = new ClusterDetailsPage_1.ClusterDetailsPage(page);
            const dataFiltersPage = new DataFiltersPage_1.DataFiltersPage(page);
            await homePage.clickClusters();
            await clusterPage.clickClusterLink(clusterName);
            await clusterDetailsPage.clickSettingsTab();
            dataFiltersAvailable = await dataFiltersPage.dataFiltersHeading
                .isVisible({ timeout: 20000 })
                .catch(() => false);
        }
        catch {
            dataFiltersAvailable = false;
        }
        finally {
            await context.close();
        }
    });
    _8_10_1.test.afterEach(async ({ page }, testInfo) => {
        await (0, _setup_1.captureScreenshot)(page, testInfo);
        await (0, _setup_1.captureFailureVideo)(page, testInfo);
    });
    _8_10_1.test.describe('Authorized operator', () => {
        _8_10_1.test.beforeEach(async ({ page, loginPage }, testInfo) => {
            skipIfUnavailable();
            await (0, UtilitiesPage_1.loginWithRetry)(page, loginPage, testUser, (testInfo.workerIndex + 1) * 1000);
        });
        (0, _8_10_1.test)('T11728018 view the Data Filters section', async ({ homePage, clusterPage, clusterDetailsPage, dataFiltersPage, }) => {
            await _8_10_1.test.step('Open cluster settings and assert Data Filters section', async () => {
                await homePage.clickClusters();
                await clusterPage.clickClusterLink(clusterName);
                await clusterDetailsPage.clickSettingsTab();
                await dataFiltersPage.assertDataFiltersSectionVisible();
            });
        });
        (0, _8_10_1.test)('T11728020 enable and set a variable filter pattern', async ({ page, homePage, clusterPage, clusterDetailsPage, dataFiltersPage, }) => {
            const pattern = 'business_*';
            await _8_10_1.test.step('Open Data Filters section', async () => {
                await homePage.clickClusters();
                await clusterPage.clickClusterLink(clusterName);
                await clusterDetailsPage.clickSettingsTab();
                await dataFiltersPage.assertDataFiltersSectionVisible();
            });
            await _8_10_1.test.step('Enable the variable filter and add a pattern', async () => {
                await dataFiltersPage.enableVariableFilter();
                await dataFiltersPage.addIncludeVariableName(pattern);
                await dataFiltersPage.assertChipVisible(pattern);
            });
            await _8_10_1.test.step('Save and verify persistence', async () => {
                await dataFiltersPage.save();
                await page.reload({ waitUntil: 'domcontentloaded' });
                await clusterDetailsPage.clickSettingsTab();
                await dataFiltersPage.assertChipVisible(pattern);
            });
        });
        (0, _8_10_1.test)('T11728021 modify an existing variable filter pattern', async ({ homePage, clusterPage, clusterDetailsPage, dataFiltersPage, }) => {
            await _8_10_1.test.step('Open Data Filters section', async () => {
                await homePage.clickClusters();
                await clusterPage.clickClusterLink(clusterName);
                await clusterDetailsPage.clickSettingsTab();
                await dataFiltersPage.assertDataFiltersSectionVisible();
            });
            await _8_10_1.test.step('Add an updated pattern and save', async () => {
                await dataFiltersPage.enableVariableFilter();
                await dataFiltersPage.addIncludeVariableName('business_updated_*');
                await dataFiltersPage.assertChipVisible('business_updated_*');
                await dataFiltersPage.save();
            });
        });
        (0, _8_10_1.test)('T11728022 disable the variable filter', async ({ homePage, clusterPage, clusterDetailsPage, dataFiltersPage, }) => {
            await _8_10_1.test.step('Open Data Filters section', async () => {
                await homePage.clickClusters();
                await clusterPage.clickClusterLink(clusterName);
                await clusterDetailsPage.clickSettingsTab();
                await dataFiltersPage.assertDataFiltersSectionVisible();
            });
            await _8_10_1.test.step('Disable the variable filter and save', async () => {
                await dataFiltersPage.disableVariableFilter();
                await dataFiltersPage.save();
            });
        });
        (0, _8_10_1.test)('T11728023 cannot save an empty variable filter pattern', async ({ homePage, clusterPage, clusterDetailsPage, dataFiltersPage, }) => {
            await _8_10_1.test.step('Open Data Filters section', async () => {
                await homePage.clickClusters();
                await clusterPage.clickClusterLink(clusterName);
                await clusterDetailsPage.clickSettingsTab();
                await dataFiltersPage.assertDataFiltersSectionVisible();
            });
            await _8_10_1.test.step('Attempt to add an empty pattern', async () => {
                await dataFiltersPage.enableVariableFilter();
                await dataFiltersPage.addIncludeVariableName('');
                await dataFiltersPage.assertValidationError();
            });
        });
        (0, _8_10_1.test)('T11728024 cannot save a variable filter pattern with invalid characters', async ({ homePage, clusterPage, clusterDetailsPage, dataFiltersPage, }) => {
            await _8_10_1.test.step('Open Data Filters section', async () => {
                await homePage.clickClusters();
                await clusterPage.clickClusterLink(clusterName);
                await clusterDetailsPage.clickSettingsTab();
                await dataFiltersPage.assertDataFiltersSectionVisible();
            });
            await _8_10_1.test.step('Attempt to add a pattern with invalid characters', async () => {
                await dataFiltersPage.enableVariableFilter();
                await dataFiltersPage.addIncludeVariableName('bad name!@#');
                await dataFiltersPage.assertValidationError();
            });
        });
        (0, _8_10_1.test)('T11728025 cannot save a variable filter pattern exceeding max length', async ({ homePage, clusterPage, clusterDetailsPage, dataFiltersPage, }) => {
            await _8_10_1.test.step('Open Data Filters section', async () => {
                await homePage.clickClusters();
                await clusterPage.clickClusterLink(clusterName);
                await clusterDetailsPage.clickSettingsTab();
                await dataFiltersPage.assertDataFiltersSectionVisible();
            });
            await _8_10_1.test.step('Attempt to add an over-length pattern', async () => {
                await dataFiltersPage.enableVariableFilter();
                await dataFiltersPage.addIncludeVariableName('a'.repeat(300));
                await dataFiltersPage.assertValidationError();
            });
        });
        (0, _8_10_1.test)('T11728026 exclude a process definition from Optimize import', async ({ homePage, clusterPage, clusterDetailsPage, dataFiltersPage, }) => {
            await _8_10_1.test.step('Open Data Filters section', async () => {
                await homePage.clickClusters();
                await clusterPage.clickClusterLink(clusterName);
                await clusterDetailsPage.clickSettingsTab();
                await dataFiltersPage.assertDataFiltersSectionVisible();
            });
            await _8_10_1.test.step('Add a process definition to the exclusion list', async () => {
                await dataFiltersPage.addExcludeProcessDefinition('dev_test_process');
                await dataFiltersPage.assertChipVisible('dev_test_process');
                await dataFiltersPage.save();
            });
        });
        (0, _8_10_1.test)('T11728027 remove a process definition from the exclusion list', async ({ page, homePage, clusterPage, clusterDetailsPage, dataFiltersPage, }) => {
            await _8_10_1.test.step('Open Data Filters section', async () => {
                await homePage.clickClusters();
                await clusterPage.clickClusterLink(clusterName);
                await clusterDetailsPage.clickSettingsTab();
                await dataFiltersPage.assertDataFiltersSectionVisible();
            });
            await _8_10_1.test.step('Add then remove a process definition exclusion', async () => {
                await dataFiltersPage.addExcludeProcessDefinition('removable_process');
                await dataFiltersPage.assertChipVisible('removable_process');
                await dataFiltersPage.removeChip('removable_process');
                await (0, test_1.expect)(page.getByText('removable_process', { exact: false })).toHaveCount(0);
            });
        });
        (0, _8_10_1.test)('T11728028 view the current process definition filter list', async ({ homePage, clusterPage, clusterDetailsPage, dataFiltersPage, }) => {
            await _8_10_1.test.step('Open Data Filters section and assert process definition fields render', async () => {
                await homePage.clickClusters();
                await clusterPage.clickClusterLink(clusterName);
                await clusterDetailsPage.clickSettingsTab();
                await dataFiltersPage.assertDataFiltersSectionVisible();
                await (0, test_1.expect)(dataFiltersPage.includeProcessDefinitionsInput.or(dataFiltersPage.excludeProcessDefinitionsInput)).toBeVisible({ timeout: 30000 });
            });
        });
        (0, _8_10_1.test)('T11728035 informed of rolling restart on save', async ({ homePage, clusterPage, clusterDetailsPage, dataFiltersPage, }) => {
            await _8_10_1.test.step('Open Data Filters section', async () => {
                await homePage.clickClusters();
                await clusterPage.clickClusterLink(clusterName);
                await clusterDetailsPage.clickSettingsTab();
                await dataFiltersPage.assertDataFiltersSectionVisible();
            });
            await _8_10_1.test.step('Change a filter and assert rolling restart notice', async () => {
                await dataFiltersPage.enableVariableFilter();
                await dataFiltersPage.addIncludeVariableName('restart_notice_*');
                await dataFiltersPage.saveButton.click({ timeout: 30000 });
                await dataFiltersPage.assertRollingRestartNotice();
            });
        });
        (0, _8_10_1.test)('T11735082 add a value to the Exclude variable names field', async ({ homePage, clusterPage, clusterDetailsPage, dataFiltersPage, }) => {
            await _8_10_1.test.step('Open Data Filters section', async () => {
                await homePage.clickClusters();
                await clusterPage.clickClusterLink(clusterName);
                await clusterDetailsPage.clickSettingsTab();
                await dataFiltersPage.assertDataFiltersSectionVisible();
            });
            await _8_10_1.test.step('Add a single exclude variable name', async () => {
                await dataFiltersPage.addExcludeVariableName('secret_var');
                await dataFiltersPage.assertChipVisible('secret_var');
            });
        });
        (0, _8_10_1.test)('T11735083 add multiple values to the Exclude variable names field', async ({ homePage, clusterPage, clusterDetailsPage, dataFiltersPage, }) => {
            await _8_10_1.test.step('Open Data Filters section', async () => {
                await homePage.clickClusters();
                await clusterPage.clickClusterLink(clusterName);
                await clusterDetailsPage.clickSettingsTab();
                await dataFiltersPage.assertDataFiltersSectionVisible();
            });
            await _8_10_1.test.step('Add multiple exclude variable names', async () => {
                await dataFiltersPage.addExcludeVariableName('secret_a');
                await dataFiltersPage.addExcludeVariableName('secret_b');
                await dataFiltersPage.assertChipVisible('secret_a');
                await dataFiltersPage.assertChipVisible('secret_b');
            });
        });
        (0, _8_10_1.test)('T11735084 add multiple values to the Include variable names field', async ({ homePage, clusterPage, clusterDetailsPage, dataFiltersPage, }) => {
            await _8_10_1.test.step('Open Data Filters section', async () => {
                await homePage.clickClusters();
                await clusterPage.clickClusterLink(clusterName);
                await clusterDetailsPage.clickSettingsTab();
                await dataFiltersPage.assertDataFiltersSectionVisible();
            });
            await _8_10_1.test.step('Add multiple include variable names', async () => {
                await dataFiltersPage.enableVariableFilter();
                await dataFiltersPage.addIncludeVariableName('business_a');
                await dataFiltersPage.addIncludeVariableName('business_b');
                await dataFiltersPage.assertChipVisible('business_a');
                await dataFiltersPage.assertChipVisible('business_b');
            });
        });
        (0, _8_10_1.test)('T11735085 add a value to the Include process definitions field', async ({ homePage, clusterPage, clusterDetailsPage, dataFiltersPage, }) => {
            await _8_10_1.test.step('Open Data Filters section', async () => {
                await homePage.clickClusters();
                await clusterPage.clickClusterLink(clusterName);
                await clusterDetailsPage.clickSettingsTab();
                await dataFiltersPage.assertDataFiltersSectionVisible();
            });
            await _8_10_1.test.step('Add a single include process definition', async () => {
                await dataFiltersPage.addIncludeProcessDefinition('prod_process');
                await dataFiltersPage.assertChipVisible('prod_process');
            });
        });
        (0, _8_10_1.test)('T11735086 add multiple values to the Include process definitions field', async ({ homePage, clusterPage, clusterDetailsPage, dataFiltersPage, }) => {
            await _8_10_1.test.step('Open Data Filters section', async () => {
                await homePage.clickClusters();
                await clusterPage.clickClusterLink(clusterName);
                await clusterDetailsPage.clickSettingsTab();
                await dataFiltersPage.assertDataFiltersSectionVisible();
            });
            await _8_10_1.test.step('Add multiple include process definitions', async () => {
                await dataFiltersPage.addIncludeProcessDefinition('prod_a');
                await dataFiltersPage.addIncludeProcessDefinition('prod_b');
                await dataFiltersPage.assertChipVisible('prod_a');
                await dataFiltersPage.assertChipVisible('prod_b');
            });
        });
        (0, _8_10_1.test)('T11735088 set both Include and Exclude process definitions simultaneously', async ({ homePage, clusterPage, clusterDetailsPage, dataFiltersPage, }) => {
            await _8_10_1.test.step('Open Data Filters section', async () => {
                await homePage.clickClusters();
                await clusterPage.clickClusterLink(clusterName);
                await clusterDetailsPage.clickSettingsTab();
                await dataFiltersPage.assertDataFiltersSectionVisible();
            });
            await _8_10_1.test.step('Set include and exclude process definitions', async () => {
                await dataFiltersPage.addIncludeProcessDefinition('include_proc');
                await dataFiltersPage.addExcludeProcessDefinition('exclude_proc');
                await dataFiltersPage.assertChipVisible('include_proc');
                await dataFiltersPage.assertChipVisible('exclude_proc');
                await dataFiltersPage.save();
            });
        });
    });
    _8_10_1.test.describe('Read-only operator', () => {
        _8_10_1.test.beforeEach(async ({ page, loginPage }, testInfo) => {
            skipIfUnavailable();
            await (0, UtilitiesPage_1.loginWithRetry)(page, loginPage, readOnlyUser, (testInfo.workerIndex + 1) * 1000);
        });
        (0, _8_10_1.test)('T11728019 read-only user cannot modify Data Filters', async ({ homePage, clusterPage, clusterDetailsPage, dataFiltersPage, }) => {
            await _8_10_1.test.step('Open Data Filters section as read-only user', async () => {
                await homePage.clickClusters();
                await clusterPage.clickClusterLink(clusterName);
                await clusterDetailsPage.clickSettingsTab();
                await dataFiltersPage.assertDataFiltersSectionVisible();
            });
            await _8_10_1.test.step('Assert modification controls are not actionable', async () => {
                await dataFiltersPage.assertControlsDisabled();
            });
        });
    });
});
