diff --git a/lib/chesstrainer_web/live/endgame_live/play.ex b/lib/chesstrainer_web/live/endgame_live/play.ex index 7571e88..4b3bb79 100644 --- a/lib/chesstrainer_web/live/endgame_live/play.ex +++ b/lib/chesstrainer_web/live/endgame_live/play.ex @@ -1,6 +1,7 @@ defmodule ChesstrainerWeb.EndgameLive.Play do use ChesstrainerWeb, :live_view + alias Chesstrainer.Accounts.Scope alias Chesstrainer.Endgames alias ChesstrainerWeb.EndgameLive.PlayCore alias ChesstrainerWeb.PlayComponents @@ -32,9 +33,12 @@ defmodule ChesstrainerWeb.EndgameLive.Play do

<:actions> - <.button navigate={~p"/endgames"}> + <.button :if={Scope.premium?(@current_scope)} navigate={~p"/endgames"}> <.icon name="hero-arrow-left" /> Back to endgames + <.button :if={!Scope.premium?(@current_scope)} navigate={~p"/"}> + <.icon name="hero-arrow-left" /> Back home + diff --git a/test/chesstrainer_web/live/endgame_live/play_test.exs b/test/chesstrainer_web/live/endgame_live/play_test.exs index 6a4314e..50f71f4 100644 --- a/test/chesstrainer_web/live/endgame_live/play_test.exs +++ b/test/chesstrainer_web/live/endgame_live/play_test.exs @@ -211,6 +211,50 @@ defmodule ChesstrainerWeb.EndgameLive.PlayTest do end end + describe "back link" do + test "points home for an anonymous visitor", %{conn: conn} do + endgame = endgame_fixture() + seed_tablebase(endgame.fen) + + {:ok, view, _html} = live(conn, ~p"/endgames/#{endgame.public_code}/play") + + assert has_element?(view, ~s{a[href="/"]}, "Back home") + refute has_element?(view, ~s{a[href="/endgames"]}) + end + + test "points home for a signed-in free user", %{conn: conn} do + user = Chesstrainer.AccountsFixtures.user_fixture() + endgame = endgame_fixture() + seed_tablebase(endgame.fen) + + {:ok, view, _html} = + conn + |> log_in_user(user) + |> live(~p"/endgames/#{endgame.public_code}/play") + + assert has_element?(view, ~s{a[href="/"]}, "Back home") + refute has_element?(view, ~s{a[href="/endgames"]}) + end + + test "points to the endgame index for a premium user", %{conn: conn} do + {:ok, user} = + Chesstrainer.AccountsFixtures.user_fixture() + |> Ecto.Changeset.change(plan: :premium) + |> Repo.update() + + endgame = endgame_fixture() + seed_tablebase(endgame.fen) + + {:ok, view, _html} = + conn + |> log_in_user(user) + |> live(~p"/endgames/#{endgame.public_code}/play") + + assert has_element?(view, ~s{a[href="/endgames"]}, "Back to endgames") + refute has_element?(view, ~s{a[href="/"]}, "Back home") + end + end + describe "tablebase availability" do test "blocks the attempt when the tablebase is cooling down", %{conn: conn} do # Six pieces routes to Lichess, so the cooldown applies (five or fewer diff --git a/test/chesstrainer_web/live/endgame_live/player_index_test.exs b/test/chesstrainer_web/live/endgame_live/player_index_test.exs index ef28341..7e7bfda 100644 --- a/test/chesstrainer_web/live/endgame_live/player_index_test.exs +++ b/test/chesstrainer_web/live/endgame_live/player_index_test.exs @@ -67,6 +67,6 @@ defmodule ChesstrainerWeb.EndgameLive.PlayerIndexTest do {:ok, view, _html} = live(conn, ~p"/endgames/#{endgame.public_code}/play") assert has_element?(view, "#endgame-board") - assert has_element?(view, ~s{a[href="/endgames"]}) + assert has_element?(view, ~s{a[href="/"]}) end end