Skip to content

Commit

Permalink
[Console] Add tests for Console's text input
Browse files Browse the repository at this point in the history
Co-authored-by: Muhammad Ibragimov <[email protected]>
  • Loading branch information
mibragimov and Muhammad Ibragimov authored Oct 11, 2022
1 parent 860ca8c commit 4e68ec9
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,11 @@ export function ConsoleHistory({ close }: Props) {

<EuiFlexGroup justifyContent="spaceBetween" alignItems="center">
<EuiFlexItem grow={false}>
<EuiButtonEmpty color="danger" onClick={() => clear()}>
<EuiButtonEmpty
data-test-subj="consoleClearHistoryButton"
color="danger"
onClick={() => clear()}
>
{i18n.translate('console.historyPage.clearHistoryButtonLabel', {
defaultMessage: 'Clear',
})}
Expand All @@ -198,7 +202,11 @@ export function ConsoleHistory({ close }: Props) {
<EuiFlexItem grow={false}>
<EuiFlexGroup justifyContent="flexEnd" alignItems="center">
<EuiFlexItem grow={false}>
<EuiButtonEmpty color="primary" onClick={() => close()}>
<EuiButtonEmpty
data-test-subj="consoleHistoryCloseButton"
color="primary"
onClick={() => close()}
>
{i18n.translate('console.historyPage.closehistoryButtonLabel', {
defaultMessage: 'Close',
})}
Expand All @@ -207,6 +215,7 @@ export function ConsoleHistory({ close }: Props) {

<EuiFlexItem grow={false}>
<EuiButton
data-test-subj="consoleHistoryApplyButton"
color="primary"
disabled={!selectedReq}
onClick={() => restoreRequestFromHistory(selectedReq.current)}
Expand Down
27 changes: 0 additions & 27 deletions test/functional/apps/console/_console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
const log = getService('log');
const browser = getService('browser');
const PageObjects = getPageObjects(['common', 'console', 'header']);
const toasts = getService('toasts');
const security = getService('security');
const testSubjects = getService('testSubjects');

Expand Down Expand Up @@ -72,32 +71,6 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
expect(initialSize.width).to.be.greaterThan(afterSize.width);
});

describe('with a data URI in the load_from query', () => {
it('loads the data from the URI', async () => {
await PageObjects.common.navigateToApp('console', {
hash: '#/console?load_from=data:text/plain,BYUwNmD2Q',
});

await retry.try(async () => {
const actualRequest = await PageObjects.console.getRequest();
log.debug(actualRequest);
expect(actualRequest.trim()).to.eql('hello');
});
});

describe('with invalid data', () => {
it('shows a toast error', async () => {
await PageObjects.common.navigateToApp('console', {
hash: '#/console?load_from=data:text/plain,BYUwNmD2',
});

await retry.try(async () => {
expect(await toasts.getToastCount()).to.equal(1);
});
});
});
});

describe('with kbn: prefix in request', () => {
before(async () => {
await PageObjects.console.clearTextArea();
Expand Down
100 changes: 100 additions & 0 deletions test/functional/apps/console/_text_input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import expect from '@kbn/expect';
import { FtrProviderContext } from '../../ftr_provider_context';

export default function ({ getService, getPageObjects }: FtrProviderContext) {
const retry = getService('retry');
const toasts = getService('toasts');
const PageObjects = getPageObjects(['common', 'console', 'header']);

describe('text input', function testTextInput() {
before(async () => {
await PageObjects.common.navigateToApp('console');
await PageObjects.console.collapseHelp();
});

beforeEach(async () => {
await PageObjects.console.clearTextArea();
});

describe('with a data URI in the load_from query', () => {
it('loads the data from the URI', async () => {
await PageObjects.common.navigateToApp('console', {
hash: '#/console?load_from=data:text/plain,BYUwNmD2Q',
});

await retry.try(async () => {
const actualRequest = await PageObjects.console.getRequest();
expect(actualRequest.trim()).to.eql('hello');
});
});

describe('with invalid data', () => {
it('shows a toast error', async () => {
await PageObjects.common.navigateToApp('console', {
hash: '#/console?load_from=data:text/plain,BYUwNmD2',
});

await retry.try(async () => {
expect(await toasts.getToastCount()).to.equal(1);
});
});
});
});

describe('copy/pasting cURL commands into the console', () => {
it('should convert cURL commands into the console request format', async () => {
await PageObjects.console.enterRequest(
`\n curl -XGET "http://localhost:9200/_search?pretty" -d'\n{"query": {"match_all": {}}}'`
);
await PageObjects.console.copyRequestsToClipboard();
await PageObjects.console.clearTextArea();
await PageObjects.console.pasteClipboardValue();
await retry.try(async () => {
const actualRequest = await PageObjects.console.getRequest();
expect(actualRequest.trim()).to.eql('GET /_search?pretty\n {"query": {"match_all": {}}}');
});
});
});

describe('console history', () => {
const sendRequest = async (request: string) => {
await PageObjects.console.enterRequest(request);
await PageObjects.console.clickPlay();
await PageObjects.header.waitUntilLoadingHasFinished();
};

it('should show the history', async () => {
await sendRequest('GET /_search?pretty');
await PageObjects.console.clickHistory();
await retry.try(async () => {
const history = await PageObjects.console.getHistoryEntries();
expect(history).to.eql(['/_search?pretty (a few seconds ago)']);
});

// Clear the history
await PageObjects.console.clickClearHistory();
await PageObjects.console.closeHistory();
});

it('should load a request from history', async () => {
await sendRequest('GET _search\n{"query": {"match_all": {}}}');
await PageObjects.console.clearTextArea();
await PageObjects.console.clickHistory();
await PageObjects.console.loadRequestFromHistory(0);
await retry.try(async () => {
const actualRequest = await PageObjects.console.getRequest();
expect(actualRequest.trim()).to.eql(
'GET _search\n{\n "query": {\n "match_all": {}\n }\n}'
);
});
});
});
});
}
1 change: 1 addition & 0 deletions test/functional/apps/console/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default function ({ getService, loadTestFile }) {
loadTestFile(require.resolve('./_xjson'));
loadTestFile(require.resolve('./_misc_console_behavior'));
loadTestFile(require.resolve('./_context_menu'));
loadTestFile(require.resolve('./_text_input'));
}
});
}
42 changes: 42 additions & 0 deletions test/functional/page_objects/console_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,4 +505,46 @@ export class ConsolePageObject extends FtrService {
const body = await this.getRequestBody();
return body.split('\n').length;
}

public async copyRequestsToClipboard() {
const textArea = await this.testSubjects.find('console-textarea');
await textArea.pressKeys([Key[process.platform === 'darwin' ? 'COMMAND' : 'CONTROL'], 'a']);
await textArea.pressKeys([Key[process.platform === 'darwin' ? 'COMMAND' : 'CONTROL'], 'c']);
}

public async pasteClipboardValue() {
const textArea = await this.testSubjects.find('console-textarea');
await textArea.pressKeys([Key[process.platform === 'darwin' ? 'COMMAND' : 'CONTROL'], 'v']);
}

public async clickHistory() {
const historyButton = await this.testSubjects.find('consoleHistoryButton');
await historyButton.click();
}

public async getHistoryEntries() {
const history = await this.find.allByCssSelector('.list-group-item');
return await Promise.all(history.map(async (item) => await item.getVisibleText()));
}

public async loadRequestFromHistory(index: number) {
const historyItem = await this.find.byCssSelector(`#historyReq${index}`);
await historyItem.click();
await this.testSubjects.click('consoleHistoryApplyButton');
}

public async clickClearHistory() {
const clearHistoryButton = await this.testSubjects.find('consoleClearHistoryButton');
await clearHistoryButton.click();

await this.retry.waitFor('history to be cleared', async () => {
const history = await this.getHistoryEntries();
return history.length === 0;
});
}

public async closeHistory() {
const closeButton = await this.testSubjects.find('consoleHistoryCloseButton');
await closeButton.click();
}
}

0 comments on commit 4e68ec9

Please sign in to comment.