Skip to content

Commit

Permalink
Make rendering integration tests more robust, get data from page
Browse files Browse the repository at this point in the history
  • Loading branch information
eliperelman committed Jan 14, 2020
1 parent 8579760 commit 369c0bb
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"kibanaVersion": "kibana",
"configPath": ["rendering_plugin"],
"server": true,
"ui": false
"ui": true
}
23 changes: 23 additions & 0 deletions test/plugin_functional/plugins/rendering_plugin/public/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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 { PluginInitializer } from 'kibana/public';
import { RenderingPlugin } from './plugin';

export const plugin: PluginInitializer = () => new RenderingPlugin();
41 changes: 41 additions & 0 deletions test/plugin_functional/plugins/rendering_plugin/public/plugin.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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 React from 'react';
import { render, unmountComponentAtNode } from 'react-dom';
import { Plugin, CoreSetup } from 'kibana/public';

export class RenderingPlugin implements Plugin {
public setup(core: CoreSetup) {
core.application.register({
id: 'rendering',
title: 'Rendering',
appRoute: '/render',
async mount(context, { element }) {
render(<h2>Rendering Service</h2>, element);

return () => unmountComponentAtNode(element);
},
});
}

public start() {}

public stop() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ export class RenderingPlugin implements Plugin {
{
path: '/render/{id}',
validate: {
query: schema.object({
includeUserSettings: schema.boolean({ defaultValue: true }),
}),
query: schema.object(
{
includeUserSettings: schema.boolean({ defaultValue: true }),
},
{ allowUnknowns: true }
),
params: schema.object({
id: schema.maybe(schema.string()),
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ export default function({ getService, getPageObjects }: PluginFunctionalProvider
expect(wrapperWidth).to.be.below(windowWidth);
});

it.skip('can navigate from NP apps to legacy apps', async () => {
it('can navigate from NP apps to legacy apps', async () => {
await appsMenu.clickLink('Management');
await loadingScreenShown();
await testSubjects.existOrFail('managementNav');
});

it.skip('can navigate from legacy apps to NP apps', async () => {
it('can navigate from legacy apps to NP apps', async () => {
await appsMenu.clickLink('Foo');
await loadingScreenShown();
await testSubjects.existOrFail('fooAppHome');
Expand Down
67 changes: 42 additions & 25 deletions test/plugin_functional/test_suites/core_plugins/rendering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,52 +17,69 @@
* under the License.
*/

import { load } from 'cheerio';

import expect from '@kbn/expect';

import '../../plugins/core_provider_plugin/types';
import { PluginFunctionalProviderContext } from '../../services';

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

function navigate(path: string) {
return browser.get(`${PageObjects.common.getHostPort()}${path}`);
}

function getLegacyMode() {
return browser.execute(() => {
return JSON.parse(document.querySelector('kbn-injected-metadata')!.getAttribute('data')!)
.legacyMode;
});
}

function getUserSettings() {
return browser.execute(() => {
return JSON.parse(document.querySelector('kbn-injected-metadata')!.getAttribute('data')!)
.legacyMetadata.uiSettings.user;
});
}

async function loadingScreenNotShown() {
expect(await testSubjects.exists('kbnLoadingMessage')).to.be(false);
}

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'));
await navigate('/render/core');

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();
await loadingScreenNotShown();
expect(await getLegacyMode()).to.be(false);
expect(await getUserSettings()).to.not.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'));
await navigate('/render/core?includeUserSettings=false');

expect(metadata.legacyMode).to.be(false);
expect(metadata.legacyMetadata.uiSettings.user).to.be.empty();
await loadingScreenNotShown();
expect(await getUserSettings()).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'));
await navigate('/render/core_plugin_legacy');

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

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'));
it('renders "legacy" application without user settings', async () => {
await navigate('/render/core_plugin_legacy?includeUserSettings=false');

expect(metadata.legacyMode).to.be(true);
expect(metadata.legacyMetadata.uiSettings.user).to.be.empty();
await loadingScreenNotShown();
expect(await getLegacyMode()).to.be(true);
expect(await getUserSettings()).to.be.empty();
});
});
}
10 changes: 0 additions & 10 deletions test/plugin_functional/test_suites/core_plugins/server_plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,5 @@ export default function({ getService }: PluginFunctionalProviderContext) {
statusCode: 400,
});
});

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

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

0 comments on commit 369c0bb

Please sign in to comment.