Skip to content

Commit b8ed7d9

Browse files
authored
Merge pull request #6 from saimedhi/tests2_copy
workflow_detail tests
2 parents 99fb0b3 + b34a878 commit b8ed7d9

File tree

3 files changed

+33
-229
lines changed

3 files changed

+33
-229
lines changed

public/pages/workflow_detail/workflow_detail.test.tsx

+1-7
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,7 @@ const workflowId = '12345';
5757
const workflowName = 'test_workflow';
5858

5959
describe('WorkflowDetail', () => {
60-
const workflowTypes = [
61-
WORKFLOW_TYPE.CUSTOM,
62-
WORKFLOW_TYPE.SEMANTIC_SEARCH,
63-
WORKFLOW_TYPE.HYBRID_SEARCH,
64-
];
65-
66-
workflowTypes.forEach((type) => {
60+
Object.values(WORKFLOW_TYPE).forEach((type) => {
6761
test(`renders the page with ${type} type`, () => {
6862
const { getAllByText, getByText, getByRole } = renderWithRouter(
6963
workflowId,

public/pages/workflows/new_workflow/utils.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export function enrichPresetWorkflowWithUiMetadata(
6060
} as WorkflowTemplate;
6161
}
6262

63-
function fetchEmptyMetadata(): UIState {
63+
export function fetchEmptyMetadata(): UIState {
6464
return {
6565
type: WORKFLOW_TYPE.CUSTOM,
6666
config: {
@@ -125,7 +125,7 @@ function fetchEmptyMetadata(): UIState {
125125
};
126126
}
127127

128-
function fetchSemanticSearchMetadata(): UIState {
128+
export function fetchSemanticSearchMetadata(): UIState {
129129
let baseState = fetchEmptyMetadata();
130130
baseState.type = WORKFLOW_TYPE.SEMANTIC_SEARCH;
131131
baseState.config.ingest.enrich.processors = [new MLIngestProcessor().toObj()];
@@ -143,7 +143,7 @@ function fetchSemanticSearchMetadata(): UIState {
143143
return baseState;
144144
}
145145

146-
function fetchMultimodalSearchMetadata(): UIState {
146+
export function fetchMultimodalSearchMetadata(): UIState {
147147
let baseState = fetchEmptyMetadata();
148148
baseState.type = WORKFLOW_TYPE.MULTIMODAL_SEARCH;
149149
baseState.config.ingest.enrich.processors = [new MLIngestProcessor().toObj()];
@@ -163,7 +163,7 @@ function fetchMultimodalSearchMetadata(): UIState {
163163
return baseState;
164164
}
165165

166-
function fetchHybridSearchMetadata(): UIState {
166+
export function fetchHybridSearchMetadata(): UIState {
167167
let baseState = fetchEmptyMetadata();
168168
baseState.type = WORKFLOW_TYPE.HYBRID_SEARCH;
169169
baseState.config.ingest.enrich.processors = [new MLIngestProcessor().toObj()];

test/utils.ts

+28-218
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import { PROCESSOR_TYPE, WORKFLOW_TYPE } from '../common/constants';
6+
import { WORKFLOW_TYPE } from '../common/constants';
7+
import { UIState, Workflow } from '../common/interfaces';
78
import {
8-
IProcessorConfig,
9-
ProcessorsConfig,
10-
Workflow,
11-
} from '../common/interfaces';
9+
fetchEmptyMetadata,
10+
fetchHybridSearchMetadata,
11+
fetchMultimodalSearchMetadata,
12+
fetchSemanticSearchMetadata,
13+
} from '../public/pages/workflows/new_workflow/utils';
1214

1315
export function mockStore(
1416
workflowId: string,
@@ -49,222 +51,30 @@ function generateWorkflow(
4951
id: workflowId,
5052
name: workflowName,
5153
version: { template: '1.0.0', compatibility: ['2.17.0', '3.0.0'] },
52-
ui_metadata: {
53-
type: workflowType,
54-
config: {
55-
search: {
56-
pipelineName: {
57-
id: 'pipelineName',
58-
type: 'string',
59-
value: 'search_pipeline',
60-
},
61-
request: {
62-
id: 'request',
63-
type: 'json',
64-
value: '{\n "query": {\n "match_all": {}\n },\n "size": 1000\n}',
65-
},
66-
index: { name: { id: 'indexName', type: 'string' } },
67-
enrichRequest: getRequestProcessor(workflowType),
68-
enrichResponse: getResponseProcessor(workflowType),
69-
},
70-
ingest: {
71-
pipelineName: {
72-
id: 'pipelineName',
73-
type: 'string',
74-
value: 'ingest_pipeline',
75-
},
76-
enrich: getRequestProcessor(workflowType),
77-
index: {
78-
settings: { id: 'indexSettings', type: 'json' },
79-
mappings: {
80-
id: 'indexMappings',
81-
type: 'json',
82-
value: '{\n "properties": {}\n}',
83-
},
84-
name: {
85-
id: 'indexName',
86-
type: 'string',
87-
value: 'my-new-index',
88-
},
89-
},
90-
enabled: { id: 'enabled', type: 'boolean', value: true },
91-
},
92-
},
93-
},
54+
ui_metadata: getConfig(workflowType),
9455
};
9556
}
96-
97-
function getRequestProcessor(workflowType: WORKFLOW_TYPE): ProcessorsConfig {
98-
if (
99-
workflowType === WORKFLOW_TYPE.HYBRID_SEARCH ||
100-
workflowType === WORKFLOW_TYPE.SEMANTIC_SEARCH
101-
) {
102-
// TODO: In the code below, only the ml_inference processor has been added. Other processors still need to be included.
103-
const mlInferenceProcessor: IProcessorConfig = {
104-
name: 'ML Inference Processor',
105-
id: 'ml_processor_ingest',
106-
fields: [
107-
{
108-
id: 'model',
109-
type: 'model',
110-
value: {
111-
id: 'dfMPE5EB8_-RPNi-S0gD',
112-
},
113-
},
114-
{
115-
id: 'input_map',
116-
type: 'mapArray',
117-
value: [
118-
[
119-
{
120-
value: 'my_text',
121-
key: '',
122-
},
123-
],
124-
],
125-
},
126-
{
127-
id: 'output_map',
128-
type: 'mapArray',
129-
value: [
130-
[
131-
{
132-
value: '',
133-
key: 'my_embedding',
134-
},
135-
],
136-
],
137-
},
138-
],
139-
type: PROCESSOR_TYPE.ML,
140-
optionalFields: [
141-
{
142-
id: 'query_template',
143-
type: 'jsonString',
144-
value: getQueryTemplate(workflowType),
145-
},
146-
{
147-
id: 'description',
148-
type: 'string',
149-
},
150-
{
151-
id: 'model_config',
152-
type: 'json',
153-
},
154-
{
155-
id: 'full_response_path',
156-
type: 'boolean',
157-
value: false,
158-
},
159-
{
160-
id: 'ignore_missing',
161-
type: 'boolean',
162-
value: false,
163-
},
164-
{
165-
id: 'ignore_failure',
166-
type: 'boolean',
167-
value: false,
168-
},
169-
{
170-
id: 'max_prediction_tasks',
171-
type: 'number',
172-
value: 10,
173-
},
174-
{
175-
id: 'tag',
176-
type: 'string',
177-
},
178-
],
179-
};
180-
return {
181-
processors: [mlInferenceProcessor],
182-
};
183-
}
184-
185-
return { processors: [] };
186-
}
187-
188-
// Function to get the query template based on workflow type
189-
function getQueryTemplate(workflowType: WORKFLOW_TYPE) {
190-
if (workflowType === WORKFLOW_TYPE.HYBRID_SEARCH) {
191-
return `{
192-
"_source": {
193-
"excludes": ["my_embedding"]
194-
},
195-
"query": {
196-
"hybrid": {
197-
"queries": [
198-
{
199-
"match": {
200-
"my_text": {
201-
"query": "{{query_text}}"
202-
}
203-
}
204-
},
205-
{
206-
"knn": {
207-
"my_embedding": {
208-
"vector": jest.fn(),
209-
"k": 10
210-
}
211-
}
212-
}
213-
]
214-
}
215-
}
216-
}`;
217-
}
218-
219-
if (workflowType === WORKFLOW_TYPE.SEMANTIC_SEARCH) {
220-
return `{
221-
"_source": {
222-
"excludes": ["my_embedding"]
223-
},
224-
"query": {
225-
"knn": {
226-
"my_embedding": {
227-
"vector": jest.fn(),
228-
"k": 10
229-
}
230-
}
231-
}
232-
}`;
57+
function getConfig(workflowType: WORKFLOW_TYPE) {
58+
let uiMetadata = {} as UIState;
59+
switch (workflowType) {
60+
case WORKFLOW_TYPE.SEMANTIC_SEARCH: {
61+
uiMetadata = fetchSemanticSearchMetadata();
62+
break;
63+
}
64+
case WORKFLOW_TYPE.MULTIMODAL_SEARCH: {
65+
uiMetadata = fetchMultimodalSearchMetadata();
66+
break;
67+
}
68+
case WORKFLOW_TYPE.HYBRID_SEARCH: {
69+
uiMetadata = fetchHybridSearchMetadata();
70+
break;
71+
}
72+
default: {
73+
uiMetadata = fetchEmptyMetadata();
74+
break;
75+
}
23376
}
234-
}
235-
236-
function getResponseProcessor(workflowType: WORKFLOW_TYPE): ProcessorsConfig {
237-
return workflowType === WORKFLOW_TYPE.HYBRID_SEARCH
238-
? {
239-
processors: [
240-
{
241-
id: 'normalization_processor',
242-
name: 'Normalization Processor',
243-
type: PROCESSOR_TYPE.NORMALIZATION,
244-
fields: [],
245-
optionalFields: [
246-
{ id: 'weights', type: 'string', value: '0.5, 0.5' },
247-
{
248-
id: 'normalization_technique',
249-
type: 'select',
250-
selectOptions: ['min_max', 'l2'],
251-
},
252-
{
253-
id: 'combination_technique',
254-
type: 'select',
255-
selectOptions: [
256-
'arithmetic_mean',
257-
'geometric_mean',
258-
'harmonic_mean',
259-
],
260-
},
261-
{ id: 'description', type: 'string' },
262-
{ id: 'tag', type: 'string' },
263-
],
264-
},
265-
],
266-
}
267-
: { processors: [] };
77+
return uiMetadata;
26878
}
26979

27080
export const resizeObserverMock = jest.fn().mockImplementation(() => ({

0 commit comments

Comments
 (0)