Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

1.5 KB
Raw Blame
import { create } from "@bufbuild/protobuf";
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import ReactionSelector from "@/components/MemoReactionListView/ReactionSelector";
import { MemoSchema } from "@/types/proto/api/memo_service_pb";

vi.mock("@/components/MemoReactionListView/hooks", () => ({
  useReactionActions: () => ({
    hasReacted: () => false,
    handleReactionClick: vi.fn(),
  }),
}));

vi.mock("@/contexts/InstanceContext", () => ({
  useInstance: () => ({ memoRelatedSetting: { reactions: ["πŸ‘"] } }),
}));

vi.mock("@/utils/i18n", () => ({
  useTranslate: () => (key: string) => key,
}));

describe("ReactionSelector", () => {
  it("uses a named native trigger with a visible focus state", async () => {
    const memo = create(MemoSchema, { name: "memos/1", reactions: [] });
    render(<ReactionSelector memo={memo} />);

    const trigger = screen.getByRole("button", { name: "setting.memo.add-reaction" });
    // The default trigger is a round quiet 28px face, closing the strip of reaction pills it follows.
    expect(trigger).toHaveClass("size-7", "rounded-full", "focus-visible:outline-2");
    expect(trigger.className).not.toMatch(/ring-/);
    expect(trigger).toHaveAttribute("aria-expanded", "false");

    fireEvent.click(trigger);

    await waitFor(() => expect(trigger).toHaveAttribute("aria-expanded", "true"));
    expect(screen.getByRole("button", { name: "πŸ‘" })).toBeInTheDocument();
  });
});