defmodule GitGudWeb.AvatarComponentTest do
use ExUnit.Case, async: true
import Phoenix.LiveViewTest
alias GitGudWeb.AvatarComponent
describe "render_spec/1" do
test "deterministic for the same seed" do
assert AvatarComponent.render_spec("alice") == AvatarComponent.render_spec("alice")
end
test "different seeds produce different specs" do
a = AvatarComponent.render_spec("alice")
b = AvatarComponent.render_spec("bob")
assert a != b
end
test "picks a color from the daisyUI palette" do
{color, _} = AvatarComponent.render_spec("alice")
assert color in AvatarComponent.palette()
end
test "every cell is mirrored — symmetric around x=2" do
{_, cells} = AvatarComponent.render_spec("identicon-symmetry-check")
for {x, y} <- cells do
assert {4 - x, y} in cells or x == 2
end
end
test "cell coords stay inside the 5x5 grid" do
{_, cells} = AvatarComponent.render_spec("xyz")
for {x, y} <- cells do
assert x in 0..4
assert y in 0..4
end
end
end
describe "avatar/1 render" do
test "emits an SVG inside a rounded-full wrapper" do
html = render_component(&AvatarComponent.avatar/1, name: "alice", size: "md")
assert html =~ "rounded-full"
assert html =~ "<svg"
assert html =~ "viewBox=\"0 0 5 5\""
end
test "fill uses theme CSS var, not a hard-coded color" do
html = render_component(&AvatarComponent.avatar/1, name: "alice")
assert html =~ "fill: var(--color-"
refute html =~ "fill: #"
end
test "size attr maps to the right Tailwind class" do
html = render_component(&AvatarComponent.avatar/1, name: "alice", size: "xs")
assert html =~ "size-4"
html = render_component(&AvatarComponent.avatar/1, name: "alice", size: "2xl")
assert html =~ "size-24"
end
test "same seed renders the same HTML on every call" do
a = render_component(&AvatarComponent.avatar/1, name: "stable")
b = render_component(&AvatarComponent.avatar/1, name: "stable")
assert a == b
end
end
end
2.1 KiB · text
5af55d9