From cca85401ac423b49a40928ab6b8d45ecf30cc7f0 Mon Sep 17 00:00:00 2001 From: fake-haris Date: Fri, 20 Sep 2024 16:36:54 +0300 Subject: [PATCH 1/7] added validations that request and response fields are not empty, added data-test-subj to request and response fields --- .../public/application/components/request_flyout.tsx | 4 ++-- .../apps/painless_lab/painless_lab_flyout.ts | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/painless_lab/public/application/components/request_flyout.tsx b/x-pack/plugins/painless_lab/public/application/components/request_flyout.tsx index 3874c00416e3b..ba8700bfd3c21 100644 --- a/x-pack/plugins/painless_lab/public/application/components/request_flyout.tsx +++ b/x-pack/plugins/painless_lab/public/application/components/request_flyout.tsx @@ -74,7 +74,7 @@ export const RequestFlyout: FunctionComponent = ({ id: 'request', name: 'Request', content: ( - + {'POST _scripts/painless/_execute\n'} {requestBody} @@ -84,7 +84,7 @@ export const RequestFlyout: FunctionComponent = ({ id: 'response', name: 'Response', content: ( - + {response} ), diff --git a/x-pack/test/functional/apps/painless_lab/painless_lab_flyout.ts b/x-pack/test/functional/apps/painless_lab/painless_lab_flyout.ts index 2f03212c72581..70208201df446 100644 --- a/x-pack/test/functional/apps/painless_lab/painless_lab_flyout.ts +++ b/x-pack/test/functional/apps/painless_lab/painless_lab_flyout.ts @@ -5,6 +5,7 @@ * 2.0. */ +import expect from '@kbn/expect/expect'; import { FtrProviderContext } from '../../ftr_provider_context'; export default function ({ getService, getPageObjects }: FtrProviderContext) { @@ -25,5 +26,16 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { await testSubjects.existOrFail('painlessLabRequestFlyoutHeader', { timeout: 10 * 1000 }); }); + + it('validate request body is not empty', async () => { + const requestText = await testSubjects.getVisibleText('painlessLabFlyoutRequest'); + expect(requestText.length === 0).to.be(false); + }); + + it('validate response body is not empty', async () => { + await testSubjects.findService.clickByCssSelector('#response'); + const requestText = await testSubjects.getVisibleText('painlessLabFlyoutResponse'); + expect(requestText.length === 0).to.be(false); + }); }); } From 14103740efdec1511a3931cab966a76d9470a6f7 Mon Sep 17 00:00:00 2001 From: fake-haris Date: Fri, 20 Sep 2024 17:10:18 +0300 Subject: [PATCH 2/7] variable renamed --- .../test/functional/apps/painless_lab/painless_lab_flyout.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/test/functional/apps/painless_lab/painless_lab_flyout.ts b/x-pack/test/functional/apps/painless_lab/painless_lab_flyout.ts index 70208201df446..b5247d68dd589 100644 --- a/x-pack/test/functional/apps/painless_lab/painless_lab_flyout.ts +++ b/x-pack/test/functional/apps/painless_lab/painless_lab_flyout.ts @@ -34,8 +34,8 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { it('validate response body is not empty', async () => { await testSubjects.findService.clickByCssSelector('#response'); - const requestText = await testSubjects.getVisibleText('painlessLabFlyoutResponse'); - expect(requestText.length === 0).to.be(false); + const responseText = await testSubjects.getVisibleText('painlessLabFlyoutResponse'); + expect(responseText.length === 0).to.be(false); }); }); } From 3d0536312775201a5b20db1e1d90d5507a00efad Mon Sep 17 00:00:00 2001 From: fake-haris Date: Tue, 24 Sep 2024 14:30:14 +0300 Subject: [PATCH 3/7] make validations for specific test script --- .../apps/painless_lab/painless_lab_flyout.ts | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/x-pack/test/functional/apps/painless_lab/painless_lab_flyout.ts b/x-pack/test/functional/apps/painless_lab/painless_lab_flyout.ts index b5247d68dd589..f010e0cd08e5f 100644 --- a/x-pack/test/functional/apps/painless_lab/painless_lab_flyout.ts +++ b/x-pack/test/functional/apps/painless_lab/painless_lab_flyout.ts @@ -8,10 +8,25 @@ import expect from '@kbn/expect/expect'; import { FtrProviderContext } from '../../ftr_provider_context'; +const TEST_SCRIPT = `return 1;`; +const TEST_SCRIPT_REQUEST = `POST _scripts/painless/_execute +{ + "script": { + "source": """return 1;""", + "params": { + "string_parameter": "string value", + "number_parameter": 1.5, + "boolean_parameter": true + } + } +}`; +const TEST_SCRIPT_RESPONSE = `"1"`; + export default function ({ getService, getPageObjects }: FtrProviderContext) { const retry = getService('retry'); const PageObjects = getPageObjects(['common', 'console', 'header']); const testSubjects = getService('testSubjects'); + const monacoEditor = getService('monacoEditor'); describe('Painless lab', function describeIndexTests() { before(async () => { @@ -22,20 +37,24 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { }); it('click show API request button and flyout should appear in page', async () => { + // replace the default script with a simpler one + await monacoEditor.setCodeEditorValue(TEST_SCRIPT); await testSubjects.click('btnViewRequest'); - await testSubjects.existOrFail('painlessLabRequestFlyoutHeader', { timeout: 10 * 1000 }); }); - it('validate request body is not empty', async () => { + it('validate request body is the expected', async () => { const requestText = await testSubjects.getVisibleText('painlessLabFlyoutRequest'); - expect(requestText.length === 0).to.be(false); + expect(requestText).equal(TEST_SCRIPT_REQUEST); }); - it('validate response body is not empty', async () => { + it('validate response body is the expected', async () => { await testSubjects.findService.clickByCssSelector('#response'); - const responseText = await testSubjects.getVisibleText('painlessLabFlyoutResponse'); - expect(responseText.length === 0).to.be(false); + await retry.waitFor('Wait for response to change', async () => { + return ( + (await testSubjects.getVisibleText('painlessLabFlyoutResponse')) === TEST_SCRIPT_RESPONSE + ); + }); }); }); } From 84ee4924e02f0b4f9128869fcfc0bbd184ab0f5d Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Tue, 24 Sep 2024 12:33:51 +0000 Subject: [PATCH 4/7] [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix' --- .../application/components/request_flyout.tsx | 14 ++++++++++++-- .../apps/painless_lab/painless_lab_flyout.ts | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/painless_lab/public/application/components/request_flyout.tsx b/x-pack/plugins/painless_lab/public/application/components/request_flyout.tsx index ba8700bfd3c21..58e363bbd7e58 100644 --- a/x-pack/plugins/painless_lab/public/application/components/request_flyout.tsx +++ b/x-pack/plugins/painless_lab/public/application/components/request_flyout.tsx @@ -74,7 +74,12 @@ export const RequestFlyout: FunctionComponent = ({ id: 'request', name: 'Request', content: ( - + {'POST _scripts/painless/_execute\n'} {requestBody} @@ -84,7 +89,12 @@ export const RequestFlyout: FunctionComponent = ({ id: 'response', name: 'Response', content: ( - + {response} ), diff --git a/x-pack/test/functional/apps/painless_lab/painless_lab_flyout.ts b/x-pack/test/functional/apps/painless_lab/painless_lab_flyout.ts index f010e0cd08e5f..4da08b6a6139a 100644 --- a/x-pack/test/functional/apps/painless_lab/painless_lab_flyout.ts +++ b/x-pack/test/functional/apps/painless_lab/painless_lab_flyout.ts @@ -5,7 +5,7 @@ * 2.0. */ -import expect from '@kbn/expect/expect'; +import expect from '@kbn/expect'; import { FtrProviderContext } from '../../ftr_provider_context'; const TEST_SCRIPT = `return 1;`; From 16c45b9987acc36a5afe44a341ff1199bf3b03d6 Mon Sep 17 00:00:00 2001 From: fake-haris Date: Wed, 25 Sep 2024 12:42:54 +0300 Subject: [PATCH 5/7] added validation in setCodeEditorValue in monaco editor, fixes based on pr comments --- test/functional/services/monaco_editor.ts | 6 ++++++ .../functional/apps/painless_lab/painless_lab_flyout.ts | 5 +++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/test/functional/services/monaco_editor.ts b/test/functional/services/monaco_editor.ts index 245a4eef2a549..2e01f24503a7f 100644 --- a/test/functional/services/monaco_editor.ts +++ b/test/functional/services/monaco_editor.ts @@ -8,6 +8,7 @@ */ import { type monaco } from '@kbn/monaco'; +import expect from '@kbn/expect'; import { FtrService } from '../ftr_provider_context'; export class MonacoEditorService extends FtrService { @@ -62,6 +63,11 @@ export class MonacoEditorService extends FtrService { value ); }); + const newCodeEditorValue = await this.getCodeEditorValue(); + expect(newCodeEditorValue).equal( + value, + `Expected value was: ${value}, but got: ${newCodeEditorValue}` + ); } public async getCurrentMarkers(testSubjId: string) { diff --git a/x-pack/test/functional/apps/painless_lab/painless_lab_flyout.ts b/x-pack/test/functional/apps/painless_lab/painless_lab_flyout.ts index 4da08b6a6139a..13d5dd0260169 100644 --- a/x-pack/test/functional/apps/painless_lab/painless_lab_flyout.ts +++ b/x-pack/test/functional/apps/painless_lab/painless_lab_flyout.ts @@ -12,7 +12,7 @@ const TEST_SCRIPT = `return 1;`; const TEST_SCRIPT_REQUEST = `POST _scripts/painless/_execute { "script": { - "source": """return 1;""", + "source": """${TEST_SCRIPT}""", "params": { "string_parameter": "string value", "number_parameter": 1.5, @@ -26,6 +26,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { const retry = getService('retry'); const PageObjects = getPageObjects(['common', 'console', 'header']); const testSubjects = getService('testSubjects'); + const find = getService('find'); const monacoEditor = getService('monacoEditor'); describe('Painless lab', function describeIndexTests() { @@ -49,7 +50,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { }); it('validate response body is the expected', async () => { - await testSubjects.findService.clickByCssSelector('#response'); + await find.clickByCssSelector('#response'); await retry.waitFor('Wait for response to change', async () => { return ( (await testSubjects.getVisibleText('painlessLabFlyoutResponse')) === TEST_SCRIPT_RESPONSE From 7874ad1d0396c356aca17e913e424b6d8fca90d6 Mon Sep 17 00:00:00 2001 From: fake-haris Date: Wed, 25 Sep 2024 13:27:06 +0300 Subject: [PATCH 6/7] moved setCodeEditorValue into defore block --- .../test/functional/apps/painless_lab/painless_lab_flyout.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/test/functional/apps/painless_lab/painless_lab_flyout.ts b/x-pack/test/functional/apps/painless_lab/painless_lab_flyout.ts index 13d5dd0260169..f16b0dfa6f4c3 100644 --- a/x-pack/test/functional/apps/painless_lab/painless_lab_flyout.ts +++ b/x-pack/test/functional/apps/painless_lab/painless_lab_flyout.ts @@ -35,11 +35,11 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { await retry.waitFor('Wait for editor to be visible', async () => { return testSubjects.isDisplayed('painless_lab'); }); + // replace the default script with a simpler one + await monacoEditor.setCodeEditorValue(TEST_SCRIPT); }); it('click show API request button and flyout should appear in page', async () => { - // replace the default script with a simpler one - await monacoEditor.setCodeEditorValue(TEST_SCRIPT); await testSubjects.click('btnViewRequest'); await testSubjects.existOrFail('painlessLabRequestFlyoutHeader', { timeout: 10 * 1000 }); }); From 1e94a5a7c4d53918131d1714e50587f78cb7fd9e Mon Sep 17 00:00:00 2001 From: fake-haris Date: Wed, 25 Sep 2024 17:04:10 +0300 Subject: [PATCH 7/7] added index parameter when calling getCodeEditorValue --- test/functional/services/monaco_editor.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/functional/services/monaco_editor.ts b/test/functional/services/monaco_editor.ts index 2e01f24503a7f..43ce38aa2c787 100644 --- a/test/functional/services/monaco_editor.ts +++ b/test/functional/services/monaco_editor.ts @@ -63,7 +63,7 @@ export class MonacoEditorService extends FtrService { value ); }); - const newCodeEditorValue = await this.getCodeEditorValue(); + const newCodeEditorValue = await this.getCodeEditorValue(nthIndex); expect(newCodeEditorValue).equal( value, `Expected value was: ${value}, but got: ${newCodeEditorValue}`