Skip to content

Commit

Permalink
console tests
Browse files Browse the repository at this point in the history
  • Loading branch information
midleman committed Nov 1, 2024
1 parent b553330 commit d10dad3
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 1 deletion.
2 changes: 1 addition & 1 deletion test/smoke/src/e2e/console/console-ansi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ test.use({
suiteId: __filename
});

test.describe('Console ANSI styling', () => {
test.describe('Console ANSI styling', { tag: ['@pr'] }, () => {
test.beforeEach(async function ({ app, interpreter }) {
await app.workbench.positronLayouts.enterLayout('fullSizedPanel');
await interpreter.set('R');
Expand Down
118 changes: 118 additions & 0 deletions test/smoke/src/e2e/console/console-input.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*---------------------------------------------------------------------------------------------
* Copyright (C) 2024 Posit Software, PBC. All rights reserved.
* Licensed under the Elastic License 2.0. See LICENSE.txt for license information.
*--------------------------------------------------------------------------------------------*/

import { test, expect } from '../_test.setup';

test.use({
suiteId: __filename
});

test.describe('Console Input', {
tag: ['@web', '@pr', '@win']
}, () => {

test.describe('Console Input - Python', () => {
test.beforeEach(async function ({ app, interpreter }) {
await interpreter.set('Python');
await app.workbench.positronLayouts.enterLayout('fullSizedPanel');
});

test('Python - Get Input String Console [C667516]', async function ({ app, interpreter }) {
await interpreter.set('Python');
const inputCode = `val = input("Enter your name: ")
print(f'Hello {val}!')`;

await expect(async () => {
await app.workbench.positronConsole.pasteCodeToConsole(inputCode);
await app.workbench.positronConsole.sendEnterKey();
await app.workbench.positronConsole.waitForConsoleContents((contents) => contents.some((line) => line.includes('Enter your name:')));

// slight wait before starting to type
await app.code.wait(200);

await app.workbench.positronConsole.typeToConsole('John Doe');
await app.workbench.positronConsole.sendEnterKey();
await app.workbench.positronConsole.waitForConsoleContents((contents) => contents.some((line) => line.includes('Hello John Doe!')));
}).toPass({ timeout: 60000 });
});
});

test.describe('Console Input - R', () => {
test.beforeEach(async function ({ app, interpreter }) {
await interpreter.set('R');
await app.workbench.positronLayouts.enterLayout('fullSizedPanel');
});

test('R - Get Input String Console [C667517]', async function ({ app }) {
const inputCode = `val <- readline(prompt = "Enter your name: ")
cat(sprintf('Hello %s!\n', val))`;

await expect(async () => {
await app.workbench.positronConsole.pasteCodeToConsole(inputCode);
await app.workbench.positronConsole.sendEnterKey();
await app.workbench.positronConsole.waitForConsoleContents((contents) => contents.some((line) => line.includes('Enter your name:')));

// slight wait before starting to type
await app.code.wait(200);
await app.workbench.positronConsole.typeToConsole('John Doe');
await app.workbench.positronConsole.sendEnterKey();
await app.workbench.positronConsole.waitForConsoleContents((contents) => contents.some((line) => line.includes('Hello John Doe!')));
}).toPass({ timeout: 60000 });

});

test('R - Can use `menu` to select alternatives [C684749]', async function ({ app }) {
const inputCode = `x <- menu(letters)`;

await expect(async () => {
await app.workbench.positronConsole.pasteCodeToConsole(inputCode);
await app.workbench.positronConsole.sendEnterKey();
await app.workbench.positronConsole.waitForConsoleContents((contents) => contents.some((line) => line.includes('Selection:')));

// slight wait before starting to type
await app.code.wait(200);
await app.workbench.positronConsole.typeToConsole('1');
await app.workbench.positronConsole.sendEnterKey();

// slight wait before starting to type
await app.code.wait(200);
await app.workbench.positronConsole.typeToConsole('x');
await app.workbench.positronConsole.sendEnterKey();

await app.workbench.positronConsole.waitForConsoleContents((contents) => contents.some((line) => line.includes('[1] 1')));
}).toPass({ timeout: 60000 });
});

test("R - Esc only dismisses autocomplete not full text typed into console [C685868]", async function ({ app }) {
// This is a regression test for https://github.com/posit-dev/positron/issues/1161

const inputCode = `base::mea`;

await expect(async () => {
await app.workbench.positronConsole.typeToConsole(inputCode);
}).toPass({ timeout: 600 });

Check failure on line 95 in test/smoke/src/e2e/console/console-input.test.ts

View workflow job for this annotation

GitHub Actions / positron-ci / e2e-playwright

[e2e-electron] › console/console-input.test.ts:88:7 › Console Input › Console Input - R › R - Esc only dismisses autocomplete not full text typed into console [C685868]

1) [e2e-electron] › console/console-input.test.ts:88:7 › Console Input › Console Input - R › R - Esc only dismisses autocomplete not full text typed into console [C685868] Error: Timeout 600ms exceeded while waiting on the predicate 93 | await expect(async () => { 94 | await app.workbench.positronConsole.typeToConsole(inputCode); > 95 | }).toPass({ timeout: 600 }); | ^ 96 | 97 | const activeConsole = app.workbench.positronConsole.activeConsole; 98 | at /home/runner/work/positron/positron/test/smoke/src/e2e/console/console-input.test.ts:95:7

const activeConsole = app.workbench.positronConsole.activeConsole;

// Makes sure the code suggestions are activated
const suggestion = activeConsole.locator('.suggest-widget');
await expect(suggestion).toBeVisible();

// We now send `Esc` to dismiss the suggestion
await app.workbench.positronConsole.sendKeyboardKey('Escape');
await expect(suggestion).toBeHidden();

const inputLocator = activeConsole.locator(".console-input");

// Send the next `Esc`, that shoukldn't cleanup the typed text
await app.workbench.positronConsole.sendKeyboardKey('Escape');
await expect(inputLocator).toContainText('base::mea');

// We can clear the console text with Ctrl + C
await app.workbench.positronConsole.sendKeyboardKey('Control+C');
await expect(inputLocator).not.toContainText("base::mea");
});
});
});

0 comments on commit d10dad3

Please sign in to comment.