test: push coverage to 70% with more CoreComponents and PostgresNotifier
- CoreComponents.input/1: expanded coverage to include the select, textarea, generic-text, and unchecked-checkbox branches, plus error-vs-no-error border styling. - PostgresNotifier: handle_info forwards pg_notify payload to Aprsme.PubSub and ignores unrelated messages. Coverage 69.56 → 70.11%.
This commit is contained in:
parent
5363b2cb69
commit
16d2e929c0
2 changed files with 140 additions and 0 deletions
24
test/aprsme/postgres_notifier_test.exs
Normal file
24
test/aprsme/postgres_notifier_test.exs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
defmodule Aprsme.PostgresNotifierTest do
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
alias Aprsme.PostgresNotifier
|
||||
|
||||
describe "handle_info/2 notification forwarding" do
|
||||
test "broadcasts the payload on Aprsme.PubSub for aprs_events channel" do
|
||||
:ok = Phoenix.PubSub.subscribe(Aprsme.PubSub, "postgres:aprsme_events")
|
||||
|
||||
msg = {:notification, :conn_stub, :from_pid, "aprs_events", "payload-content"}
|
||||
|
||||
assert {:noreply, state} = PostgresNotifier.handle_info(msg, %{conn: :stub})
|
||||
assert state.conn == :stub
|
||||
|
||||
assert_receive {:postgres_notify, "payload-content"}, 500
|
||||
end
|
||||
|
||||
test "ignores unrelated messages" do
|
||||
state = %{conn: :stub}
|
||||
assert {:noreply, ^state} = PostgresNotifier.handle_info(:random_message, state)
|
||||
assert {:noreply, ^state} = PostgresNotifier.handle_info({:other_tuple, "data"}, state)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -145,6 +145,122 @@ defmodule AprsmeWeb.CoreComponentsTest do
|
|||
# Checkbox is pre-checked when value matches "true".
|
||||
assert html =~ "checked"
|
||||
end
|
||||
|
||||
test "checkbox is unchecked when value is not 'true'" do
|
||||
html =
|
||||
render_component(&CoreComponents.input/1, %{
|
||||
id: "flag",
|
||||
name: "flag",
|
||||
type: "checkbox",
|
||||
value: "false",
|
||||
errors: []
|
||||
})
|
||||
|
||||
refute html =~ " checked "
|
||||
end
|
||||
end
|
||||
|
||||
describe "input/1 select" do
|
||||
test "renders a select with options" do
|
||||
html =
|
||||
render_component(&CoreComponents.input/1, %{
|
||||
id: "color",
|
||||
name: "color",
|
||||
type: "select",
|
||||
label: "Color",
|
||||
value: "red",
|
||||
errors: [],
|
||||
options: [{"Red", "red"}, {"Blue", "blue"}],
|
||||
multiple: false,
|
||||
prompt: nil
|
||||
})
|
||||
|
||||
assert html =~ "<select"
|
||||
assert html =~ "Red"
|
||||
assert html =~ "Blue"
|
||||
end
|
||||
|
||||
test "renders the prompt when given" do
|
||||
html =
|
||||
render_component(&CoreComponents.input/1, %{
|
||||
id: "color",
|
||||
name: "color",
|
||||
type: "select",
|
||||
label: "Color",
|
||||
value: nil,
|
||||
errors: [],
|
||||
options: [{"Red", "red"}],
|
||||
multiple: false,
|
||||
prompt: "Pick one"
|
||||
})
|
||||
|
||||
assert html =~ "Pick one"
|
||||
end
|
||||
end
|
||||
|
||||
describe "input/1 textarea" do
|
||||
test "renders a textarea with the value as content" do
|
||||
html =
|
||||
render_component(&CoreComponents.input/1, %{
|
||||
id: "bio",
|
||||
name: "bio",
|
||||
type: "textarea",
|
||||
label: "Bio",
|
||||
value: "hello world",
|
||||
errors: []
|
||||
})
|
||||
|
||||
assert html =~ "<textarea"
|
||||
assert html =~ "hello world"
|
||||
end
|
||||
|
||||
test "applies error styling when errors are present" do
|
||||
html =
|
||||
render_component(&CoreComponents.input/1, %{
|
||||
id: "bio",
|
||||
name: "bio",
|
||||
type: "textarea",
|
||||
label: "Bio",
|
||||
value: "",
|
||||
errors: ["is required"]
|
||||
})
|
||||
|
||||
assert html =~ "border-rose-400"
|
||||
assert html =~ "is required"
|
||||
end
|
||||
end
|
||||
|
||||
describe "input/1 generic" do
|
||||
test "renders a text input with errors" do
|
||||
html =
|
||||
render_component(&CoreComponents.input/1, %{
|
||||
id: "email",
|
||||
name: "email",
|
||||
type: "text",
|
||||
label: "Email",
|
||||
value: "",
|
||||
errors: ["is invalid"]
|
||||
})
|
||||
|
||||
assert html =~ ~s(name="email")
|
||||
assert html =~ "is invalid"
|
||||
assert html =~ "border-rose-400"
|
||||
end
|
||||
|
||||
test "uses no-error styling when errors are empty" do
|
||||
html =
|
||||
render_component(&CoreComponents.input/1, %{
|
||||
id: "email",
|
||||
name: "email",
|
||||
type: "text",
|
||||
label: "Email",
|
||||
value: "a@b",
|
||||
errors: []
|
||||
})
|
||||
|
||||
assert html =~ "border-zinc-300"
|
||||
refute html =~ "border-rose-400"
|
||||
end
|
||||
end
|
||||
|
||||
describe "show/1 and hide/1" do
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue