Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React from 'react';
import { render, screen, waitFor } from '@testing-library/react';
import { JudgmentsComboBox } from '../judgments_combo_box';
import { ServiceEndpoints } from '../../../../../../common';

const mockHttp = {
get: jest.fn(),
};

describe('JudgmentsComboBox', () => {
beforeEach(() => {
jest.clearAllMocks();
});

it('requests only COMPLETED judgments and renders options', async () => {
const mockResponse = {
hits: {
hits: [
{ _source: { id: '1', name: 'Completed A', status: 'COMPLETED' } },
{ _source: { id: '2', name: 'Completed B', status: 'COMPLETED' } },
],
},
};
mockHttp.get.mockResolvedValueOnce(mockResponse);

render(
<JudgmentsComboBox
selectedOptions={[]}
onChange={() => {}}
http={mockHttp as any}
hideLabel
/>
);

// Verify request used status filter
await waitFor(() => {
expect(mockHttp.get).toHaveBeenCalledWith(ServiceEndpoints.Judgments, { query: { status: 'COMPLETED' } });
});

// Placeholder switches to 'Select judgment list' once loaded
expect(screen.getByText('Select judgment list')).toBeInTheDocument();

// Ensure options are mapped (labels visible only when opening combo, but we can rely on mapping without user interaction)
// For robustness, we check the component rendered without errors and made the expected call.
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const JudgmentsComboBox = ({
let isMounted = true;
const fetchJudgments = async () => {
try {
const data = await http.get(ServiceEndpoints.Judgments);
const data = await http.get(ServiceEndpoints.Judgments, { query: { status: 'COMPLETED' } });
const options = data.hits.hits.map((judgment: any) => ({
label: judgment._source.name,
value: judgment._source.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ describe('useJudgmentList', () => {
expect(response.hits[0].name).toBe('Test Judgment');
});

// Existing hook should still request full judgments without status filter
expect(mockHttp.get).toHaveBeenCalledWith(ServiceEndpoints.Judgments);
});

Expand Down
13 changes: 11 additions & 2 deletions server/routes/search_relevance_route_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,11 @@ export function registerSearchRelevanceRoutes(router: IRouter): void {
router.get(
{
path: ServiceEndpoints.Judgments,
validate: false,
validate: {
query: schema.object({
status: schema.maybe(schema.string()),
}),
},
},
backendAction('GET', BackendEndpoints.Judgments)
);
Expand Down Expand Up @@ -251,9 +255,14 @@ const backendAction = (method, path) => {
});
} else {
// Handle PUT, POST, GET as before
// For Judgments GET with status query param, append to backend URL
let backendPath = path;
if (method === 'GET' && path === BackendEndpoints.Judgments && req.query?.status) {
backendPath = `${path}?status=${req.query.status}`;
}
response = await caller('transport.request', {
method,
path,
path: backendPath,
...(method === 'POST' || method === 'PUT' ? { body: req.body } : {}),
});
}
Expand Down
Loading