mirror of
https://github.com/TheRealOwenRees/chess-endgame-trainer.git
synced 2026-11-18 03:32:06 +00:00
Add Discord invite link to navbar and footer
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
defmodule Chesstrainer.BrandingTest do
|
||||
use ExUnit.Case, async: false
|
||||
|
||||
alias Chesstrainer.Branding
|
||||
|
||||
describe "discord_invite_url/0" do
|
||||
setup do
|
||||
previous = Application.get_env(:chesstrainer, :branding)
|
||||
on_exit(fn -> restore(:branding, previous) end)
|
||||
:ok
|
||||
end
|
||||
|
||||
test "passes a full URL through" do
|
||||
put_branding(discord_invite: "https://discord.gg/abc123")
|
||||
|
||||
assert Branding.discord_invite_url() == "https://discord.gg/abc123"
|
||||
end
|
||||
|
||||
test "expands a bare invite code" do
|
||||
put_branding(discord_invite: " abc123 ")
|
||||
|
||||
assert Branding.discord_invite_url() == "https://discord.gg/abc123"
|
||||
end
|
||||
|
||||
test "returns nil when the invite is blank" do
|
||||
put_branding(discord_invite: "")
|
||||
|
||||
assert Branding.discord_invite_url() == nil
|
||||
end
|
||||
end
|
||||
|
||||
defp put_branding(overrides) do
|
||||
config = Application.get_env(:chesstrainer, :branding, [])
|
||||
Application.put_env(:chesstrainer, :branding, Keyword.merge(config, overrides))
|
||||
end
|
||||
|
||||
defp restore(key, nil), do: Application.delete_env(:chesstrainer, key)
|
||||
defp restore(key, value), do: Application.put_env(:chesstrainer, key, value)
|
||||
end
|
||||
@@ -5,6 +5,7 @@ defmodule ChesstrainerWeb.LayoutsTest do
|
||||
|
||||
alias Chesstrainer.Accounts.Scope
|
||||
alias Chesstrainer.Accounts.User
|
||||
alias Chesstrainer.Branding
|
||||
alias ChesstrainerWeb.Layouts
|
||||
|
||||
describe "navbar/1" do
|
||||
@@ -30,6 +31,44 @@ defmodule ChesstrainerWeb.LayoutsTest do
|
||||
end
|
||||
end
|
||||
|
||||
describe "discord_link/1" do
|
||||
setup do
|
||||
previous = Application.get_env(:chesstrainer, :branding)
|
||||
on_exit(fn -> restore_env(:branding, previous) end)
|
||||
:ok
|
||||
end
|
||||
|
||||
test "renders an icon-only link to the configured invite" do
|
||||
html = render_component(&Layouts.discord_link/1, %{})
|
||||
|
||||
assert html =~ ~s(href="#{Branding.discord_invite_url()}")
|
||||
assert html =~ ~s(aria-label="Join the #{Branding.name()} Discord")
|
||||
assert html =~ ~s(target="_blank")
|
||||
assert html =~ "noopener noreferrer"
|
||||
assert html =~ ~r/<a[^>]*class="discord-link"[^>]*>\s*<svg/
|
||||
end
|
||||
|
||||
test "is rendered by the navbar and the footer" do
|
||||
navbar = render_component(&Layouts.navbar/1, %{current_scope: nil})
|
||||
assert navbar =~ ~s(class="discord-link")
|
||||
|
||||
footer = render_component(&Layouts.footer/1, %{})
|
||||
assert footer =~ ~s(class="discord-link")
|
||||
end
|
||||
|
||||
test "renders nothing when no invite is configured" do
|
||||
Application.put_env(
|
||||
:chesstrainer,
|
||||
:branding,
|
||||
Keyword.put(Application.get_env(:chesstrainer, :branding, []), :discord_invite, "")
|
||||
)
|
||||
|
||||
html = render_component(&Layouts.discord_link/1, %{})
|
||||
|
||||
refute html =~ "discord-link"
|
||||
end
|
||||
end
|
||||
|
||||
describe "colour_mode_toggle/1" do
|
||||
test "renders light and dark modes as a labelled radiogroup" do
|
||||
html = render_component(&Layouts.colour_mode_toggle/1, %{})
|
||||
|
||||
Reference in New Issue
Block a user