"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");
describe('text editor', () => {
    // Undocked mode helps against flakes when opening tabs (here Sources)
    // update to openPanel once it is able to also look for tabs in 'More tabs' menu
    setup({ dockingMode: 'undocked' });
    async function getEditorContent(textEditor) {
        return await textEditor.evaluate(node => node.state.doc.toString());
    }
    async function getEditorSelection(textEditor) {
        return JSON.parse(await textEditor.evaluate(node => {
            const { anchor, head } = node.state.selection.main;
            return JSON.stringify({ anchor, head });
        }));
    }
    async function openSnippet(devToolsPage) {
        await devToolsPage.click('aria/Sources');
        const sources = await devToolsPage.waitForAria('Sources panel');
        await devToolsPage.click('aria/More tabs', { root: sources });
        await devToolsPage.click('aria/Snippets');
        await devToolsPage.click('aria/New snippet');
    }
    it('can insert and delete some text', async ({ devToolsPage }) => {
        await openSnippet(devToolsPage);
        const textEditor = await devToolsPage.waitFor('devtools-text-editor');
        await devToolsPage.click('.cm-content', { root: textEditor });
        await devToolsPage.typeText('Some text here');
        chai_1.assert.strictEqual(await getEditorContent(textEditor), 'Some text here');
        await devToolsPage.pressKey('Backspace');
        await devToolsPage.pressKey('Backspace');
        chai_1.assert.strictEqual(await getEditorContent(textEditor), 'Some text he');
        await devToolsPage.pressKey('S', {
            control: true,
        });
    });
    it('binds the expected keys', async ({ devToolsPage }) => {
        await openSnippet(devToolsPage);
        const textEditor = await devToolsPage.waitFor('devtools-text-editor');
        await devToolsPage.click('.cm-content', { root: textEditor });
        await devToolsPage.typeText('one two');
        const ctrlOrAlt = process.platform === 'darwin' ? { alt: true } : { control: true };
        await devToolsPage.pressKey('ArrowLeft');
        chai_1.assert.strictEqual((await getEditorSelection(textEditor)).head, 6);
        await devToolsPage.pressKey('ArrowLeft', ctrlOrAlt);
        chai_1.assert.strictEqual((await getEditorSelection(textEditor)).head, 4);
        await devToolsPage.pressKey('Home');
        chai_1.assert.strictEqual((await getEditorSelection(textEditor)).head, 0);
        await devToolsPage.pressKey('ArrowRight');
        chai_1.assert.strictEqual((await getEditorSelection(textEditor)).head, 1);
        await devToolsPage.pressKey('ArrowRight', ctrlOrAlt);
        chai_1.assert.strictEqual((await getEditorSelection(textEditor)).head, 3);
        await devToolsPage.pressKey('End', { control: true });
        chai_1.assert.strictEqual((await getEditorSelection(textEditor)).head, 7);
        await devToolsPage.typeText(' three');
        chai_1.assert.strictEqual(await getEditorContent(textEditor), 'one two three');
        await devToolsPage.pressKey('Z', { control: true });
        chai_1.assert.strictEqual(await getEditorContent(textEditor), 'one two');
        await devToolsPage.pressKey('Z', { control: true });
        chai_1.assert.strictEqual(await getEditorContent(textEditor), '');
        await devToolsPage.pressKey('S', {
            control: true,
        });
    });
});
//# sourceMappingURL=text-editor.test.js.map