mirror of
https://github.com/OpenHands/OpenHands.git
synced 2026-10-07 14:58:39 +08:00
fix: clear stale urlSearchResults for non-matching HTTPS URLs in useUrlSearch (#16700)
Co-authored-by: vasco <vasco.schiavo@protonmail.com>
This commit is contained in:
@@ -238,4 +238,44 @@ describe("useUrlSearch", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
it("should clear prior results when an HTTPS URL does not match repo pattern", async () => {
|
||||
mockSearchGitRepositories.mockResolvedValue({
|
||||
items: [
|
||||
{
|
||||
id: "1",
|
||||
full_name: "owner/repo",
|
||||
git_provider: "github",
|
||||
is_public: true,
|
||||
},
|
||||
],
|
||||
next_page_id: null,
|
||||
});
|
||||
|
||||
const { result, rerender } = renderHook(
|
||||
({ inputValue, provider }) => useUrlSearch(inputValue, provider),
|
||||
{
|
||||
initialProps: {
|
||||
inputValue: "https://github.com/owner/repo",
|
||||
provider: "github" as const,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(result.current.urlSearchResults).toHaveLength(1);
|
||||
});
|
||||
|
||||
rerender({
|
||||
inputValue: "https://example.com/",
|
||||
provider: "github" as const,
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(result.current.urlSearchResults).toEqual([]);
|
||||
});
|
||||
|
||||
// Only the initial search for owner/repo should have triggered a call;
|
||||
// the non-matching HTTPS URL must not issue a second request.
|
||||
expect(mockSearchGitRepositories).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -38,6 +38,8 @@ export function useUrlSearch(
|
||||
} finally {
|
||||
setIsUrlSearchLoading(false);
|
||||
}
|
||||
} else {
|
||||
setUrlSearchResults([]);
|
||||
}
|
||||
} else {
|
||||
setUrlSearchResults([]);
|
||||
|
||||
Reference in New Issue
Block a user