fix(search): the live-search tooltip says what a search costs

It always said a live search spends the shared API quota, while the default source (the website's
own endpoint, scrape) spends none — the owner avoided a free search because of it. /api/me now names
the running search_source, and the tooltip names the cost under it: none for scrape (the enrich step
costs a unit or two), 100 units a page for the official API.
This commit is contained in:
2026-10-04 17:53:19 +02:00
parent ce8ccfc3c0
commit 0e077b84c8
8 changed files with 85 additions and 3 deletions
@@ -0,0 +1,47 @@
// @vitest-environment jsdom
//
// The live-search button's tooltip says what a search costs under the search source the instance
// actually runs. It used to say "uses shared API quota" always, while the default source (the
// website's own endpoint) spends none — so the owner avoided a free search for months.
import { describe, it, expect, vi, afterEach } from "vitest";
import { render, screen, cleanup } from "@testing-library/react";
vi.mock("react-i18next", async (importOriginal) => ({
...(await importOriginal<typeof import("react-i18next")>()),
useTranslation: () => ({ t: (k: string) => k, i18n: { language: "en" } }),
}));
vi.mock("./navigationContext", () => ({ useNavigation: () => ({ page: "feed" }) }));
vi.mock("./feedFiltersContext", () => ({
useFeedFilters: () => ({ q: "cats", sort: "newest" }),
useFeedFiltersActions: () => ({ setFilters: vi.fn() }),
}));
vi.mock("./playlistsContext", () => ({
usePlaylists: () => ({ search: "" }),
usePlaylistsActions: () => ({ setSearch: vi.fn() }),
}));
vi.mock("./channelsContext", () => ({
useChannels: () => ({ search: "" }),
useChannelsActions: () => ({ setSearch: vi.fn(), goToFullHistory: vi.fn() }),
}));
vi.mock("./SyncStatus", () => ({ default: () => null }));
import Header from "./Header";
import type { Me } from "../lib/api";
afterEach(cleanup);
function tipFor(source: Me["search_source"]): string | null {
const me = { is_demo: false, plex_enabled: false, search_source: source } as Me;
render(<Header me={me} onYtSearch={() => {}} />);
return screen.getByRole("button", { name: /header\.searchYoutube$/ }).getAttribute("title");
}
describe("the live-search tooltip", () => {
it("does not claim a quota cost under the free website source", () => {
expect(tipFor("scrape")).toBe("header.searchYoutubeTip");
});
it("names the quota cost when the instance searches through the official API", () => {
expect(tipFor("api")).toBe("header.searchYoutubeTipApi");
});
});
+3 -1
View File
@@ -60,7 +60,9 @@ const Header = forwardRef<
}}
onGo={() => onYtSearch(trimmed)}
goLabel={t("header.searchYoutube")}
goTitle={t("header.searchYoutubeTip")}
goTitle={t(
me.search_source === "api" ? "header.searchYoutubeTipApi" : "header.searchYoutubeTip",
)}
goIcon={<YouTubeIcon className="w-4 h-4" />}
goDisabled={!trimmed || me.is_demo}
/>