// @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"; import type { Me } from "../../lib/api"; vi.mock("react-i18next", async (importOriginal) => ({ ...(await importOriginal()), useTranslation: () => ({ t: (k: string) => k, i18n: { language: "en" } }), })); let me = {} as Me; vi.mock("../../lib/useMe", () => ({ useMe: () => me })); vi.mock("../../features/navigation/navigationContext", () => ({ useNavigationActions: () => ({ enterYtSearch: vi.fn() }), })); vi.mock("./feedFiltersContext", () => ({ useFeedFilters: () => ({ q: "cats", sort: "newest" }), useFeedFiltersActions: () => ({ setFilters: vi.fn() }), })); vi.mock("../channels", () => ({ useChannelsActions: () => ({ goToFullHistory: vi.fn() }), SyncStatus: () => null, })); vi.mock("./FeedScopeToggle", () => ({ default: () => null })); vi.mock("../../components/ui/PageScroller", () => ({ default: ({ children }: { children: React.ReactNode }) =>
{children}
, })); import FeedHeader from "./FeedHeader"; import PageShell from "../../components/ui/PageShell"; afterEach(() => { cleanup(); vi.unstubAllGlobals(); }); function tipFor(source: Me["search_source"]): string | null { vi.stubGlobal( "ResizeObserver", class { observe() {} disconnect() {} }, ); me = { search_source: source, search_enabled: true, role: "user" } 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"); }); }); describe("the live-search button", () => { it("is left out when the instance turned live search off", () => { vi.stubGlobal( "ResizeObserver", class { observe() {} disconnect() {} }, ); me = { search_source: "scrape", search_enabled: false, role: "user" } as Me; render( }> , ); expect(screen.queryByRole("button", { name: /header\.searchYoutube$/ })).toBeNull(); }); });