-
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.
Browse files
Browse the repository at this point in the history
…203142) # Backport This will backport the following commits from `main` to `8.17`: - [[Search] [Onboarding] Update example data for index (#201983)](#201983) <!--- Backport version: 8.9.8 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Yan Savitski","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-12-04T11:34:30Z","message":"[Search] [Onboarding] Update example data for index (#201983)\n\nImprove generated vector db data in the index\r\nUse: \r\n- Ironman\r\n- Batman\r\n- Black Widow\r\n\r\n\r\n<img width=\"1178\" alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/c47bada6-551e-4eef-9409-3041c2f7f9dd\">\r\n<img width=\"1178\" alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/112b558d-5fa1-4c61-a40d-993e344d3a9c\">\r\n\r\n---------\r\n\r\nCo-authored-by: Elastic Machine <[email protected]>","sha":"140f80d5338fdeb537dd6e2e7866470311db1de2","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport missing","v9.0.0","Team:Search","backport:prev-minor"],"number":201983,"url":"https://github.com/elastic/kibana/pull/201983","mergeCommit":{"message":"[Search] [Onboarding] Update example data for index (#201983)\n\nImprove generated vector db data in the index\r\nUse: \r\n- Ironman\r\n- Batman\r\n- Black Widow\r\n\r\n\r\n<img width=\"1178\" alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/c47bada6-551e-4eef-9409-3041c2f7f9dd\">\r\n<img width=\"1178\" alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/112b558d-5fa1-4c61-a40d-993e344d3a9c\">\r\n\r\n---------\r\n\r\nCo-authored-by: Elastic Machine <[email protected]>","sha":"140f80d5338fdeb537dd6e2e7866470311db1de2"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","labelRegex":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/201983","number":201983,"mergeCommit":{"message":"[Search] [Onboarding] Update example data for index (#201983)\n\nImprove generated vector db data in the index\r\nUse: \r\n- Ironman\r\n- Batman\r\n- Black Widow\r\n\r\n\r\n<img width=\"1178\" alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/c47bada6-551e-4eef-9409-3041c2f7f9dd\">\r\n<img width=\"1178\" alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/112b558d-5fa1-4c61-a40d-993e344d3a9c\">\r\n\r\n---------\r\n\r\nCo-authored-by: Elastic Machine <[email protected]>","sha":"140f80d5338fdeb537dd6e2e7866470311db1de2"}}]}] BACKPORT-->
- Loading branch information
1 parent
5e0cdb1
commit f25fa79
Showing
3 changed files
with
181 additions
and
5 deletions.
There are no files selected for viewing
132 changes: 132 additions & 0 deletions
132
...gins/search_indices/public/components/index_documents/add_documents_code_example.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,132 @@ | ||
/* | ||
* 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 { render } from '@testing-library/react'; | ||
import { | ||
AddDocumentsCodeExample, | ||
basicExampleTexts, | ||
exampleTextsWithCustomMapping, | ||
} from './add_documents_code_example'; | ||
import { generateSampleDocument } from '../../utils/document_generation'; | ||
import { MappingProperty } from '@elastic/elasticsearch/lib/api/types'; | ||
|
||
jest.mock('../../utils/language', () => ({ | ||
getDefaultCodingLanguage: jest.fn().mockReturnValue('python'), | ||
})); | ||
|
||
jest.mock('../../hooks/use_asset_base_path', () => ({ | ||
useAssetBasePath: jest.fn().mockReturnValue('/plugins/'), | ||
})); | ||
|
||
jest.mock('../../utils/document_generation', () => ({ | ||
generateSampleDocument: jest.fn(), | ||
})); | ||
|
||
jest.mock('../../hooks/use_elasticsearch_url', () => ({ | ||
useElasticsearchUrl: jest.fn(), | ||
})); | ||
|
||
jest.mock('@kbn/search-api-keys-components', () => ({ | ||
useSearchApiKey: jest.fn().mockReturnValue({ apiKey: 'test-api-key' }), | ||
})); | ||
|
||
jest.mock('../../hooks/use_kibana', () => ({ | ||
useKibana: jest.fn().mockReturnValue({ | ||
services: { | ||
application: {}, | ||
share: {}, | ||
console: {}, | ||
}, | ||
}), | ||
})); | ||
|
||
jest.mock('../../contexts/usage_tracker_context', () => ({ | ||
useUsageTracker: jest.fn().mockReturnValue({ | ||
count: jest.fn(), | ||
click: jest.fn(), | ||
}), | ||
})); | ||
|
||
describe('AddDocumentsCodeExample', () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
describe('generateSampleDocument', () => { | ||
it('pass basic examples when mapping is default', () => { | ||
const indexName = 'test-index'; | ||
const mappingProperties: Record<string, MappingProperty> = { | ||
vector: { type: 'dense_vector', dims: 3 }, | ||
text: { type: 'text' }, | ||
}; | ||
|
||
render( | ||
<AddDocumentsCodeExample indexName={indexName} mappingProperties={mappingProperties} /> | ||
); | ||
|
||
expect(generateSampleDocument).toHaveBeenCalledTimes(3); | ||
|
||
basicExampleTexts.forEach((text, index) => { | ||
expect(generateSampleDocument).toHaveBeenNthCalledWith(index + 1, mappingProperties, text); | ||
}); | ||
}); | ||
|
||
it('pass basic examples when mapping is not passed', () => { | ||
const indexName = 'test-index'; | ||
|
||
render(<AddDocumentsCodeExample indexName={indexName} mappingProperties={{}} />); | ||
|
||
expect(generateSampleDocument).toHaveBeenCalledTimes(3); | ||
|
||
const mappingProperties: Record<string, MappingProperty> = { | ||
vector: { type: 'dense_vector', dims: 3 }, | ||
text: { type: 'text' }, | ||
}; | ||
|
||
basicExampleTexts.forEach((text, index) => { | ||
expect(generateSampleDocument).toHaveBeenNthCalledWith(index + 1, mappingProperties, text); | ||
}); | ||
}); | ||
|
||
it('pass basic examples when mapping is default with extra vector fields', () => { | ||
const indexName = 'test-index'; | ||
const mappingProperties: Record<string, MappingProperty> = { | ||
vector: { type: 'dense_vector', dims: 3, similarity: 'extra' }, | ||
text: { type: 'text' }, | ||
}; | ||
|
||
render( | ||
<AddDocumentsCodeExample indexName={indexName} mappingProperties={mappingProperties} /> | ||
); | ||
|
||
expect(generateSampleDocument).toHaveBeenCalledTimes(3); | ||
|
||
basicExampleTexts.forEach((text, index) => { | ||
expect(generateSampleDocument).toHaveBeenNthCalledWith(index + 1, mappingProperties, text); | ||
}); | ||
}); | ||
|
||
it('pass examples text when mapping is custom', () => { | ||
const indexName = 'test-index'; | ||
const mappingProperties: Record<string, MappingProperty> = { | ||
text: { type: 'text' }, | ||
test: { type: 'boolean' }, | ||
}; | ||
|
||
render( | ||
<AddDocumentsCodeExample indexName={indexName} mappingProperties={mappingProperties} /> | ||
); | ||
|
||
expect(generateSampleDocument).toHaveBeenCalledTimes(3); | ||
|
||
exampleTextsWithCustomMapping.forEach((text, index) => { | ||
expect(generateSampleDocument).toHaveBeenNthCalledWith(index + 1, mappingProperties, text); | ||
}); | ||
}); | ||
}); | ||
}); |
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