From b34a87842743cbcf498535f9747c45cdc3f2ac39 Mon Sep 17 00:00:00 2001 From: saimedhi Date: Fri, 6 Sep 2024 10:51:47 -0700 Subject: [PATCH] workflow_detail tests Signed-off-by: saimedhi --- .../workflow_detail/workflow_detail.test.tsx | 8 +- public/pages/workflows/new_workflow/utils.ts | 8 +- test/utils.ts | 246 ++---------------- 3 files changed, 33 insertions(+), 229 deletions(-) diff --git a/public/pages/workflow_detail/workflow_detail.test.tsx b/public/pages/workflow_detail/workflow_detail.test.tsx index 3e8f06f1..a023b678 100644 --- a/public/pages/workflow_detail/workflow_detail.test.tsx +++ b/public/pages/workflow_detail/workflow_detail.test.tsx @@ -57,13 +57,7 @@ const workflowId = '12345'; const workflowName = 'test_workflow'; describe('WorkflowDetail', () => { - const workflowTypes = [ - WORKFLOW_TYPE.CUSTOM, - WORKFLOW_TYPE.SEMANTIC_SEARCH, - WORKFLOW_TYPE.HYBRID_SEARCH, - ]; - - workflowTypes.forEach((type) => { + Object.values(WORKFLOW_TYPE).forEach((type) => { test(`renders the page with ${type} type`, () => { const { getAllByText, getByText, getByRole } = renderWithRouter( workflowId, diff --git a/public/pages/workflows/new_workflow/utils.ts b/public/pages/workflows/new_workflow/utils.ts index 8988c739..f6dbb4e6 100644 --- a/public/pages/workflows/new_workflow/utils.ts +++ b/public/pages/workflows/new_workflow/utils.ts @@ -60,7 +60,7 @@ export function enrichPresetWorkflowWithUiMetadata( } as WorkflowTemplate; } -function fetchEmptyMetadata(): UIState { +export function fetchEmptyMetadata(): UIState { return { type: WORKFLOW_TYPE.CUSTOM, config: { @@ -125,7 +125,7 @@ function fetchEmptyMetadata(): UIState { }; } -function fetchSemanticSearchMetadata(): UIState { +export function fetchSemanticSearchMetadata(): UIState { let baseState = fetchEmptyMetadata(); baseState.type = WORKFLOW_TYPE.SEMANTIC_SEARCH; baseState.config.ingest.enrich.processors = [new MLIngestProcessor().toObj()]; @@ -143,7 +143,7 @@ function fetchSemanticSearchMetadata(): UIState { return baseState; } -function fetchMultimodalSearchMetadata(): UIState { +export function fetchMultimodalSearchMetadata(): UIState { let baseState = fetchEmptyMetadata(); baseState.type = WORKFLOW_TYPE.MULTIMODAL_SEARCH; baseState.config.ingest.enrich.processors = [new MLIngestProcessor().toObj()]; @@ -163,7 +163,7 @@ function fetchMultimodalSearchMetadata(): UIState { return baseState; } -function fetchHybridSearchMetadata(): UIState { +export function fetchHybridSearchMetadata(): UIState { let baseState = fetchEmptyMetadata(); baseState.type = WORKFLOW_TYPE.HYBRID_SEARCH; baseState.config.ingest.enrich.processors = [new MLIngestProcessor().toObj()]; diff --git a/test/utils.ts b/test/utils.ts index 8a51fa2a..c0d053c4 100644 --- a/test/utils.ts +++ b/test/utils.ts @@ -3,12 +3,14 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { PROCESSOR_TYPE, WORKFLOW_TYPE } from '../common/constants'; +import { WORKFLOW_TYPE } from '../common/constants'; +import { UIState, Workflow } from '../common/interfaces'; import { - IProcessorConfig, - ProcessorsConfig, - Workflow, -} from '../common/interfaces'; + fetchEmptyMetadata, + fetchHybridSearchMetadata, + fetchMultimodalSearchMetadata, + fetchSemanticSearchMetadata, +} from '../public/pages/workflows/new_workflow/utils'; export function mockStore( workflowId: string, @@ -49,222 +51,30 @@ function generateWorkflow( id: workflowId, name: workflowName, version: { template: '1.0.0', compatibility: ['2.17.0', '3.0.0'] }, - ui_metadata: { - type: workflowType, - config: { - search: { - pipelineName: { - id: 'pipelineName', - type: 'string', - value: 'search_pipeline', - }, - request: { - id: 'request', - type: 'json', - value: '{\n "query": {\n "match_all": {}\n },\n "size": 1000\n}', - }, - index: { name: { id: 'indexName', type: 'string' } }, - enrichRequest: getRequestProcessor(workflowType), - enrichResponse: getResponseProcessor(workflowType), - }, - ingest: { - pipelineName: { - id: 'pipelineName', - type: 'string', - value: 'ingest_pipeline', - }, - enrich: getRequestProcessor(workflowType), - index: { - settings: { id: 'indexSettings', type: 'json' }, - mappings: { - id: 'indexMappings', - type: 'json', - value: '{\n "properties": {}\n}', - }, - name: { - id: 'indexName', - type: 'string', - value: 'my-new-index', - }, - }, - enabled: { id: 'enabled', type: 'boolean', value: true }, - }, - }, - }, + ui_metadata: getConfig(workflowType), }; } - -function getRequestProcessor(workflowType: WORKFLOW_TYPE): ProcessorsConfig { - if ( - workflowType === WORKFLOW_TYPE.HYBRID_SEARCH || - workflowType === WORKFLOW_TYPE.SEMANTIC_SEARCH - ) { - // TODO: In the code below, only the ml_inference processor has been added. Other processors still need to be included. - const mlInferenceProcessor: IProcessorConfig = { - name: 'ML Inference Processor', - id: 'ml_processor_ingest', - fields: [ - { - id: 'model', - type: 'model', - value: { - id: 'dfMPE5EB8_-RPNi-S0gD', - }, - }, - { - id: 'input_map', - type: 'mapArray', - value: [ - [ - { - value: 'my_text', - key: '', - }, - ], - ], - }, - { - id: 'output_map', - type: 'mapArray', - value: [ - [ - { - value: '', - key: 'my_embedding', - }, - ], - ], - }, - ], - type: PROCESSOR_TYPE.ML, - optionalFields: [ - { - id: 'query_template', - type: 'jsonString', - value: getQueryTemplate(workflowType), - }, - { - id: 'description', - type: 'string', - }, - { - id: 'model_config', - type: 'json', - }, - { - id: 'full_response_path', - type: 'boolean', - value: false, - }, - { - id: 'ignore_missing', - type: 'boolean', - value: false, - }, - { - id: 'ignore_failure', - type: 'boolean', - value: false, - }, - { - id: 'max_prediction_tasks', - type: 'number', - value: 10, - }, - { - id: 'tag', - type: 'string', - }, - ], - }; - return { - processors: [mlInferenceProcessor], - }; - } - - return { processors: [] }; -} - -// Function to get the query template based on workflow type -function getQueryTemplate(workflowType: WORKFLOW_TYPE) { - if (workflowType === WORKFLOW_TYPE.HYBRID_SEARCH) { - return `{ - "_source": { - "excludes": ["my_embedding"] - }, - "query": { - "hybrid": { - "queries": [ - { - "match": { - "my_text": { - "query": "{{query_text}}" - } - } - }, - { - "knn": { - "my_embedding": { - "vector": jest.fn(), - "k": 10 - } - } - } - ] - } - } - }`; - } - - if (workflowType === WORKFLOW_TYPE.SEMANTIC_SEARCH) { - return `{ - "_source": { - "excludes": ["my_embedding"] - }, - "query": { - "knn": { - "my_embedding": { - "vector": jest.fn(), - "k": 10 - } - } - } - }`; +function getConfig(workflowType: WORKFLOW_TYPE) { + let uiMetadata = {} as UIState; + switch (workflowType) { + case WORKFLOW_TYPE.SEMANTIC_SEARCH: { + uiMetadata = fetchSemanticSearchMetadata(); + break; + } + case WORKFLOW_TYPE.MULTIMODAL_SEARCH: { + uiMetadata = fetchMultimodalSearchMetadata(); + break; + } + case WORKFLOW_TYPE.HYBRID_SEARCH: { + uiMetadata = fetchHybridSearchMetadata(); + break; + } + default: { + uiMetadata = fetchEmptyMetadata(); + break; + } } -} - -function getResponseProcessor(workflowType: WORKFLOW_TYPE): ProcessorsConfig { - return workflowType === WORKFLOW_TYPE.HYBRID_SEARCH - ? { - processors: [ - { - id: 'normalization_processor', - name: 'Normalization Processor', - type: PROCESSOR_TYPE.NORMALIZATION, - fields: [], - optionalFields: [ - { id: 'weights', type: 'string', value: '0.5, 0.5' }, - { - id: 'normalization_technique', - type: 'select', - selectOptions: ['min_max', 'l2'], - }, - { - id: 'combination_technique', - type: 'select', - selectOptions: [ - 'arithmetic_mean', - 'geometric_mean', - 'harmonic_mean', - ], - }, - { id: 'description', type: 'string' }, - { id: 'tag', type: 'string' }, - ], - }, - ], - } - : { processors: [] }; + return uiMetadata; } export const resizeObserverMock = jest.fn().mockImplementation(() => ({