"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ClusterDetailsPage = void 0;
const test_1 = require("@playwright/test");
class ClusterDetailsPage {
    page;
    customPropertiesHeading;
    constructor(page) {
        this.page = page;
        this.customPropertiesHeading = this.page.getByRole('heading', {
            name: 'Custom properties',
        });
    }
    // Test that clicking navigates to correct URL (regardless of site reachability)
    async assertCustomPropertyLink(linkTitle, linkName, expectedHref) {
        const linkElement = this.page
            .getByRole('row', { name: linkTitle })
            .getByRole('link', { name: linkName });
        // Verify link is visible and clickable
        await (0, test_1.expect)(linkElement).toBeVisible({
            timeout: 10000,
        });
        await (0, test_1.expect)(linkElement).toBeEnabled();
        // Intercept the navigation to avoid hitting external sites.
        // When a RegExp is passed (e.g. to match both www and non-www variants),
        // use it directly so both redirect and non-redirect paths are caught.
        const fulfill = (route) => route.fulfill({
            status: 200,
            contentType: 'text/html',
            body: '<html><body>Navigation test passed</body></html>',
        });
        if (expectedHref instanceof RegExp) {
            await this.page.context().route(expectedHref, fulfill);
        }
        else {
            await this.page.context().route(expectedHref, fulfill);
            await this.page.context().route(expectedHref + '/**', fulfill);
        }
        // Ensure the link is in viewport and click it
        await linkElement.scrollIntoViewIfNeeded();
        // Click and verify a new page opens with the correct URL
        const [newPage] = await Promise.all([
            this.page.context().waitForEvent('page'),
            linkElement.click({
                force: true,
                timeout: 10000,
            }),
        ]);
        // Verify the navigation attempt went to the correct URL (handle trailing slashes)
        const actualUrl = newPage.url().replace(/\/$/, '');
        if (expectedHref instanceof RegExp) {
            (0, test_1.expect)(actualUrl).toMatch(expectedHref);
        }
        else {
            (0, test_1.expect)(actualUrl).toBe(expectedHref.replace(/\/$/, ''));
        }
        await newPage.close();
    }
}
exports.ClusterDetailsPage = ClusterDetailsPage;
