Skip to content

Commit

Permalink
fix unit tests after address comments on 12/27
Browse files Browse the repository at this point in the history
Signed-off-by: Kama Huang <[email protected]>
  • Loading branch information
Kama Huang committed Dec 31, 2024
1 parent 200b2d9 commit 71bf71f
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 8 deletions.
10 changes: 9 additions & 1 deletion public/pages/workflow_detail/workflow_detail.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { WorkflowDetailRouterProps } from '../../pages';
import '@testing-library/jest-dom';
import { mockStore, resizeObserverMock } from '../../../test/utils';
import { createMemoryHistory } from 'history';
import { WORKFLOW_TYPE } from '../../../common';
import { MINIMUM_FULL_SUPPORTED_VERSION, WORKFLOW_TYPE } from '../../../common';

jest.mock('../../services', () => {
const { mockCoreServices } = require('../../../test');
Expand All @@ -39,13 +39,20 @@ const renderWithRouter = (
initialEntries: [`/workflow/${workflowId}`],
});

const needsVersion = [
WORKFLOW_TYPE.SEMANTIC_SEARCH,
WORKFLOW_TYPE.MULTIMODAL_SEARCH,
WORKFLOW_TYPE.HYBRID_SEARCH,
].includes(workflowType);

return {
...render(
<Provider
store={mockStore({
id: workflowId,
name: workflowName,
type: workflowType,
version: needsVersion ? MINIMUM_FULL_SUPPORTED_VERSION : undefined,
})}
>
<Router history={history}>
Expand All @@ -68,6 +75,7 @@ describe('WorkflowDetail Page with create ingestion option', () => {
beforeEach(() => {
jest.clearAllMocks();
});

Object.values(WORKFLOW_TYPE).forEach((type) => {
test(`renders the WorkflowDetail page with ${type} type`, async () => {
const {
Expand Down
23 changes: 23 additions & 0 deletions public/pages/workflows/new_workflow/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ export function fetchEmptyUIConfig(): WorkflowConfig {
}

export function fetchSemanticSearchMetadata(version: string): UIState {
if (!version) {
throw new Error(
'Version parameter is required for fetchSemanticSearchMetadata'
);
}
let baseState = fetchEmptyMetadata();
baseState.type = WORKFLOW_TYPE.SEMANTIC_SEARCH;
const isPreV219 = semver.lt(version, MINIMUM_FULL_SUPPORTED_VERSION);
Expand Down Expand Up @@ -179,6 +184,12 @@ export function fetchSemanticSearchMetadata(version: string): UIState {
}

export function fetchMultimodalSearchMetadata(version: string): UIState {
if (!version) {
throw new Error(
'Version parameter is required for fetchSemanticSearchMetadata'
);
}

let baseState = fetchEmptyMetadata();
baseState.type = WORKFLOW_TYPE.MULTIMODAL_SEARCH;

Expand Down Expand Up @@ -213,6 +224,12 @@ export function fetchMultimodalSearchMetadata(version: string): UIState {
}

export function fetchHybridSearchMetadata(version: string): UIState {
if (!version) {
throw new Error(
'Version parameter is required for fetchSemanticSearchMetadata'
);
}

let baseState = fetchEmptyMetadata();
baseState.type = WORKFLOW_TYPE.HYBRID_SEARCH;
const isPreV219 = semver.lt(version, MINIMUM_FULL_SUPPORTED_VERSION);
Expand Down Expand Up @@ -252,6 +269,12 @@ export function fetchHybridSearchMetadata(version: string): UIState {
}

export function fetchRAGMetadata(version: string): UIState {
if (!version) {
throw new Error(
'Version parameter is required for fetchSemanticSearchMetadata'
);
}

let baseState = fetchEmptyMetadata();
baseState.type = WORKFLOW_TYPE.RAG;
baseState.config.ingest.index.name.value = generateId('my_index', 6);
Expand Down
1 change: 1 addition & 0 deletions test/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export type WorkflowInput = {
id: string;
name: string;
type: WORKFLOW_TYPE;
version?: string;
};
32 changes: 25 additions & 7 deletions test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import {
INITIAL_WORKFLOWS_STATE,
} from '../public/store';
import { WorkflowInput } from '../test/interfaces';
import { WORKFLOW_TYPE } from '../common/constants';
import {
MINIMUM_FULL_SUPPORTED_VERSION,
WORKFLOW_TYPE,
} from '../common/constants';
import { UIState, Workflow, WorkflowDict } from '../common/interfaces';
import {
fetchEmptyMetadata,
Expand Down Expand Up @@ -44,27 +47,42 @@ export function mockStore(...workflowSets: WorkflowInput[]) {
}

function generateWorkflow({ id, name, type }: WorkflowInput): Workflow {
const isSearchWorkflow = [
WORKFLOW_TYPE.SEMANTIC_SEARCH,
WORKFLOW_TYPE.MULTIMODAL_SEARCH,
WORKFLOW_TYPE.HYBRID_SEARCH,
].includes(type);

const version = {
template: '1.0.0',
compatibility: isSearchWorkflow
? [MINIMUM_FULL_SUPPORTED_VERSION]
: ['2.18.0', '3.0.0'],
};

return {
id,
name,
version: { template: '1.0.0', compatibility: ['2.18.0', '3.0.0'] },
ui_metadata: getConfig(type),
version,
ui_metadata: getConfig(type, version.compatibility[0]),
};
}

function getConfig(workflowType: WORKFLOW_TYPE) {
function getConfig(workflowType: WORKFLOW_TYPE, version?: string) {
let uiMetadata = {} as UIState;
const searchVersion = version || MINIMUM_FULL_SUPPORTED_VERSION;

switch (workflowType) {
case WORKFLOW_TYPE.SEMANTIC_SEARCH: {
uiMetadata = fetchSemanticSearchMetadata();
uiMetadata = fetchSemanticSearchMetadata(searchVersion);
break;
}
case WORKFLOW_TYPE.MULTIMODAL_SEARCH: {
uiMetadata = fetchMultimodalSearchMetadata();
uiMetadata = fetchMultimodalSearchMetadata(searchVersion);
break;
}
case WORKFLOW_TYPE.HYBRID_SEARCH: {
uiMetadata = fetchHybridSearchMetadata();
uiMetadata = fetchHybridSearchMetadata(searchVersion);
break;
}
default: {
Expand Down

0 comments on commit 71bf71f

Please sign in to comment.