The personal finance app for everyone (by everyone)
Ruby
fix(categories): update avatar preview when picking a color (#3554)
Justin McBride244609c46efd
diff --git a/app/views/categories/_color_avatar.html.erb b/app/views/categories/_color_avatar.html.erbindex 8e690c3b8a..abefba842e 100644--- a/app/views/categories/_color_avatar.html.erb+++ b/app/views/categories/_color_avatar.html.erb@@ -3,6 +3,6 @@<spandata-color-icon-picker-target="avatar"class="w-14 h-14 flex items-center justify-center rounded-full"- style="background-color: color-mix(in oklab, <%= category.color %> 10%, transparent); color: <%= category.color %>">+ style="--avatar-color: <%= category.color %>; background-color: color-mix(in oklab, var(--avatar-color) 10%, transparent); color: var(--avatar-color)"><%= icon(category.lucide_icon, size: "2xl", color: "current") %></span>diff --git a/test/system/categories_test.rb b/test/system/categories_test.rbindex f1cd39d2db..c3eff0be3e 100644--- a/test/system/categories_test.rb+++ b/test/system/categories_test.rb@@ -58,6 +58,21 @@ class CategoriesTest < ApplicationSystemTestCaseassert_equal "pizza", @user.family.categories.find_by!(name: "Takeout").lucide_iconend+ test "picking a color updates the avatar preview" do+ visit categories_url+ click_link I18n.t("categories.new.new_category")++ avatar = find("[data-color-icon-picker-target='avatar']")+ initial_color = avatar.evaluate_script("getComputedStyle(this).color")++ find("summary[aria-label='#{I18n.t("categories.form.trigger_label")}']").click++ color = Category::COLORS.find { |c| hex_to_rgb(c) != initial_color }+ find("input[type='radio'][value='#{color}']", visible: :all).find(:xpath, "..").click++ assert_equal hex_to_rgb(color), avatar.evaluate_script("getComputedStyle(this).color")+ end+test "reopening the icon picker clears the previous search" dovisit categories_urlclick_link I18n.t("categories.new.new_category")@@ -118,4 +133,9 @@ class CategoriesTest < ApplicationSystemTestCaseassert_operator page_scroll_width, :<=, viewport_widthend++ private+ def hex_to_rgb(hex)+ "rgb(#{hex.delete_prefix("#").scan(/../).map { |c| c.to_i(16) }.join(", ")})"+ endend