// @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()), 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 = { plex_enabled: false, search_source: source } as Me; render(
{}} />); 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"); }); });