fix(notifications): a confirm names its user and channel again; t() and a notice's text are kept apart by a contract
The value sweep wrapped two plain t() values in raw(), so the delete-user and the YouTube subscribe confirms read "[object Object]" where the email or the channel was. tsc cannot see that seam, so a syntax contract now refuses a notice value handed to t() and an already-said text kept in a notice. The raw() doc says what it is: text kept as fetched (a Plex title in the language it was fetched in). seasonTitleText's no-number branches are tested.
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
// @vitest-environment jsdom
|
||||
//
|
||||
// Subscribing changes the reader's real YouTube account, so the confirm names the channel it
|
||||
// subscribes to — in both languages, through the real i18n. A notice's value (`raw`, `msg`) is said
|
||||
// only by sayNotif: handed to a plain `t()` it reads "[object Object]".
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { act, cleanup, renderHook } from "@testing-library/react";
|
||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
import type { ReactNode } from "react";
|
||||
import i18n from "../../i18n";
|
||||
|
||||
const h = vi.hoisted(() => ({ confirm: vi.fn(async (_o: { message: string }) => false) }));
|
||||
vi.mock("../../components/ui/confirmContext", () => ({ useConfirm: () => h.confirm }));
|
||||
|
||||
import { useWatchedChannelActions } from "./useWatchedChannelActions";
|
||||
import type { WatchedChannel } from "../../lib/api";
|
||||
|
||||
afterEach(async () => {
|
||||
cleanup();
|
||||
h.confirm.mockClear();
|
||||
await i18n.changeLanguage("en");
|
||||
});
|
||||
|
||||
const channel = { id: "UC1", title: "Kurzgesagt" } as WatchedChannel;
|
||||
|
||||
const wrapper = ({ children }: { children: ReactNode }) => (
|
||||
<QueryClientProvider client={new QueryClient()}>{children}</QueryClientProvider>
|
||||
);
|
||||
|
||||
describe("the subscribe confirm", () => {
|
||||
it.each(["en", "hu"])("names the channel (%s)", async (lng) => {
|
||||
await i18n.changeLanguage(lng);
|
||||
const { result } = renderHook(() => useWatchedChannelActions(() => {}), { wrapper });
|
||||
await act(() => result.current.onSubscribe(channel));
|
||||
const said = h.confirm.mock.lastCall![0].message;
|
||||
expect(said).toContain("Kurzgesagt");
|
||||
expect(said).not.toContain("[object Object]");
|
||||
});
|
||||
});
|
||||
@@ -54,7 +54,7 @@ export function useWatchedChannelActions(onOpenWizard: () => void) {
|
||||
const onSubscribe = async (c: WatchedChannel): Promise<boolean> => {
|
||||
const ok = await confirm({
|
||||
title: t("channels.discovery.subscribe"),
|
||||
message: t("channels.discovery.confirmSubscribe", { name: raw(nameOf(c)) }),
|
||||
message: t("channels.discovery.confirmSubscribe", { name: nameOf(c) }),
|
||||
confirmLabel: t("channels.discovery.subscribe"),
|
||||
});
|
||||
if (ok) subscribe.mutate(c);
|
||||
|
||||
Reference in New Issue
Block a user