"use strict";
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
Object.defineProperty(exports, "__esModule", { value: true });
const chai_1 = require("chai");
const console_helpers_js_1 = require("../helpers/console-helpers.js");
describe('Console search', () => {
    it('finds and highlights matches including a "current match"', async ({ devToolsPage, inspectedPage }) => {
        await Promise.all([
            inspectedPage.goToResource('console/search.html'),
            (0, console_helpers_js_1.navigateToConsoleTab)(devToolsPage),
        ]);
        await openSearchBar(devToolsPage);
        await devToolsPage.typeText('Message');
        await devToolsPage.waitForElementWithTextContent('1 of 200', await devToolsPage.waitFor('.search-results-matches'));
        await waitForHighlightedCurrentSearchResult(devToolsPage, 'Message');
        // Since we have 200 console messages not all of them are rendered, so we make sure that at least a reasonable amount
        // of highlighted search results are rendered.
        chai_1.assert.isAbove((await devToolsPage.$$('.highlighted-search-result')).length, 50);
    });
    it('can jump forwards and backwards', async ({ devToolsPage, inspectedPage }) => {
        await Promise.all([
            inspectedPage.goToResource('console/search.html'),
            (0, console_helpers_js_1.navigateToConsoleTab)(devToolsPage),
        ]);
        await openSearchBar(devToolsPage);
        await devToolsPage.typeText('MATCH');
        await waitForHighlightedCurrentSearchResult(devToolsPage, 'MATCH');
        chai_1.assert.strictEqual(await devToolsPage.getTextContent('.console-message-text:has(.current-search-result)'), 'FIRST MATCH, SECOND MATCH');
        await devToolsPage.click('aria/Show next result');
        await devToolsPage.click('aria/Show next result');
        chai_1.assert.strictEqual(await devToolsPage.getTextContent('.console-message-text:has(.current-search-result)'), 'LAST MATCH');
        await devToolsPage.click('aria/Show previous result');
        chai_1.assert.strictEqual(await devToolsPage.getTextContent('.console-message-text:has(.current-search-result)'), 'FIRST MATCH, SECOND MATCH');
    });
    it('can jump forward in remote object property matches', async ({ devToolsPage, inspectedPage }) => {
        await Promise.all([
            inspectedPage.goToResource('console/search.html'),
            (0, console_helpers_js_1.navigateToConsoleTab)(devToolsPage),
        ]);
        await openSearchBar(devToolsPage);
        await devToolsPage.typeText('field_');
        await waitForHighlightedCurrentSearchResult(devToolsPage, 'field_');
        chai_1.assert.strictEqual(await devToolsPage.getTextContent('.console-message-text:has(.current-search-result)'), '{field_0: \'value #0\', field_1: \'value #1\'}');
    });
});
async function openSearchBar(devToolsPage) {
    await devToolsPage.pressKey('f', { control: true });
    await devToolsPage.waitFor('.search-bar:not(.hidden)');
}
async function waitForHighlightedCurrentSearchResult(devToolsPage, matchingText) {
    await devToolsPage.waitForFunction(async () => {
        const actualText = await devToolsPage.getTextContent('.current-search-result');
        return actualText === matchingText;
    });
}
//# sourceMappingURL=search.test.js.map