kibana/x-pack/plugins/global_search/common/process_result.test.ts
Pierre Gayvallet 29c0acfb2f
Add globalSearch x-pack plugin (#66293) (#68259)
* add skeleton for global_search plugin

* base implementation of the server-side service

* add utils tests

* add server-side mocks

* move take_in_array to common folder

* implements base of client-side plugin

* add tests for server-side service

* fix server plugin tests

* implement `navigateToUrl` core API

* extract processResults for the client-side

* fetch server results from the client side

* factorize process_results

* fix plugin start params

* move things around

* move all server types to single file

* fix types imports

* add basic FTR tests

* add client-side service tests

* add tests for addNavigate

* add getDefaultPreference & tests

* use optional for RequestHandlerContext

* add registerRoutes test

* add base test for context

* resolve TODO

* common nits/doc

* common nits/doc on public

* update CODEOWNERS

* add import for declare statement

* add license check on the server-side

* add license check on the client-side

* eslint

* address some review comments

* use properly typed errors for obs

* add integration tests for the find endpoint

* fix unit tests

* use licensing start contract

* translate the error message

* fix eslint rule for test_utils

* fix test_utils imports

* remove NavigableGlobalSearchResult, use `application.navigateToUrl` instead.

* use coreProvider plugin in FTR tests

* nits

* fix service start params

* fix service start params, bis

* I really need to fix this typecheck oom error

* add README, update missing jsdoc

* nits on doc
# Conflicts:
#	.github/CODEOWNERS
#	rfcs/text/0011_global_search.md
2020-06-04 19:12:06 +02:00

73 lines
2 KiB
TypeScript

/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { convertResultUrlMock } from './process_result.test.mocks';
import { IBasePath } from './utils';
import { GlobalSearchProviderResult } from './types';
import { processProviderResult } from './process_result';
const createResult = (parts: Partial<GlobalSearchProviderResult>): GlobalSearchProviderResult => ({
id: 'id',
title: 'title',
type: 'type',
icon: 'icon',
url: '/foo/bar',
score: 42,
meta: { foo: 'bar' },
...parts,
});
describe('processProviderResult', () => {
let basePath: jest.Mocked<IBasePath>;
beforeEach(() => {
basePath = {
prepend: jest.fn(),
};
convertResultUrlMock.mockClear();
});
it('returns all properties unchanged except `url`', () => {
const r1 = createResult({
id: '1',
type: 'test',
url: '/url-1',
title: 'title 1',
icon: 'foo',
score: 69,
meta: { hello: 'dolly' },
});
expect(processProviderResult(r1, basePath)).toEqual({
...r1,
url: expect.any(String),
});
});
it('converts the url using `convertResultUrl`', () => {
const r1 = createResult({ id: '1', url: '/url-1' });
const r2 = createResult({ id: '2', url: '/url-2' });
convertResultUrlMock.mockReturnValueOnce('/url-A');
convertResultUrlMock.mockReturnValueOnce('/url-B');
expect(convertResultUrlMock).not.toHaveBeenCalled();
const g1 = processProviderResult(r1, basePath);
expect(g1.url).toEqual('/url-A');
expect(convertResultUrlMock).toHaveBeenCalledTimes(1);
expect(convertResultUrlMock).toHaveBeenCalledWith(r1.url, basePath);
const g2 = processProviderResult(r2, basePath);
expect(g2.url).toEqual('/url-B');
expect(convertResultUrlMock).toHaveBeenCalledTimes(2);
expect(convertResultUrlMock).toHaveBeenCalledWith(r2.url, basePath);
});
});