Files
owenrees 69b89f68ef Add a public health probe and monitoring runbook (#166)
* move theme picker position in add endgames form

* Add branded favicons and web manifest

- Replace the placeholder favicon with the knight mark: .ico (16/32/48),
  SVG, and 16/32 PNGs.
- Add opaque apple-touch and Android launcher icons plus a site
  webmanifest naming the app and using the brand palette.
- Link the icon set, manifest, and theme-color from the root layout and
  the 404/500 pages.
- Whitelist the new static files in static_paths/0 and the prelaunch
  allowlist so they are served in production and behind the gate.
- Sync the coming-soon site's favicon.ico and drop the unused Phoenix
  logo.

* Add a public health probe and monitoring runbook

Probe https://<PHX_HOST>/health through Cloudflare every two minutes and
report to a healthchecks.io check. A healthy run posts the raw health JSON;
a tablebase mismatch is a green check-in with the mismatch recorded; a
non-200, non-JSON, down database or network failure posts one fail ping with
the response body and a loopback cross-check as evidence.

--dry-run evaluates the success, degraded, fail, non-JSON and unreachable
fixtures without reading config or touching the network. The runbook covers
the healthchecks.io check, install, what /health proves, Beszel's blind spot
and the drills.

* Fix theme picker search after moving it into the endgame form

The picker moved inside the endgame form, which nested the component's
own <form>. Browsers, and the LiveView test DOM, drop a nested form along
with its phx-change and phx-submit bindings, so the search box did nothing
and three form tests lost their #theme-form selector.

The component now renders no form: phx-change sits on the search input,
which works both inside the endgame form and standalone on the bulk
importer. The unreachable create_theme_from_search handlers go away; theme
creation uses the existing button. Tests search through the input and
click that button.
2026-11-13 13:24:35 +01:00

166 lines
4.8 KiB
Elixir

defmodule ChesstrainerWeb.EndgameLive.FormTest do
use ChesstrainerWeb.ConnCase
import Phoenix.LiveViewTest
import Chesstrainer.ThemesFixtures
alias Chesstrainer.Endgames
alias Chesstrainer.Repo
alias Chesstrainer.Themes
@fen "8/8/3k4/8/8/3K1R2/8/8 w - - 0 1"
setup :register_and_log_in_admin
describe "rating default" do
test "new endgame form pre-fills rating with 1500", %{conn: conn} do
{:ok, view, _html} = live(conn, ~p"/admin/endgames/new")
html = view |> element("#endgame-form input[name='endgame[rating]']") |> render()
assert html =~ ~s(value="1500")
end
test "creates an endgame rated 1500 when rating is left unchanged", %{conn: conn} do
{:ok, view, _html} = live(conn, ~p"/admin/endgames/new")
view
|> form("#endgame-form", endgame: %{fen: @fen, result: "win"})
|> render_submit()
assert_redirect(view, ~p"/admin/endgames")
endgame = Endgames.list_endgames() |> Enum.find(&(&1.fen == @fen))
assert endgame.rating == 1500
end
test "editing an endgame keeps its stored rating", %{conn: conn} do
attrs = %{fen: @fen, color: :white, result: :win, rating: 1625}
{:ok, endgame} = Endgames.create_endgame(attrs)
{:ok, view, _html} = live(conn, ~p"/admin/endgames/#{endgame.id}/edit")
html = view |> element("#endgame-form input[name='endgame[rating]']") |> render()
assert html =~ ~s(value="1625")
end
end
describe "position preview" do
test "shows the board once the FEN is valid", %{conn: conn} do
{:ok, view, _html} = live(conn, ~p"/admin/endgames/new")
refute has_element?(view, "#endgame-preview-board")
view
|> form("#endgame-form", endgame: %{fen: @fen})
|> render_change()
assert has_element?(view, "#endgame-preview-board")
assert has_element?(view, "#endgame-preview-board img[src='/images/pieces/white/rook.svg']")
end
test "hides the board when the FEN is invalid", %{conn: conn} do
{:ok, view, _html} = live(conn, ~p"/admin/endgames/new")
view
|> form("#endgame-form", endgame: %{fen: @fen})
|> render_change()
assert has_element?(view, "#endgame-preview-board")
view
|> form("#endgame-form", endgame: %{fen: "not a fen"})
|> render_change()
refute has_element?(view, "#endgame-preview-board")
end
end
test "creates an endgame with staged themes", %{conn: conn} do
theme = theme_fixture(%{name: "Lucena"})
{:ok, view, html} = live(conn, ~p"/admin/endgames/new")
assert html =~ "max-w-2xl"
view
|> element("#theme-picker input[name='theme_search']")
|> render_change(%{theme_search: "Luc"})
view |> element("button", "Lucena") |> render_click()
view
|> form("#endgame-form",
endgame: %{fen: @fen, rating: 1500, result: "win"}
)
|> render_submit()
assert_redirect(view, ~p"/admin/endgames")
endgame =
Endgames.list_endgames()
|> Enum.find(&(&1.fen == @fen))
|> Repo.preload(:themes)
assert Enum.map(endgame.themes, & &1.id) == [theme.id]
end
test "attaches multiple themes", %{conn: conn} do
theme_fixture(%{name: "Lucena"})
theme_fixture(%{name: "Philidor"})
{:ok, view, _html} = live(conn, ~p"/admin/endgames/new")
view
|> element("#theme-picker input[name='theme_search']")
|> render_change(%{theme_search: "Luc"})
view |> element("button", "Lucena") |> render_click()
view
|> element("#theme-picker input[name='theme_search']")
|> render_change(%{theme_search: "Phil"})
view |> element("button", "Philidor") |> render_click()
html = render(view)
assert html =~ "Lucena"
assert html =~ "Philidor"
end
test "creates and attaches a new theme inline", %{conn: conn} do
{:ok, view, _html} = live(conn, ~p"/admin/endgames/new")
view
|> element("#theme-picker input[name='theme_search']")
|> render_change(%{theme_search: "Lucerne"})
view |> element("button", ~s(Create theme "Lucerne")) |> render_click()
assert render(view) =~ "Lucerne"
assert [%{name: "Lucerne"}] = Themes.search("Lucerne", "endgame")
end
test "removes a theme from an existing endgame", %{conn: conn} do
theme = theme_fixture(%{name: "Lucena"})
attrs = %{fen: @fen, color: :white, result: :win, rating: 1500}
{:ok, endgame} = Endgames.create_endgame(attrs, [theme])
{:ok, view, _html} = live(conn, ~p"/admin/endgames/#{endgame.id}/edit")
assert render(view) =~ "Lucena"
view |> element("button[aria-label='Remove Lucena']") |> render_click()
view
|> form("#endgame-form", endgame: %{rating: 1500, result: "win"})
|> render_submit()
assert_redirect(view, ~p"/admin/endgames")
updated = Endgames.get_endgame!(endgame.id) |> Repo.preload(:themes)
assert updated.themes == []
end
end