"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.registerAssertionSteps = registerAssertionSteps;
function requirePage(ctx, op) {
    if (!ctx.ui || !ctx.ui.page) {
        throw new Error(`Missing UI page on context for op "${op}"`);
    }
    return ctx.ui.page;
}
function registerAssertionSteps(registry) {
    registry.register("ui.expectVisible", async (ctx, step) => {
        const page = requirePage(ctx, "ui.expectVisible");
        const input = (step.with ?? {});
        if (!input.selector) {
            throw new Error('Missing "selector" in step.with for op "ui.expectVisible"');
        }
        await page.waitForSelector(input.selector, { state: "visible" });
    });
    registry.register("ui.expectHidden", async (ctx, step) => {
        const page = requirePage(ctx, "ui.expectHidden");
        const input = (step.with ?? {});
        if (!input.selector) {
            throw new Error('Missing "selector" in step.with for op "ui.expectHidden"');
        }
        await page.waitForSelector(input.selector, { state: "hidden" });
    });
    registry.register("ui.expectText", async (ctx, step) => {
        const page = requirePage(ctx, "ui.expectText");
        const input = (step.with ?? {});
        if (!input.selector) {
            throw new Error('Missing "selector" in step.with for op "ui.expectText"');
        }
        const text = await page.locator(input.selector).innerText();
        if (input.equals !== undefined) {
            if (text !== input.equals) {
                throw new Error(`Expected text to equal "${input.equals}" but got "${text}"`);
            }
            return;
        }
        if (input.contains !== undefined) {
            if (!text.includes(input.contains)) {
                throw new Error(`Expected text to contain "${input.contains}" but got "${text}"`);
            }
            return;
        }
        throw new Error('Missing "equals" or "contains" in step.with for op "ui.expectText"');
    });
}
//# sourceMappingURL=assertions.step.js.map