Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move rendering functional tests and add user settings tests #54801

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions src/plugins/testbed/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { schema, TypeOf } from '@kbn/config-schema';
import {
CoreSetup,
CoreStart,
LegacyRenderOptions,
Logger,
PluginInitializerContext,
PluginConfigDescriptor,
Expand Down Expand Up @@ -78,29 +77,6 @@ class Plugin {
}
);

router.get(
{
path: '/requestcontext/render/{id}',
validate: {
params: schema.object({
id: schema.maybe(schema.string()),
}),
},
},
async (context, req, res) => {
const { id } = req.params;
const options: Partial<LegacyRenderOptions> = { app: { getId: () => id! } };
const body = await context.core.rendering.render(options);

return res.ok({
body,
headers: {
'content-securty-policy': core.http.csp.header,
},
});
}
);

return {
data$: this.initializerContext.config.create<ConfigType>().pipe(
map(configValue => {
Expand Down
5 changes: 0 additions & 5 deletions test/api_integration/apis/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ export default function({ getService }) {
200,
'SavedObjects client: {"page":1,"per_page":20,"total":0,"saved_objects":[]}'
));

it('provides access to application rendering client', async () => {
await supertest.get('/requestcontext/render/core').expect(200, /app:core/);
await supertest.get('/requestcontext/render/testbed').expect(200, /app:testbed/);
});
});

describe('compression', () => {
Expand Down
40 changes: 40 additions & 0 deletions test/api_integration/apis/rendering/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export default function({ getService }) {
const supertest = getService('supertest');

describe('rendering', () => {
it('renders "core" application', async () => {
await supertest.get('/render/core').expect(200, /app:core/);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this API only available in the plugin functional tests where the rendering plugin is available?

});

it('renders "core" application without user data', async () => {
await supertest.get('/render/core?excludeUserSettings').expect(200, /app:core/);
});

it('renders "legacy" application', async () => {
await supertest.get('/render/legacy').expect(200, /app:legacy/);
});

it('renders "legacy" application wihtout user data', async () => {
await supertest.get('/render/legacy?excludeUserSettings').expect(200, /app:legacy/);
});
});
}
8 changes: 8 additions & 0 deletions test/plugin_functional/plugins/rendering_plugin/kibana.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"id": "rendering_plugin",
"version": "0.0.1",
"kibanaVersion": "kibana",
"configPath": ["rendering_plugin"],
"server": true,
"ui": false
}
17 changes: 17 additions & 0 deletions test/plugin_functional/plugins/rendering_plugin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "rendering_plugin",
"version": "1.0.0",
"main": "target/test/plugin_functional/plugins/rendering_plugin",
"kibana": {
"version": "kibana",
"templateVersion": "1.0.0"
},
"license": "Apache-2.0",
"scripts": {
"kbn": "node ../../../../scripts/kbn.js",
"build": "rm -rf './target' && tsc"
},
"devDependencies": {
"typescript": "3.5.3"
}
}
22 changes: 22 additions & 0 deletions test/plugin_functional/plugins/rendering_plugin/server/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { RenderingPlugin } from './plugin';

export const plugin = () => new RenderingPlugin();
60 changes: 60 additions & 0 deletions test/plugin_functional/plugins/rendering_plugin/server/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { Plugin, CoreSetup, IRenderOptions } from 'kibana/server';

import { schema } from '@kbn/config-schema';

export class RenderingPlugin implements Plugin {
public setup(core: CoreSetup) {
const router = core.http.createRouter();

router.get(
{
path: '/render/{id}',
validate: {
query: schema.object({
includeUserSettings: schema.boolean({ defaultValue: true }),
}),
params: schema.object({
id: schema.maybe(schema.string()),
}),
},
},
async (context, req, res) => {
const { id } = req.params;
const { includeUserSettings } = req.query;
const app = { getId: () => id! };
const options: Partial<IRenderOptions> = { app, includeUserSettings };
const body = await context.core.rendering.render(options);

return res.ok({
body,
headers: {
'content-security-policy': core.http.csp.header,
},
});
}
);
}

public start() {}

public stop() {}
}
12 changes: 12 additions & 0 deletions test/plugin_functional/plugins/rendering_plugin/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "../../../../tsconfig.json",
"compilerOptions": {
"outDir": "./target",
"skipLibCheck": true
},
"include": [
"server/**/*.ts",
"../../../../typings/**/*",
],
"exclude": []
}
1 change: 1 addition & 0 deletions test/plugin_functional/test_suites/core_plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ export default function({ loadTestFile }: PluginFunctionalProviderContext) {
loadTestFile(require.resolve('./top_nav'));
loadTestFile(require.resolve('./application_leave_confirm'));
loadTestFile(require.resolve('./application_status'));
loadTestFile(require.resolve('./rendering'));
});
}
68 changes: 68 additions & 0 deletions test/plugin_functional/test_suites/core_plugins/rendering.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { load } from 'cheerio';

import expect from '@kbn/expect';

import { PluginFunctionalProviderContext } from '../../services';

// eslint-disable-next-line import/no-default-export
export default function({ getService, getPageObjects }: PluginFunctionalProviderContext) {
const supertest = getService('supertest');

describe('rendering service', () => {
it('renders "core" application', async () => {
const response = await supertest.get('/render/core').expect(200);
const dom = load(response.text);
const metadata = JSON.parse(dom('kbn-injected-metadata').attr('data'));

expect(metadata.legacyMode).to.be(false);
expect(dom('script[src="/bundles/app/core/bootstrap.js"]').length).to.be(1);
expect(metadata.legacyMetadata.uiSettings.user).not.to.be.empty();
});

it('renders "core" application without user settings', async () => {
const response = await supertest.get('/render/core?includeUserSettings=false').expect(200);
const dom = load(response.text);
const metadata = JSON.parse(dom('kbn-injected-metadata').attr('data'));

expect(metadata.legacyMode).to.be(false);
expect(metadata.legacyMetadata.uiSettings.user).to.be.empty();
});

it('renders "legacy" application', async () => {
const response = await supertest.get('/render/legacy').expect(200);
const dom = load(response.text);
const metadata = JSON.parse(dom('kbn-injected-metadata').attr('data'));

expect(metadata.legacyMode).to.be(true);
expect(dom('script[src="/bundles/app/legacy/bootstrap.js"]').length).to.be(1);
});

it('renders "legacy" application wihtout user settings', async () => {
const response = await supertest.get('/render/legacy?includeUserSettings=false').expect(200);
const dom = load(response.text);
const metadata = JSON.parse(dom('kbn-injected-metadata').attr('data'));

expect(metadata.legacyMode).to.be(true);
expect(metadata.legacyMetadata.uiSettings.user).to.be.empty();
});
});
}