mirror of
https://github.com/TheRealOwenRees/chess-endgame-trainer.git
synced 2026-11-18 11:42:07 +00:00
Add theme slugs, kinds and link provenance (#192)
* add function for upgrading a user's plan in interactive Elixir * Add theme slugs, kinds and link provenance Themes gain a stable slug, an optional description and a kind so the app can tell material, motif and technique labels apart. Slugs are generated from the name on first save and keep their value when the theme is renamed, so links to a theme stay valid. Endgame-to-theme links now record their source (derived, curated or community) and creation time. Existing links are backfilled as curated. A derived pass can therefore replace only its own links, leaving human work untouched. The admin index shows each theme's kind and its coverage across the library. Creating a theme name requires the manage_themes capability, and members get an unauthorized error instead, ahead of the suggestion flow. Closes #185
This commit is contained in:
@@ -17,7 +17,30 @@ defmodule ChesstrainerWeb.Admin.ThemeLive.FormTest do
|
||||
|
||||
assert_redirect(view, ~p"/admin/themes")
|
||||
|
||||
assert [%{name: "Lucena", category: :endgame}] = Themes.search("Lucena", "endgame")
|
||||
assert [%{name: "Lucena", slug: "lucena", kind: :technique, category: :endgame}] =
|
||||
Themes.search("Lucena", "endgame")
|
||||
end
|
||||
|
||||
test "creates a theme with a kind and description", %{conn: conn} do
|
||||
{:ok, view, _html} = live(conn, ~p"/admin/themes/new")
|
||||
|
||||
view
|
||||
|> form("#theme-form",
|
||||
theme: %{
|
||||
name: "Rook endgame",
|
||||
kind: "material",
|
||||
category: "endgame",
|
||||
description: "Positions where a rook and pawn face a rook."
|
||||
}
|
||||
)
|
||||
|> render_submit()
|
||||
|
||||
assert_redirect(view, ~p"/admin/themes")
|
||||
|
||||
assert [theme] = Themes.search("Rook endgame", "endgame")
|
||||
assert theme.slug == "rook-endgame"
|
||||
assert theme.kind == :material
|
||||
assert theme.description == "Positions where a rook and pawn face a rook."
|
||||
end
|
||||
|
||||
test "renames and recategorises a theme", %{conn: conn} do
|
||||
|
||||
@@ -11,8 +11,8 @@ defmodule ChesstrainerWeb.Admin.ThemeLive.IndexTest do
|
||||
|
||||
setup :register_and_log_in_admin
|
||||
|
||||
test "lists themes with their usage count", %{conn: conn} do
|
||||
used_theme = theme_fixture(%{name: "Lucena"})
|
||||
test "lists themes with their kind and coverage", %{conn: conn} do
|
||||
used_theme = theme_fixture(%{name: "Lucena", kind: :technique})
|
||||
unused_theme = theme_fixture(%{name: "Philidor"})
|
||||
endgame = endgame_fixture()
|
||||
{:ok, _} = Endgames.update_endgame(endgame, %{}, [used_theme])
|
||||
@@ -20,8 +20,9 @@ defmodule ChesstrainerWeb.Admin.ThemeLive.IndexTest do
|
||||
{:ok, view, _html} = live(conn, ~p"/admin/themes")
|
||||
|
||||
assert has_element?(view, "#theme-#{used_theme.id}")
|
||||
assert has_element?(view, "#theme-usage-#{used_theme.id}", "1 endgame")
|
||||
assert has_element?(view, "#theme-usage-#{unused_theme.id}", "0 endgames")
|
||||
assert has_element?(view, "#theme-#{used_theme.id}", "technique")
|
||||
assert has_element?(view, "#theme-usage-#{used_theme.id}", "1 of 1 endgame")
|
||||
assert has_element?(view, "#theme-usage-#{unused_theme.id}", "0 of 1 endgame")
|
||||
end
|
||||
|
||||
test "filters by name and category", %{conn: conn} do
|
||||
@@ -57,7 +58,7 @@ defmodule ChesstrainerWeb.Admin.ThemeLive.IndexTest do
|
||||
|
||||
{:ok, view, html} = live(conn, ~p"/admin/themes")
|
||||
|
||||
assert html =~ "Used by 1 endgame"
|
||||
assert html =~ "Used by 1 of 1 endgame"
|
||||
assert html =~ "The endgames will be kept"
|
||||
|
||||
view |> element("#theme-#{theme.id} a", "Delete") |> render_click()
|
||||
|
||||
Reference in New Issue
Block a user