"use strict";
// Copyright 2021 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 });
exports.waitForSoftContextMenu = waitForSoftContextMenu;
exports.findSubMenuEntryItem = findSubMenuEntryItem;
exports.openSoftContextMenuAndClickOnItem = openSoftContextMenuAndClickOnItem;
exports.openSubMenu = openSubMenu;
const chai_1 = require("chai");
async function waitForSoftContextMenu(devToolsPage) {
    return await devToolsPage.waitFor('.soft-context-menu');
}
async function findSubMenuEntryItem(text, devToolsPage) {
    const matchingElement = await devToolsPage.$textContent(text);
    if (!matchingElement) {
        const allItems = await devToolsPage.$$('.soft-context-menu > .soft-context-menu-item');
        const allItemsText = await Promise.all(allItems.map(item => item.evaluate(div => div.textContent)));
        chai_1.assert.fail(`Could not find "${text}" option on context menu. Found items: ${allItemsText.join(' | ')}`);
    }
    return matchingElement;
}
async function openSoftContextMenuAndClickOnItem(selector, label, devToolsPage) {
    // Find the selected node, right click.
    await devToolsPage.click(selector, { clickOptions: { button: 'right' } });
    // Wait for the context menu option, and click it.
    const root = await waitForSoftContextMenu(devToolsPage);
    await devToolsPage.click(`[aria-label="${label}"]`, { root });
}
async function openSubMenu(selector, text, devToolsPage) {
    // Find the selected node, right click.
    await devToolsPage.click(selector, { clickOptions: { button: 'right' } });
    // Wait for the context menu option, and click it.
    await waitForSoftContextMenu(devToolsPage);
    const subMenuEntryItem = await findSubMenuEntryItem(text, devToolsPage);
    await subMenuEntryItem.hover();
}
//# sourceMappingURL=context-menu-helpers.js.map