defmodule ChesstrainerWeb.LandingComponentsTest do use ChesstrainerWeb.ConnCase, async: true import Phoenix.LiveViewTest alias Chesstrainer.Endgames.Endgame alias Chesstrainer.Themes.Theme alias ChesstrainerWeb.LandingComponents @endgame %Endgame{ fen: "8/8/3k4/8/8/3K1R2/8/8 w - - 0 1", color: :white, key: "KR v K" } test "renders the endgame's pieces, side to move, and caption" do html = render_component(&LandingComponents.board_preview/1, %{endgame: @endgame}) assert html =~ "KR v K" assert html =~ "To move" assert html =~ "White" assert html =~ "♔" assert html =~ "♖" assert html =~ "♚" assert html =~ "Today’s position" end test "describes the board as an image for assistive technology" do html = render_component(&LandingComponents.board_preview/1, %{endgame: @endgame}) assert html =~ ~s(role="img") assert html =~ "Chess position. White to move" assert html =~ "rook on f3" end test "falls back to a neutral position without an endgame" do html = render_component(&LandingComponents.board_preview/1, %{endgame: nil}) assert html =~ "Featured position" assert html =~ "White" assert html =~ "♖" end test "renders themes under the position title" do endgame = %{ fen: @endgame.fen, color: :white, key: "KR v K", themes: [%Theme{name: "Lucena"}] } html = render_component(&LandingComponents.board_preview/1, %{endgame: endgame}) assert html =~ "Lucena" end test "renders the spark icon as a decorative primitive" do html = render_component(&LandingComponents.icon_spark/1, %{}) assert html =~ "