Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

workflow_detail tests #6

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions public/pages/workflow_detail/workflow_detail.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions public/pages/workflows/new_workflow/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function enrichPresetWorkflowWithUiMetadata(
} as WorkflowTemplate;
}

function fetchEmptyMetadata(): UIState {
export function fetchEmptyMetadata(): UIState {
return {
type: WORKFLOW_TYPE.CUSTOM,
config: {
Expand Down Expand Up @@ -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()];
Expand All @@ -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()];
Expand All @@ -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()];
Expand Down
246 changes: 28 additions & 218 deletions test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(() => ({
Expand Down
Loading