mirror of
https://github.com/TheRealOwenRees/chess-endgame-trainer.git
synced 2026-11-18 03:32:06 +00:00
@@ -17,7 +17,7 @@ defmodule Chesstrainer.Endgames.Endgame do
|
|||||||
field :message, :string
|
field :message, :string
|
||||||
field :notes, :string
|
field :notes, :string
|
||||||
field :result, Ecto.Enum, values: [:win, :loss, :draw]
|
field :result, Ecto.Enum, values: [:win, :loss, :draw]
|
||||||
field :rating, :integer
|
field :rating, :integer, default: 1500
|
||||||
field :rating_deviation, :integer
|
field :rating_deviation, :integer
|
||||||
field :times_attempted, :integer
|
field :times_attempted, :integer
|
||||||
field :times_solved, :integer
|
field :times_solved, :integer
|
||||||
|
|||||||
@@ -150,6 +150,14 @@ defmodule Chesstrainer.EndgamesTest do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "rating default" do
|
||||||
|
test "a new endgame changeset defaults rating to 1500" do
|
||||||
|
changeset = Endgames.change_endgame(%Endgame{})
|
||||||
|
|
||||||
|
assert Ecto.Changeset.get_field(changeset, :rating) == 1500
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "listing and filtering" do
|
describe "listing and filtering" do
|
||||||
test "list_keys/0 returns the distinct keys sorted" do
|
test "list_keys/0 returns the distinct keys sorted" do
|
||||||
create_endgame!(@kr)
|
create_endgame!(@kr)
|
||||||
|
|||||||
@@ -10,6 +10,40 @@ defmodule ChesstrainerWeb.EndgameLive.FormTest do
|
|||||||
|
|
||||||
@fen "8/8/3k4/8/8/3K1R2/8/8 w - - 0 1"
|
@fen "8/8/3k4/8/8/3K1R2/8/8 w - - 0 1"
|
||||||
|
|
||||||
|
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}/edit")
|
||||||
|
|
||||||
|
html = view |> element("#endgame-form input[name='endgame[rating]']") |> render()
|
||||||
|
|
||||||
|
assert html =~ ~s(value="1625")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
test "creates an endgame with staged themes", %{conn: conn} do
|
test "creates an endgame with staged themes", %{conn: conn} do
|
||||||
theme = theme_fixture(%{name: "Lucena"})
|
theme = theme_fixture(%{name: "Lucena"})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user