add category related meta to application results (#77618)

This commit is contained in:
Pierre Gayvallet 2020-09-16 20:01:19 +02:00 committed by GitHub
parent 04a5a4c0ca
commit 33f6025add
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 1 deletions

View file

@ -4,7 +4,12 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { AppNavLinkStatus, AppStatus, PublicAppInfo } from 'src/core/public';
import {
AppNavLinkStatus,
AppStatus,
PublicAppInfo,
DEFAULT_APP_CATEGORIES,
} from 'src/core/public';
import { appToResult, getAppResults, scoreApp } from './get_app_results';
const createApp = (props: Partial<PublicAppInfo> = {}): PublicAppInfo => ({
@ -70,6 +75,7 @@ describe('appToResult', () => {
title: 'Foo',
euiIconType: 'fooIcon',
appRoute: '/app/foo',
category: DEFAULT_APP_CATEGORIES.security,
});
expect(appToResult(app, 42)).toEqual({
id: 'foo',
@ -77,6 +83,31 @@ describe('appToResult', () => {
type: 'application',
icon: 'fooIcon',
url: '/app/foo',
meta: {
categoryId: DEFAULT_APP_CATEGORIES.security.id,
categoryLabel: DEFAULT_APP_CATEGORIES.security.label,
},
score: 42,
});
});
it('converts an app without category to a result', () => {
const app = createApp({
id: 'foo',
title: 'Foo',
euiIconType: 'fooIcon',
appRoute: '/app/foo',
});
expect(appToResult(app, 42)).toEqual({
id: 'foo',
title: 'Foo',
type: 'application',
icon: 'fooIcon',
url: '/app/foo',
meta: {
categoryId: null,
categoryLabel: null,
},
score: 42,
});
});

View file

@ -50,6 +50,10 @@ export const appToResult = (app: PublicAppInfo, score: number): GlobalSearchProv
type: 'application',
icon: app.euiIconType,
url: app.appRoute,
meta: {
categoryId: app.category?.id ?? null,
categoryLabel: app.category?.label ?? null,
},
score,
};
};