-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[App Search] Synonyms set up (#97187)
* Add barebones Synonyms view * Update Synonyms route+nav link * Add server API routes - will be used in upcoming PRs, may change Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
- Loading branch information
1 parent
08b5f0d
commit 283e2ca
Showing
8 changed files
with
358 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ | |
*/ | ||
|
||
export { SYNONYMS_TITLE } from './constants'; | ||
export { Synonyms } from './synonyms'; |
21 changes: 21 additions & 0 deletions
21
...ns/enterprise_search/public/applications/app_search/components/synonyms/synonyms.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import '../../__mocks__/engine_logic.mock'; | ||
|
||
import React from 'react'; | ||
|
||
import { shallow } from 'enzyme'; | ||
|
||
import { Synonyms } from './'; | ||
|
||
describe('Synonyms', () => { | ||
it('renders', () => { | ||
shallow(<Synonyms />); | ||
// TODO: Check for Synonym cards, Synonym modal | ||
}); | ||
}); |
27 changes: 27 additions & 0 deletions
27
...plugins/enterprise_search/public/applications/app_search/components/synonyms/synonyms.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
|
||
import { EuiPageHeader, EuiPageContentBody } from '@elastic/eui'; | ||
|
||
import { FlashMessages } from '../../../shared/flash_messages'; | ||
import { SetAppSearchChrome as SetPageChrome } from '../../../shared/kibana_chrome'; | ||
import { getEngineBreadcrumbs } from '../engine'; | ||
|
||
import { SYNONYMS_TITLE } from './constants'; | ||
|
||
export const Synonyms: React.FC = () => { | ||
return ( | ||
<> | ||
<SetPageChrome trail={getEngineBreadcrumbs([SYNONYMS_TITLE])} /> | ||
<EuiPageHeader pageTitle={SYNONYMS_TITLE} /> | ||
<FlashMessages /> | ||
<EuiPageContentBody>TODO</EuiPageContentBody> | ||
</> | ||
); | ||
}; |
207 changes: 207 additions & 0 deletions
207
x-pack/plugins/enterprise_search/server/routes/app_search/synonyms.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,207 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { MockRouter, mockRequestHandler, mockDependencies } from '../../__mocks__'; | ||
|
||
import { registerSynonymsRoutes } from './synonyms'; | ||
|
||
describe('synonyms routes', () => { | ||
describe('GET /api/app_search/engines/{engineName}/synonyms', () => { | ||
let mockRouter: MockRouter; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
mockRouter = new MockRouter({ | ||
method: 'get', | ||
path: '/api/app_search/engines/{engineName}/synonyms', | ||
}); | ||
|
||
registerSynonymsRoutes({ | ||
...mockDependencies, | ||
router: mockRouter.router, | ||
}); | ||
}); | ||
|
||
it('creates a request handler', () => { | ||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({ | ||
path: '/as/engines/:engineName/synonyms/collection', | ||
}); | ||
}); | ||
|
||
describe('validates', () => { | ||
it('with pagination query params', () => { | ||
const request = { | ||
query: { | ||
'page[current]': 1, | ||
'page[size]': 10, | ||
}, | ||
}; | ||
mockRouter.shouldValidate(request); | ||
}); | ||
|
||
it('missing query params', () => { | ||
const request = { query: {} }; | ||
mockRouter.shouldThrow(request); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('POST /api/app_search/engines/{engineName}/synonyms', () => { | ||
let mockRouter: MockRouter; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
mockRouter = new MockRouter({ | ||
method: 'post', | ||
path: '/api/app_search/engines/{engineName}/synonyms', | ||
}); | ||
|
||
registerSynonymsRoutes({ | ||
...mockDependencies, | ||
router: mockRouter.router, | ||
}); | ||
}); | ||
|
||
it('creates a request handler', () => { | ||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({ | ||
path: '/as/engines/:engineName/synonyms/collection', | ||
}); | ||
}); | ||
|
||
describe('validates', () => { | ||
it('with synonyms', () => { | ||
const request = { | ||
body: { | ||
synonyms: ['a', 'b', 'c'], | ||
}, | ||
}; | ||
mockRouter.shouldValidate(request); | ||
}); | ||
|
||
it('empty synonyms array', () => { | ||
const request = { | ||
body: { | ||
queries: [], | ||
}, | ||
}; | ||
mockRouter.shouldThrow(request); | ||
}); | ||
|
||
it('only one synonym', () => { | ||
const request = { | ||
body: { | ||
queries: ['a'], | ||
}, | ||
}; | ||
mockRouter.shouldThrow(request); | ||
}); | ||
|
||
it('empty synonym strings', () => { | ||
const request = { | ||
body: { | ||
queries: ['', '', ''], | ||
}, | ||
}; | ||
mockRouter.shouldThrow(request); | ||
}); | ||
|
||
it('missing synonyms', () => { | ||
const request = { body: {} }; | ||
mockRouter.shouldThrow(request); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('PUT /api/app_search/engines/{engineName}/synonyms/{synonymId}', () => { | ||
let mockRouter: MockRouter; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
mockRouter = new MockRouter({ | ||
method: 'put', | ||
path: '/api/app_search/engines/{engineName}/synonyms/{synonymId}', | ||
}); | ||
|
||
registerSynonymsRoutes({ | ||
...mockDependencies, | ||
router: mockRouter.router, | ||
}); | ||
}); | ||
|
||
it('creates a request handler', () => { | ||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({ | ||
path: '/as/engines/:engineName/synonyms/:synonymId', | ||
}); | ||
}); | ||
|
||
describe('validates', () => { | ||
it('with synonyms', () => { | ||
const request = { | ||
body: { | ||
synonyms: ['a', 'b', 'c'], | ||
}, | ||
}; | ||
mockRouter.shouldValidate(request); | ||
}); | ||
|
||
it('empty synonyms array', () => { | ||
const request = { | ||
body: { | ||
queries: [], | ||
}, | ||
}; | ||
mockRouter.shouldThrow(request); | ||
}); | ||
|
||
it('only one synonym', () => { | ||
const request = { | ||
body: { | ||
queries: ['a'], | ||
}, | ||
}; | ||
mockRouter.shouldThrow(request); | ||
}); | ||
|
||
it('empty synonym strings', () => { | ||
const request = { | ||
body: { | ||
queries: ['', '', ''], | ||
}, | ||
}; | ||
mockRouter.shouldThrow(request); | ||
}); | ||
|
||
it('missing synonyms', () => { | ||
const request = { body: {} }; | ||
mockRouter.shouldThrow(request); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('DELETE /api/app_search/engines/{engineName}/synonyms/{synonymId}', () => { | ||
let mockRouter: MockRouter; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
mockRouter = new MockRouter({ | ||
method: 'delete', | ||
path: '/api/app_search/engines/{engineName}/synonyms/{synonymId}', | ||
}); | ||
|
||
registerSynonymsRoutes({ | ||
...mockDependencies, | ||
router: mockRouter.router, | ||
}); | ||
}); | ||
|
||
it('creates a request handler', () => { | ||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({ | ||
path: '/as/engines/:engineName/synonyms/:synonymId', | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.