// Copyright 2022 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 {click, getBrowserAndPages, typeText, waitFor, waitForNone} from '../../shared/helper.js';
import {describe, it} from '../../shared/mocha-extensions.js';
import {CONSOLE_CREATE_LIVE_EXPRESSION_SELECTOR, CONSOLE_TAB_SELECTOR} from '../helpers/console-helpers.js';

describe('The Console Tab', () => {
  it('commits live expression with Enter', async () => {
    const {frontend} = getBrowserAndPages();

    await click(CONSOLE_TAB_SELECTOR);
    await click(CONSOLE_CREATE_LIVE_EXPRESSION_SELECTOR);

    const consolePin = await waitFor('.console-pin');

    await waitFor('.cm-editor.cm-focused', consolePin);
    await typeText('1 + 2 + 3');

    const editorUnfocusedPromise = waitForNone('.cm-editor.cm-focused', consolePin);
    await frontend.keyboard.press('Enter');
    await editorUnfocusedPromise;
  });
});

// Copyright 2022 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 {click, getBrowserAndPages, typeText, waitFor, waitForNone} from '../../shared/helper.js';
import {describe, it} from '../../shared/mocha-extensions.js';
import {CONSOLE_CREATE_LIVE_EXPRESSION_SELECTOR, CONSOLE_TAB_SELECTOR} from '../helpers/console-helpers.js';

describe('The Console Tab', () => {
  it('commits live expression with Enter', async () => {
    const {frontend} = getBrowserAndPages();

    await click(CONSOLE_TAB_SELECTOR);
    await click(CONSOLE_CREATE_LIVE_EXPRESSION_SELECTOR);

    const consolePin = await waitFor('.console-pin');
    const editorFocusedPromise = waitFor('.cm-editor.cm-focused', consolePin);
    const editorUnfocusedPromise = waitForNone('.cm-editor.cm-focused', consolePin);

    await editorFocusedPromise;
    await typeText('1 + 2 + 3');
    await frontend.keyboard.press('Enter');
    await editorUnfocusedPromise;
  });
});

--- 
+++ 
@@ -14,11 +14,11 @@
     await click(CONSOLE_CREATE_LIVE_EXPRESSION_SELECTOR);
 
     const consolePin = await waitFor('.console-pin');
-    const editorFocusedPromise = waitFor('.cm-editor.cm-focused', consolePin);
+
+    await waitFor('.cm-editor.cm-focused', consolePin);
+    await typeText('1 + 2 + 3');
+
     const editorUnfocusedPromise = waitForNone('.cm-editor.cm-focused', consolePin);
-
-    await editorFocusedPromise;
-    await typeText('1 + 2 + 3');
     await frontend.keyboard.press('Enter');
     await editorUnfocusedPromise;
   });
[console] Fix live expression e2e test.

Bug: chromium:1260744
Change-Id: I001298ec21e42d6f469548dc2c82fb9e8f283e04
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3566004
Commit-Queue: Benedikt Meurer <024a1e0af501338d11c3b837c6193d11c140d792@chromium.org>
Auto-Submit: Benedikt Meurer <024a1e0af501338d11c3b837c6193d11c140d792@chromium.org>
Reviewed-by: Danil Somsikov <f16a5ee11618cab93684e694f9aa762d34f02920@chromium.org>
Commit-Queue: Danil Somsikov <f16a5ee11618cab93684e694f9aa762d34f02920@chromium.org>
