The reveal was one linear clock, so every character cost the same and a comma had nowhere to breathe. It now runs off a schedule: each visible unit costs BASE_UNIT_MS plus a pause after it, longer at a sentence end and longest at a line or paragraph break. Pauses never stack (a break after a full stop owns the pause) and a comma inside a number is not a clause. The schedule is built in relative units and scaled to the target duration, so a line paced to a recorded clip keeps the rhythm instead of flattening it. Between two spoken lines there is now a beat with the speaker's typing dots, and clicking during it starts the next line at once. The opening line of a cascade gets no beat. The typing sound is synthesized (one tick per 55ms at most) from precomputed, seeded tick times, so a re-render cannot re-roll the rhythm. It stays silent on a line with a recorded clip, when the header mute is on, and under reduced motion. It follows a new account preference, users.preferences.dialogue.typewriterSound, separate from the voice switch, with a migration. visibleLength is now defined as visibleText(text).length, so the schedule and the renderer cannot disagree about how long a line is.
84 lines
3.1 KiB
TypeScript
84 lines
3.1 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",
|
|
conversationTypewriterSound: true,
|
|
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: "Play a typing sound 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",
|
|
conversationTypewriterSound: false,
|
|
conversationVoice: false,
|
|
});
|
|
});
|
|
});
|
|
});
|