Skip to content

Commit

Permalink
Fix banner not being displayed on login page (elastic#140688)
Browse files Browse the repository at this point in the history
* Fix banner not being displayed on login page

* fix and re-enable banner FTR tests

* revert commit to config file

* add unit test

* don't use whitespace for cli config value

Co-authored-by: Tre <wayne.seymour@elastic.co>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit b86cef5)
  • Loading branch information
pgayvallet committed Sep 20, 2022
1 parent 3e42c11 commit 3a15806
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .buildkite/ftr_configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ disabled:
- x-pack/test/alerting_api_integration/security_and_spaces/group2/tests/actions/config.ts
- x-pack/test/alerting_api_integration/security_and_spaces/group2/tests/telemetry/config.ts
- x-pack/test/alerting_api_integration/spaces_only_legacy/config.ts
- x-pack/test/banners_functional/config.ts
- x-pack/test/cloud_integration/config.ts
- x-pack/test/performance/config.playwright.ts
- x-pack/test/load/config.ts
Expand Down Expand Up @@ -125,6 +124,7 @@ enabled:
- x-pack/test/apm_api_integration/basic/config.ts
- x-pack/test/apm_api_integration/rules/config.ts
- x-pack/test/apm_api_integration/trial/config.ts
- x-pack/test/banners_functional/config.ts
- x-pack/test/cases_api_integration/security_and_spaces/config_basic.ts
- x-pack/test/cases_api_integration/security_and_spaces/config_trial.ts
- x-pack/test/cases_api_integration/spaces_only/config.ts
Expand Down
5 changes: 3 additions & 2 deletions x-pack/plugins/banners/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
"kibanaVersion": "kibana",
"server": true,
"ui": true,
"requiredPlugins": ["licensing", "screenshotMode"],
"optionalPlugins": [],
"enabledOnAnonymousPages": true,
"requiredPlugins": ["licensing"],
"optionalPlugins": ["screenshotMode"],
"requiredBundles": ["kibanaReact"],
"configPath": ["xpack", "banners"]
}
30 changes: 27 additions & 3 deletions x-pack/plugins/banners/public/plugin.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,15 @@ describe('BannersPlugin', () => {
});
});

const startPlugin = async () => {
const startPlugin = async ({
screenshotPluginPresent = true,
}: { screenshotPluginPresent?: boolean } = {}) => {
pluginInitContext = coreMock.createPluginInitializerContext();
plugin = new BannersPlugin(pluginInitContext);
plugin.setup(coreSetup);
plugin.start(coreStart, { screenshotMode: screenshotModeStart });
plugin.start(coreStart, {
screenshotMode: screenshotPluginPresent ? screenshotModeStart : undefined,
});
// await for the `getBannerInfo` promise to resolve
await nextTick();
};
Expand Down Expand Up @@ -84,12 +88,32 @@ describe('BannersPlugin', () => {
});

it('does not register the banner in screenshot mode', async () => {
getBannerInfoMock.mockResolvedValue({
allowed: true,
banner: createBannerConfig({
placement: 'top',
}),
});

screenshotModeStart.isScreenshotMode.mockReturnValue(true);

await startPlugin();

expect(coreStart.chrome.setHeaderBanner).not.toHaveBeenCalled();
});

it('registers the banner if screenshotMode plugin not present', async () => {
getBannerInfoMock.mockResolvedValue({
allowed: true,
banner: createBannerConfig({
placement: 'top',
}),
});

await startPlugin({ screenshotPluginPresent: false });

expect(coreStart.chrome.setHeaderBanner).toHaveBeenCalled();
});
});

describe('when banner is not allowed', () => {
Expand All @@ -116,7 +140,7 @@ describe('BannersPlugin', () => {

await startPlugin();

expect(coreStart.chrome.setHeaderBanner).toHaveBeenCalledTimes(0);
expect(coreStart.chrome.setHeaderBanner).not.toHaveBeenCalled();
});

it('does not register the banner in screenshot mode', async () => {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/banners/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class BannersPlugin implements Plugin<{}, {}, {}, BannerPluginStartDepend
{ chrome, uiSettings, http }: CoreStart,
{ screenshotMode }: BannerPluginStartDependencies
) {
if (!screenshotMode.isScreenshotMode()) {
if (!(screenshotMode?.isScreenshotMode() ?? false)) {
getBannerInfo(http).then(
({ allowed, banner }) => {
if (allowed && banner.placement === 'top') {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/banners/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
import type { ScreenshotModePluginStart } from '@kbn/screenshot-mode-plugin/public';

export interface BannerPluginStartDependencies {
screenshotMode: ScreenshotModePluginStart;
screenshotMode?: ScreenshotModePluginStart;
}
2 changes: 1 addition & 1 deletion x-pack/test/banners_functional/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) {
serverArgs: [
...kibanaFunctionalConfig.get('kbnTestServer.serverArgs'),
'--xpack.banners.placement=top',
'--xpack.banners.textContent="global banner text"',
'--xpack.banners.textContent=global_banner_text',
],
},
};
Expand Down
2 changes: 1 addition & 1 deletion x-pack/test/banners_functional/tests/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function ({ getPageObjects }: FtrProviderContext) {
await PageObjects.common.navigateToApp('login');

expect(await PageObjects.banners.isTopBannerVisible()).to.eql(true);
expect(await PageObjects.banners.getTopBannerText()).to.eql('global banner text');
expect(await PageObjects.banners.getTopBannerText()).to.eql('global_banner_text');
});
});
}
20 changes: 9 additions & 11 deletions x-pack/test/banners_functional/tests/spaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { FtrProviderContext } from '../ftr_provider_context';

export default function ({ getPageObjects, getService }: FtrProviderContext) {
const esArchiver = getService('esArchiver');
const kibanaServer = getService('kibanaServer');
const PageObjects = getPageObjects([
'common',
'security',
Expand All @@ -28,18 +29,15 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
});

before(async () => {
await kibanaServer.uiSettings.replace(
{
'banners:textContent': 'default space banner text',
},
{ space: 'default' }
);
await PageObjects.security.login(undefined, undefined, {
expectSpaceSelector: true,
});
await PageObjects.spaceSelector.clickSpaceCard('default');

await PageObjects.settings.navigateTo();
await PageObjects.settings.clickKibanaSettings();

await PageObjects.settings.setAdvancedSettingsTextArea(
'banners:textContent',
'default space banner text'
);
});

it('displays the space-specific banner within the space', async () => {
Expand All @@ -53,15 +51,15 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
await PageObjects.common.navigateToApp('home', { basePath: '/s/another-space' });

expect(await PageObjects.banners.isTopBannerVisible()).to.eql(true);
expect(await PageObjects.banners.getTopBannerText()).to.eql('global banner text');
expect(await PageObjects.banners.getTopBannerText()).to.eql('global_banner_text');
});

it('displays the global banner on the login page', async () => {
await PageObjects.security.forceLogout();
await PageObjects.common.navigateToApp('login');

expect(await PageObjects.banners.isTopBannerVisible()).to.eql(true);
expect(await PageObjects.banners.getTopBannerText()).to.eql('global banner text');
expect(await PageObjects.banners.getTopBannerText()).to.eql('global_banner_text');
});
});
}

0 comments on commit 3a15806

Please sign in to comment.