mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[Reporting] Remove banner from reports (#116147)
* remove banner from reports * added types file * updated types references and imports * added screenshot mode public mock * added jest tests for when screenshot mode is enabled * Update x-pack/plugins/banners/public/plugin.test.tsx Co-authored-by: Michael Dokolin <dokmic@gmail.com> * Update x-pack/plugins/banners/public/plugin.test.tsx Co-authored-by: Michael Dokolin <dokmic@gmail.com> Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Michael Dokolin <dokmic@gmail.com>
This commit is contained in:
parent
25426708a8
commit
d9bbe9c9be
6 changed files with 73 additions and 22 deletions
19
src/plugins/screenshot_mode/public/mocks.ts
Normal file
19
src/plugins/screenshot_mode/public/mocks.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* 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 and the Server Side Public License, v 1; you may not use this file except
|
||||
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import type { DeeplyMockedKeys } from '@kbn/utility-types/jest';
|
||||
import type { ScreenshotModePluginSetup, ScreenshotModePluginStart } from './types';
|
||||
|
||||
export const screenshotModePluginMock = {
|
||||
createSetupContract: (): DeeplyMockedKeys<ScreenshotModePluginSetup> => ({
|
||||
isScreenshotMode: jest.fn(() => false),
|
||||
}),
|
||||
createStartContract: (): DeeplyMockedKeys<ScreenshotModePluginStart> => ({
|
||||
isScreenshotMode: jest.fn(() => false),
|
||||
}),
|
||||
};
|
|
@ -8,7 +8,7 @@
|
|||
"kibanaVersion": "kibana",
|
||||
"server": true,
|
||||
"ui": true,
|
||||
"requiredPlugins": ["licensing"],
|
||||
"requiredPlugins": ["licensing", "screenshotMode"],
|
||||
"optionalPlugins": [],
|
||||
"requiredBundles": ["kibanaReact"],
|
||||
"configPath": ["xpack", "banners"]
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
import { getBannerInfoMock } from './plugin.test.mocks';
|
||||
import { coreMock } from '../../../../src/core/public/mocks';
|
||||
import { screenshotModePluginMock } from '../../../../src/plugins/screenshot_mode/public/mocks';
|
||||
import { BannerConfiguration } from '../common/types';
|
||||
import { BannersPlugin } from './plugin';
|
||||
|
||||
|
@ -25,11 +26,13 @@ describe('BannersPlugin', () => {
|
|||
let pluginInitContext: ReturnType<typeof coreMock.createPluginInitializerContext>;
|
||||
let coreSetup: ReturnType<typeof coreMock.createSetup>;
|
||||
let coreStart: ReturnType<typeof coreMock.createStart>;
|
||||
let screenshotModeStart: ReturnType<typeof screenshotModePluginMock.createStartContract>;
|
||||
|
||||
beforeEach(() => {
|
||||
pluginInitContext = coreMock.createPluginInitializerContext();
|
||||
coreSetup = coreMock.createSetup();
|
||||
coreStart = coreMock.createStart();
|
||||
screenshotModeStart = screenshotModePluginMock.createStartContract();
|
||||
|
||||
getBannerInfoMock.mockResolvedValue({
|
||||
allowed: false,
|
||||
|
@ -41,7 +44,7 @@ describe('BannersPlugin', () => {
|
|||
pluginInitContext = coreMock.createPluginInitializerContext();
|
||||
plugin = new BannersPlugin(pluginInitContext);
|
||||
plugin.setup(coreSetup);
|
||||
plugin.start(coreStart);
|
||||
plugin.start(coreStart, { screenshotMode: screenshotModeStart });
|
||||
// await for the `getBannerInfo` promise to resolve
|
||||
await nextTick();
|
||||
};
|
||||
|
@ -79,6 +82,14 @@ describe('BannersPlugin', () => {
|
|||
|
||||
expect(coreStart.chrome.setHeaderBanner).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
it('does not register the banner in screenshot mode', async () => {
|
||||
screenshotModeStart.isScreenshotMode.mockReturnValue(true);
|
||||
|
||||
await startPlugin();
|
||||
|
||||
expect(coreStart.chrome.setHeaderBanner).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when banner is not allowed', () => {
|
||||
|
@ -107,5 +118,13 @@ describe('BannersPlugin', () => {
|
|||
|
||||
expect(coreStart.chrome.setHeaderBanner).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
it('does not register the banner in screenshot mode', async () => {
|
||||
screenshotModeStart.isScreenshotMode.mockReturnValue(true);
|
||||
|
||||
await startPlugin();
|
||||
|
||||
expect(coreStart.chrome.setHeaderBanner).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -10,27 +10,33 @@ import { CoreSetup, CoreStart, Plugin, PluginInitializerContext } from 'src/core
|
|||
import { toMountPoint } from '../../../../src/plugins/kibana_react/public';
|
||||
import { Banner } from './components';
|
||||
import { getBannerInfo } from './get_banner_info';
|
||||
import { BannerPluginStartDependencies } from './types';
|
||||
|
||||
export class BannersPlugin implements Plugin<{}, {}, {}, {}> {
|
||||
export class BannersPlugin implements Plugin<{}, {}, {}, BannerPluginStartDependencies> {
|
||||
constructor(context: PluginInitializerContext) {}
|
||||
|
||||
setup({}: CoreSetup<{}, {}>) {
|
||||
return {};
|
||||
}
|
||||
|
||||
start({ chrome, uiSettings, http }: CoreStart) {
|
||||
getBannerInfo(http).then(
|
||||
({ allowed, banner }) => {
|
||||
if (allowed && banner.placement === 'top') {
|
||||
chrome.setHeaderBanner({
|
||||
content: toMountPoint(<Banner bannerConfig={banner} />),
|
||||
});
|
||||
start(
|
||||
{ chrome, uiSettings, http }: CoreStart,
|
||||
{ screenshotMode }: BannerPluginStartDependencies
|
||||
) {
|
||||
if (!screenshotMode.isScreenshotMode()) {
|
||||
getBannerInfo(http).then(
|
||||
({ allowed, banner }) => {
|
||||
if (allowed && banner.placement === 'top') {
|
||||
chrome.setHeaderBanner({
|
||||
content: toMountPoint(<Banner bannerConfig={banner} />),
|
||||
});
|
||||
}
|
||||
},
|
||||
() => {
|
||||
chrome.setHeaderBanner(undefined);
|
||||
}
|
||||
},
|
||||
() => {
|
||||
chrome.setHeaderBanner(undefined);
|
||||
}
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
|
12
x-pack/plugins/banners/public/types.ts
Normal file
12
x-pack/plugins/banners/public/types.ts
Normal file
|
@ -0,0 +1,12 @@
|
|||
/*
|
||||
* 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 type { ScreenshotModePluginStart } from '../../../../src/plugins/screenshot_mode/public';
|
||||
|
||||
export interface BannerPluginStartDependencies {
|
||||
screenshotMode: ScreenshotModePluginStart;
|
||||
}
|
|
@ -6,16 +6,11 @@
|
|||
"declaration": true,
|
||||
"declarationMap": true
|
||||
},
|
||||
"include": [
|
||||
"public/**/*",
|
||||
"server/**/*",
|
||||
"common/**/*",
|
||||
"../../../typings/**/*"
|
||||
],
|
||||
"include": ["public/**/*", "server/**/*", "common/**/*", "../../../typings/**/*"],
|
||||
"references": [
|
||||
{ "path": "../../../src/core/tsconfig.json" },
|
||||
{ "path": "../../../src/plugins/kibana_react/tsconfig.json" },
|
||||
{ "path": "../../../src/plugins/screenshot_mode/tsconfig.json" },
|
||||
{ "path": "../licensing/tsconfig.json" }
|
||||
]
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue