mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-06 20:11:38 +08:00
R=tvanderlippe@chromium.org Bug: 1241848 Change-Id: I54cab003ebe6fe38ebce89adb4c57b259cefd9cd Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3197676 Reviewed-by: Tim van der Lippe <tvanderlippe@chromium.org> Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
73 lines
2.9 KiB
TypeScript
73 lines
2.9 KiB
TypeScript
// Copyright 2020 The Chromium Authors. All rights reserved.
|
|
// 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 {click, pressKey, typeText, waitFor} from '../../shared/helper.js';
|
|
import {it} from '../../shared/mocha-extensions.js';
|
|
import {loadComponentDocExample, preloadForCodeCoverage} from '../helpers/shared.js';
|
|
|
|
import type {ElementHandle} from 'puppeteer';
|
|
import type * as TextEditor from '../../../front_end/ui/components/text_editor/text_editor.js';
|
|
|
|
async function getEditorContent(textEditor: ElementHandle): Promise<string> {
|
|
return textEditor.evaluate(node => (node as TextEditor.TextEditor.TextEditor).state.doc.toString());
|
|
}
|
|
|
|
async function getEditorSelection(textEditor: ElementHandle): Promise<{anchor: number, head: number}> {
|
|
return JSON.parse(await textEditor.evaluate(node => {
|
|
const {anchor, head} = (node as TextEditor.TextEditor.TextEditor).state.selection.main;
|
|
return JSON.stringify({anchor, head});
|
|
}));
|
|
}
|
|
|
|
describe('text editor', async () => {
|
|
preloadForCodeCoverage('text_editor/basic.html');
|
|
|
|
it('can insert and delete some text', async () => {
|
|
await loadComponentDocExample('text_editor/basic.html');
|
|
const textEditor = await waitFor('devtools-text-editor');
|
|
|
|
await click('.cm-content', {root: textEditor});
|
|
await typeText('Some text here');
|
|
|
|
assert.strictEqual(await getEditorContent(textEditor), 'Some text here');
|
|
|
|
await pressKey('Backspace');
|
|
await pressKey('Backspace');
|
|
|
|
assert.strictEqual(await getEditorContent(textEditor), 'Some text he');
|
|
});
|
|
|
|
it('binds the expected keys', async () => {
|
|
await loadComponentDocExample('text_editor/basic.html');
|
|
const textEditor = await waitFor('devtools-text-editor');
|
|
|
|
await click('.cm-content', {root: textEditor});
|
|
await typeText('one two');
|
|
const ctrlOrAlt = process.platform === 'darwin' ? {alt: true} : {control: true};
|
|
|
|
await pressKey('ArrowLeft');
|
|
assert.strictEqual((await getEditorSelection(textEditor)).head, 6);
|
|
await pressKey('ArrowLeft', ctrlOrAlt);
|
|
assert.strictEqual((await getEditorSelection(textEditor)).head, 4);
|
|
await pressKey('Home');
|
|
assert.strictEqual((await getEditorSelection(textEditor)).head, 0);
|
|
|
|
await pressKey('ArrowRight');
|
|
assert.strictEqual((await getEditorSelection(textEditor)).head, 1);
|
|
await pressKey('ArrowRight', ctrlOrAlt);
|
|
assert.strictEqual((await getEditorSelection(textEditor)).head, 3);
|
|
await pressKey('End', {control: true});
|
|
assert.strictEqual((await getEditorSelection(textEditor)).head, 7);
|
|
|
|
await typeText(' three');
|
|
assert.strictEqual(await getEditorContent(textEditor), 'one two three');
|
|
await pressKey('Z', {control: true});
|
|
assert.strictEqual(await getEditorContent(textEditor), 'one two');
|
|
await pressKey('Z', {control: true});
|
|
assert.strictEqual(await getEditorContent(textEditor), '');
|
|
});
|
|
});
|