Skip to content

Commit

Permalink
Merge branch 'master' of github.com:elastic/kibana into 43904_Add_Cle…
Browse files Browse the repository at this point in the history
…anup_Action_To_UI
  • Loading branch information
John Dorlus committed Dec 26, 2019
2 parents f86725a + 6669111 commit 1296528
Show file tree
Hide file tree
Showing 48 changed files with 878 additions and 306 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
import { UiSettingsPlugin } from './plugin';

export const plugin = () => new UiSettingsPlugin();
import Fs from 'fs';
import { promisify } from 'util';

export const readFile = promisify(Fs.readFile);
export const writeFile = promisify(Fs.writeFile);
19 changes: 5 additions & 14 deletions src/core/server/uuid/resolve_uuid.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,22 @@
* under the License.
*/

import { promises } from 'fs';
import { join } from 'path';
import { readFile, writeFile } from './fs';
import { resolveInstanceUuid } from './resolve_uuid';
import { configServiceMock } from '../config/config_service.mock';
import { loggingServiceMock } from '../logging/logging_service.mock';
import { BehaviorSubject } from 'rxjs';
import { Logger } from '../logging';

const { readFile, writeFile } = promises;

jest.mock('uuid', () => ({
v4: () => 'NEW_UUID',
}));

jest.mock('fs', () => {
const actual = jest.requireActual('fs');
return {
...actual,
promises: {
...actual.promises,
readFile: jest.fn(() => Promise.resolve('')),
writeFile: jest.fn(() => Promise.resolve('')),
},
};
});
jest.mock('./fs', () => ({
readFile: jest.fn(() => Promise.resolve('')),
writeFile: jest.fn(() => Promise.resolve('')),
}));

const DEFAULT_FILE_UUID = 'FILE_UUID';
const DEFAULT_CONFIG_UUID = 'CONFIG_UUID';
Expand Down
4 changes: 1 addition & 3 deletions src/core/server/uuid/resolve_uuid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@
*/

import uuid from 'uuid';
import { promises } from 'fs';
import { join } from 'path';
import { take } from 'rxjs/operators';
import { readFile, writeFile } from './fs';
import { IConfigService } from '../config';
import { PathConfigType, config as pathConfigDef } from '../path';
import { HttpConfigType, config as httpConfigDef } from '../http';
import { Logger } from '../logging';

const { readFile, writeFile } = promises;

const FILE_ENCODING = 'utf8';
const FILE_NAME = 'uuid';

Expand Down
5 changes: 3 additions & 2 deletions test/plugin_functional/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ export default async function({ readConfigFile }) {
...functionalConfig.get('kbnTestServer'),
serverArgs: [
...functionalConfig.get('kbnTestServer.serverArgs'),

// Required to load new platform plugins via `--plugin-path` flag.
'--env.name=development',
...plugins.map(
pluginDir => `--plugin-path=${path.resolve(__dirname, 'plugins', pluginDir)}`
),
// Required to load new platform plugins via `--plugin-path` flag.
'--env.name=development',
],
},
};
Expand Down
15 changes: 6 additions & 9 deletions test/plugin_functional/plugins/core_plugin_b/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ import { CorePluginAPluginSetup } from '../../core_plugin_a/public/plugin';

declare global {
interface Window {
corePluginB?: string;
hasAccessToInjectedMetadata?: boolean;
receivedStartServices?: boolean;
env?: PluginInitializerContext['env'];
}
}
Expand All @@ -39,12 +36,6 @@ export class CorePluginBPlugin
window.env = pluginContext.env;
}
public setup(core: CoreSetup, deps: CorePluginBDeps) {
window.corePluginB = `Plugin A said: ${deps.core_plugin_a.getGreeting()}`;
window.hasAccessToInjectedMetadata = 'getInjectedVar' in core.injectedMetadata;
core.getStartServices().then(([coreStart, plugins]) => {
window.receivedStartServices = 'overlays' in coreStart;
});

core.application.register({
id: 'bar',
title: 'Bar',
Expand All @@ -53,6 +44,12 @@ export class CorePluginBPlugin
return renderApp(context, params);
},
});

return {
sayHi() {
return `Plugin A said: ${deps.core_plugin_a.getGreeting()}`;
},
};
}

public start() {}
Expand Down
36 changes: 36 additions & 0 deletions test/plugin_functional/plugins/core_provider_plugin/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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 { resolve } from 'path';
import { Legacy } from '../../../../kibana';

// eslint-disable-next-line import/no-default-export
export default function CoreProviderPlugin(kibana: any) {
const config: Legacy.PluginSpecOptions = {
id: 'core-provider',
require: [],
publicDir: resolve(__dirname, 'public'),
init: (server: Legacy.Server) => ({}),
uiExports: {
hacks: [resolve(__dirname, 'public/index')],
},
};

return new kibana.Plugin(config);
}
17 changes: 17 additions & 0 deletions test/plugin_functional/plugins/core_provider_plugin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "core_provider_plugin",
"version": "1.0.0",
"main": "target/test/plugin_functional/plugins/core_provider_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"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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 { npSetup, npStart } from 'ui/new_platform';
import '../types';

window.__coreProvider = {
setup: npSetup,
start: npStart,
testUtils: {
delay: (ms: number) => new Promise(res => setTimeout(res, ms)),
},
};
14 changes: 14 additions & 0 deletions test/plugin_functional/plugins/core_provider_plugin/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "../../../../tsconfig.json",
"compilerOptions": {
"outDir": "./target",
"skipLibCheck": true
},
"include": [
"index.ts",
"types.ts",
"public/**/*.ts",
"../../../../typings/**/*",
],
"exclude": []
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@
* specific language governing permissions and limitations
* under the License.
*/

import { CoreSetup, Plugin } from 'kibana/public';
import { LegacyCoreSetup, LegacyCoreStart } from 'kibana/public';

declare global {
interface Window {
uiSettingsPlugin?: Record<string, any>;
uiSettingsPluginValue?: string;
__coreProvider: {
setup: {
core: LegacyCoreSetup;
plugins: Record<string, any>;
};
start: {
core: LegacyCoreStart;
plugins: Record<string, any>;
};
testUtils: {
delay: (ms: number) => Promise<void>;
};
};
}
}

export class UiSettingsPlugin implements Plugin {
public setup(core: CoreSetup) {
window.uiSettingsPlugin = core.uiSettings.getAll().ui_settings_plugin;
window.uiSettingsPluginValue = core.uiSettings.get('ui_settings_plugin');
}

public start() {}
public stop() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"kibanaVersion": "kibana",
"configPath": ["ui_settings_plugin"],
"server": true,
"ui": true
"ui": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
"skipLibCheck": true
},
"include": [
"index.ts",
"public/**/*.ts",
"public/**/*.tsx",
"server/**/*.ts",
"../../../../typings/**/*",
],
Expand Down
45 changes: 24 additions & 21 deletions test/plugin_functional/test_suites/core_plugins/ui_plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import expect from '@kbn/expect';
import { PluginFunctionalProviderContext } from '../../services';
import '../../../../test/plugin_functional/plugins/core_provider_plugin/types';

// eslint-disable-next-line import/no-default-export
export default function({ getService, getPageObjects }: PluginFunctionalProviderContext) {
Expand All @@ -31,22 +32,35 @@ export default function({ getService, getPageObjects }: PluginFunctionalProvider
await PageObjects.common.navigateToApp('settings');
});

it('should attach string to window.corePluginB', async () => {
const corePluginB = await browser.execute('return window.corePluginB');
expect(corePluginB).to.equal(`Plugin A said: Hello from Plugin A!`);
it('should run the new platform plugins', async () => {
expect(
await browser.execute(() => {
return window.__coreProvider.setup.plugins.core_plugin_b.sayHi();
})
).to.be('Plugin A said: Hello from Plugin A!');
});
});

describe('have injectedMetadata service provided', function describeIndexTests() {
describe('should have access to the core services', function describeIndexTests() {
before(async () => {
await PageObjects.common.navigateToApp('bar');
await PageObjects.common.navigateToApp('settings');
});

it('to injectedMetadata service', async () => {
expect(
await browser.execute(() => {
return window.__coreProvider.setup.core.injectedMetadata.getKibanaBuildNumber();
})
).to.be.a('number');
});

it('should attach boolean to window.hasAccessToInjectedMetadata', async () => {
const hasAccessToInjectedMetadata = await browser.execute(
'return window.hasAccessToInjectedMetadata'
);
expect(hasAccessToInjectedMetadata).to.equal(true);
it('to start services via coreSetup.getStartServices', async () => {
expect(
await browser.executeAsync(async cb => {
const [coreStart] = await window.__coreProvider.setup.core.getStartServices();
cb(Boolean(coreStart.overlays));
})
).to.be(true);
});
});

Expand All @@ -61,16 +75,5 @@ export default function({ getService, getPageObjects }: PluginFunctionalProvider
expect(envData.packageInfo.version).to.be.a('string');
});
});

describe('have access to start services via coreSetup.getStartServices', function describeIndexTests() {
before(async () => {
await PageObjects.common.navigateToApp('bar');
});

it('should attach boolean to window.receivedStartServices', async () => {
const receivedStartServices = await browser.execute('return window.receivedStartServices');
expect(receivedStartServices).to.equal(true);
});
});
});
}
20 changes: 18 additions & 2 deletions test/plugin_functional/test_suites/core_plugins/ui_settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
import expect from '@kbn/expect';
import { PluginFunctionalProviderContext } from '../../services';
import '../../plugins/core_provider_plugin/types';

// eslint-disable-next-line import/no-default-export
export default function({ getService, getPageObjects }: PluginFunctionalProviderContext) {
Expand All @@ -31,15 +32,30 @@ export default function({ getService, getPageObjects }: PluginFunctionalProvider
});

it('client plugins have access to registered settings', async () => {
const settings = await browser.execute('return window.uiSettingsPlugin');
const settings = await browser.execute(() => {
return window.__coreProvider.setup.core.uiSettings.getAll().ui_settings_plugin;
});

expect(settings).to.eql({
category: ['any'],
description: 'just for testing',
name: 'from_ui_settings_plugin',
value: '2',
});
const settingsValue = await browser.execute('return window.uiSettingsPluginValue');

const settingsValue = await browser.execute(() => {
return window.__coreProvider.setup.core.uiSettings.get('ui_settings_plugin');
});

expect(settingsValue).to.be('2');

const settingsValueViaObservables = await browser.executeAsync(async (callback: Function) => {
window.__coreProvider.setup.core.uiSettings
.get$('ui_settings_plugin')
.subscribe(v => callback(v));
});

expect(settingsValueViaObservables).to.be('2');
});

it('server plugins have access to registered settings', async () => {
Expand Down

0 comments on commit 1296528

Please sign in to comment.