1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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");
});
});
|