fix: reworking some code smell issues
This commit is contained in:
@@ -1,6 +1,20 @@
|
||||
defmodule BDS.I18nTest do
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
test "language_name/1 returns a non-empty native autonym for exactly the supported codes" do
|
||||
codes = Enum.map(BDS.I18n.supported_languages(), & &1.code)
|
||||
|
||||
for code <- codes do
|
||||
assert BDS.I18n.language_name(code) not in [nil, ""]
|
||||
end
|
||||
|
||||
assert BDS.I18n.language_name("de") == "Deutsch"
|
||||
assert BDS.I18n.language_name("fr") == "Français"
|
||||
assert BDS.I18n.language_name("es") == "Español"
|
||||
# Unsupported codes fall back to the resolved render locale (default "en").
|
||||
assert BDS.I18n.language_name("pt-BR") == "English"
|
||||
end
|
||||
|
||||
test "supported languages, normalization, and UI locale resolution follow the spec" do
|
||||
assert Enum.map(BDS.I18n.supported_languages(), & &1.code) == ["en", "de", "fr", "it", "es"]
|
||||
|
||||
|
||||
12
test/bds/strings_test.exs
Normal file
12
test/bds/strings_test.exs
Normal file
@@ -0,0 +1,12 @@
|
||||
defmodule BDS.StringsTest do
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
alias BDS.Strings
|
||||
|
||||
test "pad2/1 zero-pads to at least two digits" do
|
||||
assert Strings.pad2(0) == "00"
|
||||
assert Strings.pad2(3) == "03"
|
||||
assert Strings.pad2(12) == "12"
|
||||
assert Strings.pad2(123) == "123"
|
||||
end
|
||||
end
|
||||
@@ -552,7 +552,13 @@ defmodule BDS.UI.ShellTest do
|
||||
"phx-window-keydown={if(@titlebar_menu_group, do: \"titlebar_menu_keydown\")}"
|
||||
|
||||
assert template =~ "window-titlebar-menu-group"
|
||||
assert live_ex =~ ~s(def handle_event("titlebar_menu_keydown")
|
||||
|
||||
# titlebar/native menu events are routed from ShellLive to NativeMenuEvents.
|
||||
native_menu_ex =
|
||||
File.read!("/Users/gb/Projects/bDS2/lib/bds/desktop/shell_live/native_menu_events.ex")
|
||||
|
||||
assert live_ex =~ "@native_menu_events"
|
||||
assert native_menu_ex =~ ~s(def handle("titlebar_menu_keydown")
|
||||
assert live_ex =~ "titlebar_menu_item_index"
|
||||
end
|
||||
|
||||
|
||||
51
test/bds/values_test.exs
Normal file
51
test/bds/values_test.exs
Normal file
@@ -0,0 +1,51 @@
|
||||
defmodule BDS.ValuesTest do
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
alias BDS.Values
|
||||
|
||||
describe "present?/1 and blank?/1 (non-trimming)" do
|
||||
test "nil and empty string are blank" do
|
||||
assert Values.blank?(nil)
|
||||
assert Values.blank?("")
|
||||
refute Values.present?(nil)
|
||||
refute Values.present?("")
|
||||
end
|
||||
|
||||
test "whitespace-only strings are PRESENT (non-trimming contract)" do
|
||||
# Crucial: matches BDS.MapUtils.blank_to_nil/1 — a trim-aware caller must
|
||||
# compose String.trim/1 itself.
|
||||
assert Values.present?(" ")
|
||||
assert Values.present?("\n")
|
||||
refute Values.blank?(" ")
|
||||
refute Values.blank?("\n")
|
||||
end
|
||||
|
||||
test "non-empty values are present" do
|
||||
for v <- ["x", 0, 1, 1.0, false, true] do
|
||||
assert Values.present?(v)
|
||||
refute Values.blank?(v)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "truthy?/1" do
|
||||
test "accepts the canonical truthy set" do
|
||||
for v <- [true, "true", "on", 1, 1.0, "1"] do
|
||||
assert Values.truthy?(v)
|
||||
end
|
||||
end
|
||||
|
||||
test "rejects everything else" do
|
||||
for v <- [false, "false", "off", 0, "0", nil, "", "yes", 2] do
|
||||
refute Values.truthy?(v)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
test "blank_to_nil/1 delegates to MapUtils (non-trimming)" do
|
||||
assert Values.blank_to_nil(nil) == nil
|
||||
assert Values.blank_to_nil("") == nil
|
||||
assert Values.blank_to_nil(" ") == " "
|
||||
assert Values.blank_to_nil("x") == "x"
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user