From 2f3583212f470f454a8bd4942a36742be92ad62b Mon Sep 17 00:00:00 2001
From: nsfisis <nsfisis@gmail.com>
Date: Tue, 17 Feb 2026 20:32:58 +0900
Subject: test(frontend): add comprehensive tests for components, hooks, and
 state

Add 84 new tests covering Jotai atoms (play/watch state transitions,
game timing, score management), utility functions (calcCodeSize,
checkGameResultKind), UI components (SubmitStatusLabel, LeftTime,
SubmitButton, InputText, BorderedContainerWithCaption,
FoldableBorderedContainerWithCaption, UserIcon, PlayerNameAndIcon),
and the usePageTitle hook.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---
 frontend/app/components/UserIcon.test.tsx | 62 +++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)
 create mode 100644 frontend/app/components/UserIcon.test.tsx

(limited to 'frontend/app/components/UserIcon.test.tsx')

diff --git a/frontend/app/components/UserIcon.test.tsx b/frontend/app/components/UserIcon.test.tsx
new file mode 100644
index 0000000..964aae1
--- /dev/null
+++ b/frontend/app/components/UserIcon.test.tsx
@@ -0,0 +1,62 @@
+/**
+ * @vitest-environment jsdom
+ */
+import { cleanup, render, screen } from "@testing-library/react";
+import { afterEach, describe, expect, test } from "vitest";
+import UserIcon from "./UserIcon";
+
+afterEach(() => {
+	cleanup();
+});
+
+describe("UserIcon", () => {
+	test("renders an img element", () => {
+		render(
+			<UserIcon
+				iconPath="icons/test.png"
+				displayName="TestUser"
+				className="w-16 h-16"
+			/>,
+		);
+		const img = screen.getByAltText("TestUser のアイコン");
+		expect(img.tagName).toBe("IMG");
+	});
+
+	test("sets alt text with display name", () => {
+		render(
+			<UserIcon
+				iconPath="icons/test.png"
+				displayName="Alice"
+				className="w-16 h-16"
+			/>,
+		);
+		expect(screen.getByAltText("Alice のアイコン")).toBeDefined();
+	});
+
+	test("applies rounded-full and border classes", () => {
+		render(
+			<UserIcon
+				iconPath="icons/test.png"
+				displayName="Bob"
+				className="w-16 h-16"
+			/>,
+		);
+		const img = screen.getByAltText("Bob のアイコン");
+		expect(img.className).toContain("rounded-full");
+		expect(img.className).toContain("border-4");
+		expect(img.className).toContain("border-white");
+	});
+
+	test("applies custom className", () => {
+		render(
+			<UserIcon
+				iconPath="icons/test.png"
+				displayName="Bob"
+				className="w-48 h-48"
+			/>,
+		);
+		const img = screen.getByAltText("Bob のアイコン");
+		expect(img.className).toContain("w-48");
+		expect(img.className).toContain("h-48");
+	});
+});
-- 
cgit v1.3.1

