Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

1.9 KB
Raw Blame
import { describe, expect, it, vi } from "vitest";
import {
	handleEmojiReaction,
	REACTIONS,
} from "@/app/s/[videoId]/_components/toolbar-reactions";

describe("toolbar reactions", () => {
	it("exposes the standard reaction set in display order", () => {
		expect(REACTIONS).toEqual([
			{ emoji: "๐Ÿ˜‚", label: "joy" },
			{ emoji: "๐Ÿ˜", label: "love" },
			{ emoji: "๐Ÿ˜ฎ", label: "wow" },
			{ emoji: "๐Ÿ™Œ", label: "yay" },
			{ emoji: "๐Ÿ‘", label: "up" },
			{ emoji: "๐Ÿ‘Ž", label: "down" },
		]);
	});

	it("prompts sign-in overlay when unauthenticated viewer reacts", () => {
		const onRequireAuth = vi.fn();
		const onReact = vi.fn();

		handleEmojiReaction({
			emoji: "๐Ÿ˜‚",
			canReact: true,
			user: null,
			onRequireAuth,
			onReact,
		});

		expect(onRequireAuth).toHaveBeenCalledOnce();
		expect(onReact).not.toHaveBeenCalled();
	});

	it("prompts sign-in overlay when user is undefined", () => {
		const onRequireAuth = vi.fn();
		const onReact = vi.fn();

		handleEmojiReaction({
			emoji: "๐Ÿ‘",
			canReact: true,
			user: undefined,
			onRequireAuth,
			onReact,
		});

		expect(onRequireAuth).toHaveBeenCalledOnce();
		expect(onReact).not.toHaveBeenCalled();
	});

	it("suppresses interaction when reactions are disabled", () => {
		const onRequireAuth = vi.fn();
		const onReact = vi.fn();

		handleEmojiReaction({
			emoji: "๐Ÿ˜",
			canReact: false,
			user: null,
			onRequireAuth,
			onReact,
		});

		expect(onRequireAuth).not.toHaveBeenCalled();
		expect(onReact).not.toHaveBeenCalled();
	});

	it("submits reaction when viewer is signed in", () => {
		const onRequireAuth = vi.fn();
		const onReact = vi.fn();

		handleEmojiReaction({
			emoji: "๐Ÿ™Œ",
			canReact: true,
			user: { id: "user-123" },
			onRequireAuth,
			onReact,
		});

		expect(onRequireAuth).not.toHaveBeenCalled();
		expect(onReact).toHaveBeenCalledOnce();
		expect(onReact).toHaveBeenCalledWith("๐Ÿ™Œ", { id: "user-123" });
	});
});