Skip to content

Commit

Permalink
Allow chromeless applications to hide left navbar link (#50060)
Browse files Browse the repository at this point in the history
  • Loading branch information
eliperelman authored Nov 14, 2019
1 parent 0af6ea3 commit e44616e
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 32 deletions.
76 changes: 57 additions & 19 deletions src/core/public/chrome/nav_links/nav_links_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,34 @@

import { NavLinksService } from './nav_links_service';
import { take, map, takeLast } from 'rxjs/operators';
import { LegacyApp } from '../../application';
import { App, LegacyApp } from '../../application';

const mockAppService = {
availableApps: new Map(),
availableLegacyApps: new Map<string, LegacyApp>([
[
'legacyApp1',
{ id: 'legacyApp1', order: 0, title: 'Legacy App 1', icon: 'legacyApp1', appUrl: '/app1' },
],
[
'legacyApp2',
availableApps: new Map<string, App>(
([
{ id: 'app1', order: 0, title: 'App 1', icon: 'app1' },
{
id: 'legacyApp2',
id: 'app2',
order: -10,
title: 'App 2',
euiIconType: 'canvasApp',
},
{ id: 'chromelessApp', order: 20, title: 'Chromless App', chromeless: true },
] as App[]).map(app => [app.id, app])
),
availableLegacyApps: new Map<string, LegacyApp>(
([
{ id: 'legacyApp1', order: 5, title: 'Legacy App 1', icon: 'legacyApp1', appUrl: '/app1' },
{
id: 'legacyApp2',
order: -5,
title: 'Legacy App 2',
euiIconType: 'canvasApp',
appUrl: '/app2',
},
],
['legacyApp3', { id: 'legacyApp3', order: 20, title: 'Legacy App 3', appUrl: '/app3' }],
]),
{ id: 'legacyApp3', order: 15, title: 'Legacy App 3', appUrl: '/app3' },
] as LegacyApp[]).map(app => [app.id, app])
),
} as any;

const mockHttp = {
Expand All @@ -58,6 +65,18 @@ describe('NavLinksService', () => {
});

describe('#getNavLinks$()', () => {
it('does not include `chromeless` applications', async () => {
expect(
await start
.getNavLinks$()
.pipe(
take(1),
map(links => links.map(l => l.id))
)
.toPromise()
).not.toContain('chromelessApp');
});

it('sorts navlinks by `order` property', async () => {
expect(
await start
Expand All @@ -67,7 +86,7 @@ describe('NavLinksService', () => {
map(links => links.map(l => l.id))
)
.toPromise()
).toEqual(['legacyApp2', 'legacyApp1', 'legacyApp3']);
).toEqual(['app2', 'legacyApp2', 'app1', 'legacyApp1', 'legacyApp3']);
});

it('emits multiple values', async () => {
Expand All @@ -78,8 +97,8 @@ describe('NavLinksService', () => {

service.stop();
expect(emittedLinks).toEqual([
['legacyApp2', 'legacyApp1', 'legacyApp3'],
['legacyApp2', 'legacyApp1', 'legacyApp3'],
['app2', 'legacyApp2', 'app1', 'legacyApp1', 'legacyApp3'],
['app2', 'legacyApp2', 'app1', 'legacyApp1', 'legacyApp3'],
]);
});

Expand All @@ -105,7 +124,13 @@ describe('NavLinksService', () => {

describe('#getAll()', () => {
it('returns a sorted array of navlinks', () => {
expect(start.getAll().map(l => l.id)).toEqual(['legacyApp2', 'legacyApp1', 'legacyApp3']);
expect(start.getAll().map(l => l.id)).toEqual([
'app2',
'legacyApp2',
'app1',
'legacyApp1',
'legacyApp3',
]);
});
});

Expand All @@ -130,7 +155,20 @@ describe('NavLinksService', () => {
map(links => links.map(l => l.id))
)
.toPromise()
).toEqual(['legacyApp2', 'legacyApp1', 'legacyApp3']);
).toEqual(['app2', 'legacyApp2', 'app1', 'legacyApp1', 'legacyApp3']);
});

it('does nothing on chromeless applications', async () => {
start.showOnly('chromelessApp');
expect(
await start
.getNavLinks$()
.pipe(
take(1),
map(links => links.map(l => l.id))
)
.toPromise()
).toEqual(['app2', 'legacyApp2', 'app1', 'legacyApp1', 'legacyApp3']);
});

it('removes all other links', async () => {
Expand All @@ -157,7 +195,7 @@ describe('NavLinksService', () => {
"icon": "legacyApp1",
"id": "legacyApp1",
"legacy": true,
"order": 0,
"order": 5,
"title": "Legacy App 1",
}
`);
Expand Down
24 changes: 13 additions & 11 deletions src/core/public/chrome/nav_links/nav_links_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,19 @@ export class NavLinksService {
private readonly stop$ = new ReplaySubject(1);

public start({ application, http }: StartDeps): ChromeNavLinks {
const appLinks = [...application.availableApps].map(
([appId, app]) =>
[
appId,
new NavLinkWrapper({
...app,
legacy: false,
baseUrl: relativeToAbsolute(http.basePath.prepend(`/app/${appId}`)),
}),
] as [string, NavLinkWrapper]
);
const appLinks = [...application.availableApps]
.filter(([, app]) => !app.chromeless)
.map(
([appId, app]) =>
[
appId,
new NavLinkWrapper({
...app,
legacy: false,
baseUrl: relativeToAbsolute(http.basePath.prepend(`/app/${appId}`)),
}),
] as [string, NavLinkWrapper]
);

const legacyAppLinks = [...application.availableLegacyApps].map(
([appId, app]) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,18 @@ export default function({ getService, getPageObjects }: PluginFunctionalProvider
await testSubjects.existOrFail('fooAppPageA');
});

it('chromeless applications are not visible in apps list', async () => {
expect(await appsMenu.linkExists('Chromeless')).to.be(false);
});

it('navigating to chromeless application hides chrome', async () => {
await appsMenu.clickLink('Chromeless');
await PageObjects.common.navigateToApp('chromeless');
await loadingScreenNotShown();
expect(await testSubjects.exists('headerGlobalNav')).to.be(false);
});

it('navigating away from chromeless application shows chrome', async () => {
await browser.goBack();
await PageObjects.common.navigateToApp('foo');
await loadingScreenNotShown();
expect(await testSubjects.exists('headerGlobalNav')).to.be(true);
});
Expand Down

0 comments on commit e44616e

Please sign in to comment.