"use strict";
// Copyright 2020 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 changes_helpers_js_1 = require("../helpers/changes-helpers.js");
const elements_helpers_js_1 = require("../helpers/elements-helpers.js");
const quick_open_helpers_js_1 = require("../helpers/quick_open-helpers.js");
const visual_logging_helpers_js_1 = require("../helpers/visual-logging-helpers.js");
describe('The Changes Panel', () => {
    const PANEL_ROOT_SELECTOR = 'div[aria-label="Changes panel"]';
    async function openChangesPanelAndNavigateTo(testName, devToolsPage, inspectedPage) {
        await inspectedPage.goToResource(`changes/${testName}.html`);
        await (0, quick_open_helpers_js_1.openCommandMenu)(devToolsPage);
        await devToolsPage.page.keyboard.type('changes');
        // TODO: it should actually wait for rendering to finish.
        await devToolsPage.drainTaskQueue();
        await devToolsPage.page.keyboard.press('Enter');
        // TODO: it should actually wait for rendering to finish.
        await devToolsPage.drainTaskQueue();
        await devToolsPage.waitFor(PANEL_ROOT_SELECTOR);
    }
    async function getChangesList(devToolsPage) {
        const root = await devToolsPage.waitFor(PANEL_ROOT_SELECTOR);
        const items = await devToolsPage.$$('.tree-element-title', root);
        return await Promise.all(items.map(node => {
            return node.evaluate(node => node.innerText);
        }));
    }
    async function waitForNewChanges(initialChanges, devToolsPage) {
        let newChanges = [];
        return await devToolsPage.waitForFunction(async () => {
            newChanges = await getChangesList(devToolsPage);
            return newChanges.length !== initialChanges.length;
        });
    }
    it('Shows changes made in the Styles pane', async ({ devToolsPage, inspectedPage }) => {
        const TEST_PAGE = 'styled-page';
        await openChangesPanelAndNavigateTo(TEST_PAGE, devToolsPage, inspectedPage);
        let changes = await getChangesList(devToolsPage);
        chai_1.assert.lengthOf(changes, 0, 'There should be no changes by default');
        await (0, elements_helpers_js_1.editCSSProperty)('html, body', 'background', 'red', devToolsPage);
        await waitForNewChanges(changes, devToolsPage);
        changes = await getChangesList(devToolsPage);
        chai_1.assert.lengthOf(changes, 1, 'There should now be 1 change in the list');
        chai_1.assert.strictEqual(changes[0], `${TEST_PAGE}.html`);
        await (0, visual_logging_helpers_js_1.expectVeEvents)([
            (0, visual_logging_helpers_js_1.veImpressionsUnder)('Drawer', [(0, changes_helpers_js_1.veImpressionForChangesPanel)()]),
        ], undefined, devToolsPage);
    });
});
//# sourceMappingURL=changes.test.js.map