// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import { assert } from 'chai';
import sinon from 'sinon';
import * as SDK from '../../core/sdk/sdk.js';
import { renderElementIntoDOM } from '../../testing/DOMHelpers.js';
import { createTarget, stubNoopSettings } from '../../testing/EnvironmentHelpers.js';
import { describeWithMockConnection } from '../../testing/MockConnection.js';
import * as TreeOutline from '../../ui/components/tree_outline/tree_outline.js';
import * as Elements from './elements.js';
const MAIN_FRAME_ID = 'MAIN_FRAME_ID';
describeWithMockConnection('AccessibilityTreeView', () => {
    let target;
    let treeComponent;
    beforeEach(() => {
        stubNoopSettings();
        target = createTarget();
        treeComponent = new TreeOutline.TreeOutline.TreeOutline();
    });
    const updatesUiOnEvent = (inScope) => async () => {
        SDK.TargetManager.TargetManager.instance().setScopeTarget(inScope ? target : null);
        const view = new Elements.AccessibilityTreeView.AccessibilityTreeView(treeComponent);
        renderElementIntoDOM(view);
        const model = target.model(SDK.AccessibilityModel.AccessibilityModel);
        const treeComponentDataSet = sinon.spy(treeComponent, 'data', ['set']);
        sinon.stub(SDK.FrameManager.FrameManager.instance(), 'getOutermostFrame').returns({
            id: MAIN_FRAME_ID,
        });
        model.dispatchEventToListeners("TreeUpdated" /* SDK.AccessibilityModel.Events.TREE_UPDATED */, {
            root: { numChildren: () => 0, role: () => null, getFrameId: () => MAIN_FRAME_ID, id: () => 'id' },
        });
        await new Promise(resolve => queueMicrotask(resolve));
        assert.strictEqual(treeComponentDataSet.set.called, inScope);
        view.detach();
    };
    it('updates UI on in scope update event', updatesUiOnEvent(true));
    it('does not update UI on out of scope update event', updatesUiOnEvent(false));
});
//# sourceMappingURL=AccessibilityTreeView.test.js.map