diff --git a/src/plugins/console/public/application/containers/console_history/console_history.tsx b/src/plugins/console/public/application/containers/console_history/console_history.tsx index dcc19d340ae5d..6918f572ce916 100644 --- a/src/plugins/console/public/application/containers/console_history/console_history.tsx +++ b/src/plugins/console/public/application/containers/console_history/console_history.tsx @@ -188,7 +188,11 @@ export function ConsoleHistory({ close }: Props) { - clear()}> + clear()} + > {i18n.translate('console.historyPage.clearHistoryButtonLabel', { defaultMessage: 'Clear', })} @@ -198,7 +202,11 @@ export function ConsoleHistory({ close }: Props) { - close()}> + close()} + > {i18n.translate('console.historyPage.closehistoryButtonLabel', { defaultMessage: 'Close', })} @@ -207,6 +215,7 @@ export function ConsoleHistory({ close }: Props) { restoreRequestFromHistory(selectedReq.current)} diff --git a/test/functional/apps/console/_console.ts b/test/functional/apps/console/_console.ts index 6736dc5a2f721..d7a591efca014 100644 --- a/test/functional/apps/console/_console.ts +++ b/test/functional/apps/console/_console.ts @@ -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'); @@ -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(); diff --git a/test/functional/apps/console/_text_input.ts b/test/functional/apps/console/_text_input.ts new file mode 100644 index 0000000000000..29290fac6728f --- /dev/null +++ b/test/functional/apps/console/_text_input.ts @@ -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}' + ); + }); + }); + }); + }); +} diff --git a/test/functional/apps/console/index.js b/test/functional/apps/console/index.js index 06c29f0e031ec..a2a1206fe85bd 100644 --- a/test/functional/apps/console/index.js +++ b/test/functional/apps/console/index.js @@ -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')); } }); } diff --git a/test/functional/page_objects/console_page.ts b/test/functional/page_objects/console_page.ts index 0069682f828d6..a368d085160f4 100644 --- a/test/functional/page_objects/console_page.ts +++ b/test/functional/page_objects/console_page.ts @@ -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(); + } }