1
0
Fork 0
polaris-task-force/tests/int/preferences-form.int.spec.ts
Z8MB1E 18ea696d1b feat(npc-dialogue): voice clips on dialogue lines
A line can now carry a recorded voice, played when it lands with the text
paced to the clip so speech and text finish together. Clips live in media and
flowData keeps only a pointer, so a deleted file goes quiet instead of
breaking the line; resolveVoiceClip turns it into a URL per read.

Authors get two sources in the node editor: a direct upload, and an accepted
voiceover take imported from the existing submission flow. Both convert to mono
MP3 through the voiceover transcoder, because browser recordings are WebM and
iOS will not always play them, and a failed transcode stores the original
rather than losing the take.

Players control it twice: users.preferences.dialogue.voice (default on) is the
durable choice, and the speaker button in the conversation header mutes for
that conversation. Autoplay is not guaranteed, so a rejected play() shows a
Play voice button on the line rather than failing silently.
2026-11-24 17:59:36 -05:00

81 lines
2.9 KiB
TypeScript

// @vitest-environment jsdom
import { createElement } from "react";
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { PreferencesForm } from "@/components/frontend/account/PreferencesForm";
import { updatePreferences } from "@/app/(frontend)/account/actions";
vi.mock("next/navigation", () => ({
useRouter: () => ({ refresh: vi.fn() }),
}));
vi.mock("@/app/(frontend)/account/actions", () => ({
updatePreferences: vi.fn(),
}));
class ResizeObserverMock implements ResizeObserver {
observe(_target: Element, _options?: ResizeObserverOptions): void {}
unobserve(_target: Element): void {}
disconnect(): void {}
}
globalThis.ResizeObserver = ResizeObserverMock;
const mockedUpdatePreferences = vi.mocked(updatePreferences);
describe("PreferencesForm", () => {
beforeEach(() => {
mockedUpdatePreferences.mockReset();
mockedUpdatePreferences.mockResolvedValue({ success: true });
});
it("submits all display, in-app, and Discord preferences", async () => {
render(
createElement(PreferencesForm, {
mutedAll: false,
mutedTypes: ["market:offer"],
showCallsign: false,
showVersionOverlay: true,
showBackgroundTexture: true,
leadOrActual: "lead",
discordEnabled: false,
discordMutedTypes: [],
xpDisplayMini: false,
conversationTypewriter: "default",
conversationVoice: true,
}),
);
fireEvent.click(screen.getByRole("switch", { name: "Show callsign instead of display name" }));
fireEvent.click(screen.getByRole("switch", { name: "Use mini mode for XP display" }));
fireEvent.click(screen.getByRole("switch", { name: "Mute all in-app notifications" }));
fireEvent.click(screen.getByRole("radio", { name: "Actual" }));
fireEvent.click(screen.getByRole("radio", { name: "Show instantly" }));
fireEvent.click(screen.getByRole("switch", { name: "Play voice clips in conversations" }));
fireEvent.click(screen.getByRole("switch", { name: "Enable Discord notifications" }));
const discordMarketOffer = document.getElementById("discord-market-offer");
if (!(discordMarketOffer instanceof HTMLElement)) {
throw new Error("Discord market-offer switch was not rendered.");
}
fireEvent.click(discordMarketOffer);
fireEvent.click(screen.getByRole("button", { name: "Save preferences" }));
await waitFor(() => {
expect(mockedUpdatePreferences).toHaveBeenCalledWith({
mutedAll: true,
mutedTypes: ["market:offer"],
showCallsign: true,
showVersionOverlay: true,
showBackgroundTexture: true,
leadOrActual: "actual",
discordEnabled: true,
discordMutedTypes: ["market:offer"],
xpDisplayMini: true,
conversationTypewriter: "off",
conversationVoice: false,
});
});
});
});