Skip to content

Commit

Permalink
exclude apps with non visible navlinks from results
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet committed Aug 17, 2020
1 parent a987cef commit 436a28a
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 11 deletions.
39 changes: 33 additions & 6 deletions src/core/public/application/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
*/

import { of } from 'rxjs';
import { LegacyApp, App, AppStatus, AppNavLinkStatus } from './types';
import { App, AppNavLinkStatus, AppStatus, LegacyApp } from './types';
import { BasePath } from '../http/base_path';
import {
removeSlashes,
appendAppPath,
getAppInfo,
isLegacyApp,
relativeToAbsolute,
parseAppUrl,
getAppInfo,
relativeToAbsolute,
removeSlashes,
} from './utils';

describe('removeSlashes', () => {
Expand Down Expand Up @@ -494,7 +494,7 @@ describe('getAppInfo', () => {
id: 'some-id',
title: 'some-title',
status: AppStatus.accessible,
navLinkStatus: AppNavLinkStatus.default,
navLinkStatus: AppNavLinkStatus.visible,
appRoute: `/app/some-id`,
legacy: false,
});
Expand All @@ -509,8 +509,35 @@ describe('getAppInfo', () => {
id: 'some-id',
title: 'some-title',
status: AppStatus.accessible,
navLinkStatus: AppNavLinkStatus.default,
navLinkStatus: AppNavLinkStatus.visible,
legacy: true,
});
});

it('computes the navLinkStatus depending on the app status', () => {
expect(
getAppInfo(
createApp({
navLinkStatus: AppNavLinkStatus.default,
status: AppStatus.inaccessible,
})
)
).toEqual(
expect.objectContaining({
navLinkStatus: AppNavLinkStatus.hidden,
})
);
expect(
getAppInfo(
createApp({
navLinkStatus: AppNavLinkStatus.default,
status: AppStatus.accessible,
})
)
).toEqual(
expect.objectContaining({
navLinkStatus: AppNavLinkStatus.visible,
})
);
});
});
20 changes: 17 additions & 3 deletions src/core/public/application/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@
*/

import { IBasePath } from '../http';
import { App, LegacyApp, PublicAppInfo, PublicLegacyAppInfo, ParsedAppUrl } from './types';
import {
App,
AppNavLinkStatus,
AppStatus,
LegacyApp,
ParsedAppUrl,
PublicAppInfo,
PublicLegacyAppInfo,
} from './types';

/**
* Utility to remove trailing, leading or duplicate slashes.
Expand Down Expand Up @@ -116,20 +124,26 @@ const removeBasePath = (url: string, basePath: IBasePath, origin: string): strin
};

export function getAppInfo(app: App<unknown> | LegacyApp): PublicAppInfo | PublicLegacyAppInfo {
const navLinkStatus =
app.navLinkStatus === AppNavLinkStatus.default
? app.status === AppStatus.inaccessible
? AppNavLinkStatus.hidden
: AppNavLinkStatus.visible
: app.navLinkStatus!;
if (isLegacyApp(app)) {
const { updater$, ...infos } = app;
return {
...infos,
status: app.status!,
navLinkStatus: app.navLinkStatus!,
navLinkStatus,
legacy: true,
};
} else {
const { updater$, mount, ...infos } = app;
return {
...infos,
status: app.status!,
navLinkStatus: app.navLinkStatus!,
navLinkStatus,
appRoute: app.appRoute!,
legacy: false,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { getAppResultsMock } from './application.test.mocks';

import { of, EMPTY } from 'rxjs';
import { EMPTY, of } from 'rxjs';
import { TestScheduler } from 'rxjs/testing';
import { ApplicationStart, AppNavLinkStatus, AppStatus, PublicAppInfo } from 'src/core/public';
import {
Expand Down Expand Up @@ -100,6 +100,20 @@ describe('applicationResultProvider', () => {
expect(getAppResultsMock).toHaveBeenCalledWith('term', [expectApp('app1')]);
});

it('ignores apps with non-visible navlink', async () => {
application.applications$ = of(
createAppMap([
createApp({ id: 'app1', title: 'App 1', navLinkStatus: AppNavLinkStatus.visible }),
createApp({ id: 'disabled', title: 'disabled', navLinkStatus: AppNavLinkStatus.disabled }),
createApp({ id: 'hidden', title: 'hidden', navLinkStatus: AppNavLinkStatus.hidden }),
])
);
const provider = createApplicationResultProvider(Promise.resolve(application));
await provider.find('term', defaultOption).toPromise();

expect(getAppResultsMock).toHaveBeenCalledWith('term', [expectApp('app1')]);
});

it('ignores chromeless apps', async () => {
application.applications$ = of(
createAppMap([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export const createApplicationResultProvider = (
mergeMap((application) => application.applications$),
map((apps) =>
[...apps.values()].filter(
(app) => app.status === 0 && (app.legacy === true || app.chromeless !== true)
// only include non-chromeless enabled apps with visible navLinks
(app) => app.status === 0 && app.navLinkStatus === 1 && app.chromeless !== true
)
),
shareReplay(1)
Expand Down

0 comments on commit 436a28a

Please sign in to comment.