Skip to content

Commit

Permalink
[Painless Lab] Add basic functional smoke tests for both serverless a…
Browse files Browse the repository at this point in the history
…nd stateful (#172679)
  • Loading branch information
sabarasaba authored Dec 7, 2023
1 parent f5c78b9 commit 7ea0b23
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 0 deletions.
1 change: 1 addition & 0 deletions .buildkite/ftr_configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ enabled:
- x-pack/test/functional/apps/ml/stack_management_jobs/config.ts
- x-pack/test/functional/apps/monitoring/config.ts
- x-pack/test/functional/apps/observability_log_explorer/config.ts
- x-pack/test/functional/apps/painless_lab/config.ts
- x-pack/test/functional/apps/remote_clusters/config.ts
- x-pack/test/functional/apps/reporting_management/config.ts
- x-pack/test/functional/apps/rollup_job/config.ts
Expand Down
17 changes: 17 additions & 0 deletions x-pack/test/functional/apps/painless_lab/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { FtrConfigProviderContext } from '@kbn/test';

export default async function ({ readConfigFile }: FtrConfigProviderContext) {
const functionalConfig = await readConfigFile(require.resolve('../../config.base.js'));

return {
...functionalConfig.getAll(),
testFiles: [require.resolve('.')],
};
}
14 changes: 14 additions & 0 deletions x-pack/test/functional/apps/painless_lab/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { FtrProviderContext } from '../../ftr_provider_context';

export default ({ loadTestFile }: FtrProviderContext) => {
describe('Painless lab app', function () {
loadTestFile(require.resolve('./painless_lab'));
});
};
53 changes: 53 additions & 0 deletions x-pack/test/functional/apps/painless_lab/painless_lab.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import expect from '@kbn/expect';
import { FtrProviderContext } from '../../ftr_provider_context';

const TEST_SCRIPT_RESULT = 45;
const TEST_SCRIPT = `
int total = 0;
for (int i = 0; i < 10; ++i) {
total += i;
}
return total;
`.trim();

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 () => {
await PageObjects.common.navigateToApp('dev_tools', { hash: '/painless_lab' });
await retry.waitFor('Wait for editor to be visible', async () => {
return testSubjects.isDisplayed('painless_lab');
});
});

it('should show the editor and preview panels', async () => {
const editor = await testSubjects.find('kibanaCodeEditor');
const preview = await testSubjects.find('painlessTabs');

expect(await editor.isDisplayed()).to.be(true);
expect(await preview.isDisplayed()).to.be(true);
});

it('executes the script and shows the right result', async () => {
await monacoEditor.setCodeEditorValue(TEST_SCRIPT);

await retry.try(async () => {
const result = await testSubjects.find('painlessTabs');
expect(await result.getVisibleText()).to.contain(TEST_SCRIPT_RESULT.toString());
});
});
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { FtrProviderContext } from '../../../ftr_provider_context';

export default function ({ loadTestFile }: FtrProviderContext) {
describe('Serverless Common UI - Painless lab', function () {
loadTestFile(require.resolve('./painless_lab'));
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../ftr_provider_context';

const TEST_SCRIPT_RESULT = 45;
const TEST_SCRIPT = `
int total = 0;
for (int i = 0; i < 10; ++i) {
total += i;
}
return total;
`.trim();

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

describe('Painless lab', function describeIndexTests() {
before(async () => {
await PageObjects.svlCommonPage.login();
await PageObjects.common.navigateToApp('dev_tools', { hash: '/painless_lab' });
await retry.waitFor('Wait for editor to be visible', async () => {
return testSubjects.isDisplayed('painless_lab');
});
});

after(async () => {
await PageObjects.svlCommonPage.forceLogout();
});

it('should show the editor and preview panels', async () => {
const editor = await testSubjects.find('kibanaCodeEditor');
const preview = await testSubjects.find('painlessTabs');

expect(await editor.isDisplayed()).to.be(true);
expect(await preview.isDisplayed()).to.be(true);
});

it('executes the script and shows the right result', async () => {
await monacoEditor.setCodeEditorValue(TEST_SCRIPT);

await retry.try(async () => {
const result = await testSubjects.find('painlessTabs');
expect(await result.getVisibleText()).to.contain(TEST_SCRIPT_RESULT.toString());
});
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) {
require.resolve('../../common/reporting'),
require.resolve('../../common/grok_debugger'),
require.resolve('../../common/console'),
require.resolve('../../common/painless_lab'),
],
junit: {
reportName: 'Serverless Observability Functional Tests - Common Group 1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) {
require.resolve('../../common/reporting'),
require.resolve('../../common/grok_debugger'),
require.resolve('../../common/console'),
require.resolve('../../common/painless_lab'),
],
junit: {
reportName: 'Serverless Security Functional Tests - Common Group 1',
Expand Down

0 comments on commit 7ea0b23

Please sign in to comment.