-
Notifications
You must be signed in to change notification settings - Fork 10
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 unit tests #345
Merged
+181
−4
Merged
Changes from 10 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
930f664
workflow_detail tests
saimedhi 307ee99
Merge branch 'opensearch-project:main' into tests_copy
saimedhi 34e96d1
workflow_detail tests
saimedhi e85b048
workflow_detail tests
saimedhi 2334fa7
Merge pull request #3 from saimedhi/tests2_copy
saimedhi 55e4c0f
workflow_detail tests
saimedhi 6735c58
Merge pull request #4 from saimedhi/tests2_copy
saimedhi 1e39db4
workflow_detail tests
saimedhi 8a4d8b2
workflow_detail tests
saimedhi 99fb0b3
Merge pull request #5 from saimedhi/tests2_copy
saimedhi b34a878
workflow_detail tests
saimedhi b8ed7d9
Merge pull request #6 from saimedhi/tests2_copy
saimedhi bcbbcbf
workflow_detail tests
saimedhi 7407a63
Merge pull request #7 from saimedhi/tests2_copy
saimedhi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { Provider } from 'react-redux'; | ||
import { | ||
RouteComponentProps, | ||
Route, | ||
Switch, | ||
Router, | ||
Redirect, | ||
} from 'react-router-dom'; | ||
import { WorkflowDetail } from './workflow_detail'; | ||
import { WorkflowDetailRouterProps } from '../../pages'; | ||
import '@testing-library/jest-dom'; | ||
import { mockStore, resizeObserverMock } from '../../../test/utils'; | ||
import { createMemoryHistory } from 'history'; | ||
import { WORKFLOW_TYPE } from '../../../common'; | ||
|
||
jest.mock('../../services', () => { | ||
const { mockCoreServices } = require('../../../test'); | ||
return { | ||
...jest.requireActual('../../services'), | ||
...mockCoreServices, | ||
}; | ||
}); | ||
|
||
const history = createMemoryHistory(); | ||
window.ResizeObserver = resizeObserverMock; | ||
|
||
const renderWithRouter = ( | ||
workflowId: string, | ||
workflowName: string, | ||
workflowType: WORKFLOW_TYPE | ||
) => ({ | ||
...render( | ||
<Provider store={mockStore(workflowId, workflowName, workflowType)}> | ||
<Router history={history}> | ||
<Switch> | ||
<Route | ||
path="/workflow/:workflowId" | ||
render={(props: RouteComponentProps<WorkflowDetailRouterProps>) => { | ||
return <WorkflowDetail setActionMenu={jest.fn()} {...props} />; | ||
}} | ||
/> | ||
<Redirect from="/" to={`/workflow/${workflowId}`} /> | ||
</Switch> | ||
</Router> | ||
</Provider> | ||
), | ||
}); | ||
|
||
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) => { | ||
test(`renders the page with ${type} type`, () => { | ||
saimedhi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const { getAllByText, getByText, getByRole } = renderWithRouter( | ||
workflowId, | ||
workflowName, | ||
type | ||
); | ||
|
||
expect(getAllByText(workflowName).length).toBeGreaterThan(0); | ||
expect(getAllByText('Create an ingest pipeline').length).toBeGreaterThan( | ||
0 | ||
); | ||
expect(getAllByText('Skip ingestion pipeline').length).toBeGreaterThan(0); | ||
expect(getAllByText('Define ingest pipeline').length).toBeGreaterThan(0); | ||
expect(getAllByText('Tools').length).toBeGreaterThan(0); | ||
expect(getAllByText('Preview').length).toBeGreaterThan(0); | ||
expect(getAllByText('Not started').length).toBeGreaterThan(0); | ||
expect( | ||
getAllByText((content) => content.startsWith('Last updated:')).length | ||
).toBeGreaterThan(0); | ||
expect(getAllByText('Search pipeline').length).toBeGreaterThan(0); | ||
expect(getByText('Close')).toBeInTheDocument(); | ||
expect(getByText('Export')).toBeInTheDocument(); | ||
expect(getByText('Visual')).toBeInTheDocument(); | ||
expect(getByText('JSON')).toBeInTheDocument(); | ||
expect(getByRole('tab', { name: 'Run ingestion' })).toBeInTheDocument(); | ||
expect(getByRole('tab', { name: 'Run queries' })).toBeInTheDocument(); | ||
expect(getByRole('tab', { name: 'Errors' })).toBeInTheDocument(); | ||
expect(getByRole('tab', { name: 'Resources' })).toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |
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,274 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { PROCESSOR_TYPE, WORKFLOW_TYPE } from '../common/constants'; | ||
import { | ||
IProcessorConfig, | ||
ProcessorsConfig, | ||
Workflow, | ||
} from '../common/interfaces'; | ||
|
||
export function mockStore( | ||
workflowId: string, | ||
workflowName: string, | ||
workflowType: WORKFLOW_TYPE | ||
) { | ||
return { | ||
getState: () => ({ | ||
opensearch: { | ||
errorMessage: '', | ||
}, | ||
ml: {}, | ||
workflows: { | ||
loading: false, | ||
errorMessage: '', | ||
workflows: { | ||
[workflowId]: generateWorkflow( | ||
workflowId, | ||
workflowName, | ||
workflowType | ||
), | ||
}, | ||
}, | ||
}), | ||
dispatch: jest.fn(), | ||
subscribe: jest.fn(), | ||
replaceReducer: jest.fn(), | ||
[Symbol.observable]: jest.fn(), | ||
}; | ||
} | ||
|
||
function generateWorkflow( | ||
workflowId: string, | ||
workflowName: string, | ||
workflowType: WORKFLOW_TYPE | ||
): Workflow { | ||
return { | ||
id: workflowId, | ||
name: workflowName, | ||
version: { template: '1.0.0', compatibility: ['2.17.0', '3.0.0'] }, | ||
ui_metadata: { | ||
saimedhi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 }, | ||
}, | ||
}, | ||
}, | ||
}; | ||
} | ||
|
||
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 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: [] }; | ||
} | ||
|
||
export const resizeObserverMock = jest.fn().mockImplementation(() => ({ | ||
observe: jest.fn(), | ||
unobserve: jest.fn(), | ||
disconnect: jest.fn(), | ||
})); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wondering why we need this redirect? Can't we specify the path directly on line 44?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
path="/workflow/:workflowId"