Files
clinch/test/helpers/application_helper_test.rb
Dan Milne fe68f6e81e Use Tailwind dark: toggles for dark-mode icons
The previous <picture media="(prefers-color-scheme: dark)"> only fires
when the OS is in dark mode. Clinch toggles dark mode with a class on
<html> via dark_mode_controller and Tailwind's @custom-variant dark
(&:where(.dark, .dark *)), so the picture source never swapped when
users clicked the in-app theme toggle. Render both <img> tags and
use Tailwind's dark:hidden / hidden dark:block so the swap follows
whatever strategy Tailwind is configured for.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-06-07 17:19:36 +10:00

54 lines
2.1 KiB
Ruby

require "test_helper"
class ApplicationHelperTest < ActionView::TestCase
test "monogram_initials picks capitals from camelCase" do
assert_equal "SL", monogram_initials("ShelfLife")
assert_equal "KR", monogram_initials("KavitaReader")
assert_equal "AB", monogram_initials("AudioBookShelf") # first two of 4 capitals
end
test "monogram_initials falls back to first two letters when fewer than two capitals" do
assert_equal "AU", monogram_initials("Audiobookshelf")
assert_equal "ME", monogram_initials("metube")
assert_equal "GI", monogram_initials("git")
end
test "monogram_initials handles single-character and unusual names" do
assert_equal "X", monogram_initials("X")
assert_equal "X1", monogram_initials("X1")
assert_equal "?", monogram_initials("")
assert_equal "?", monogram_initials(nil)
end
test "monogram_color is deterministic for the same name" do
a = monogram_color("ShelfLife")
b = monogram_color("ShelfLife")
assert_equal a, b
assert_match(/\A#[0-9a-f]{6}\z/i, a)
end
test "monogram_color differs for different names" do
# not a guarantee for all pairs, but should hold for at least one pair
assert_not_equal monogram_color("Kavita"), monogram_color("Navidrome")
end
test "app_icon_picture renders both icons with Tailwind dark: toggles when icon_dark is attached" do
app = applications(:kavita_app)
app.icon.attach(io: StringIO.new("light"), filename: "light.png", content_type: "image/png")
app.icon_dark.attach(io: StringIO.new("dark"), filename: "dark.png", content_type: "image/png")
html = app_icon_picture(app, class: "h-10 w-10 rounded-lg")
assert_match(/dark:hidden/, html)
assert_match(/hidden dark:block/, html)
end
test "app_icon_picture renders one img when no icon_dark is attached" do
app = applications(:kavita_app)
app.icon.attach(io: StringIO.new("light"), filename: "light.png", content_type: "image/png")
html = app_icon_picture(app, class: "h-10 w-10")
refute_match(/dark:hidden/, html)
refute_match(/hidden dark:block/, html)
end
end