Filtering for endpoint selector

This commit is contained in:
yuneng-jiang
2025-12-05 17:36:45 -08:00
parent 4d39a1a18f
commit c595f7a9cb
2 changed files with 21 additions and 2 deletions
@@ -1,5 +1,6 @@
import { render, waitFor } from "@testing-library/react";
import { describe, it, expect } from "vitest";
import { render, screen, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { describe, expect, it } from "vitest";
import EndpointSelector from "./EndpointSelector";
import { ENDPOINT_OPTIONS } from "./chatConstants";
@@ -12,4 +13,18 @@ describe("EndpointSelector", () => {
});
});
});
it("should filter and show audio endpoints when user inputs 'audio'", async () => {
const user = userEvent.setup();
render(<EndpointSelector endpointType={ENDPOINT_OPTIONS[0].value} onEndpointChange={() => {}} />);
const combobox = screen.getByRole("combobox");
await user.click(combobox);
const input = await screen.findByRole("combobox");
await user.type(input, "audio");
expect(await screen.findByText("/v1/audio/speech")).toBeInTheDocument();
expect(await screen.findByText("/v1/audio/transcriptions")).toBeInTheDocument();
});
});
@@ -18,6 +18,10 @@ const EndpointSelector: React.FC<EndpointSelectorProps> = ({ endpointType, onEnd
onChange={onEndpointChange}
options={ENDPOINT_OPTIONS}
className="rounded-md"
filterOption={(input, option) =>
(option?.label ?? "").toLowerCase().includes(input.toLowerCase()) ||
(option?.value ?? "").toLowerCase().includes(input.toLowerCase())
}
/>
</div>
);