The personal finance app for everyone (by everyone)
Ruby
Show the Income plan AI chips only when there is a plan (#3917)
Guillem Arias Fausteee30e377d48d
diff --git a/app/views/bills/paycheck.html.erb b/app/views/bills/paycheck.html.erbindex bf7b203c16..b89ca51232 100644--- a/app/views/bills/paycheck.html.erb+++ b/app/views/bills/paycheck.html.erb@@ -18,7 +18,10 @@<div class="space-y-4 pb-6 lg:pb-12"><%= render "bills/view_switcher", active: "paycheck" %>- <%= render "bills/ai_prompts", prompts: %w[due_before_paycheck safe_to_spend] %>+ <%# No plan means no paycheck and no period for these to ask about. %>+ <% if @plan %>+ <%= render "bills/ai_prompts", prompts: %w[due_before_paycheck safe_to_spend] %>+ <% end %><% if @income_series.any? %><%= render "bills/paycheck_income" %>diff --git a/test/controllers/bills_controller_test.rb b/test/controllers/bills_controller_test.rbindex 2e27cffaf7..d6ad9543f3 100644--- a/test/controllers/bills_controller_test.rb+++ b/test/controllers/bills_controller_test.rb@@ -658,6 +658,40 @@ class BillsControllerTest < ActionDispatch::IntegrationTestassert_match I18n.t("bills.paycheck.empty.title"), response.bodyend+ # With no plan there is no paycheck and no period, so the chips would open a+ # chat that can only say so. The review button proves AI is available, so+ # the missing chips can't pass for want of AI.+ test "the paycheck view offers its AI chips only with a plan" do+ Provider::Registry.stubs(:preferred_llm_provider).returns(Object.new)+ chips = %w[due_before_paycheck safe_to_spend].map { |key| ERB::Util.html_escape(I18n.t("bills.ai_prompts.#{key}")) }++ get bills_url(view: "paycheck")++ assert_response :success+ assert_match I18n.t("bills.paycheck.empty.title"), response.body+ assert_match I18n.t("bills.index.review_with_ai"), response.body+ chips.each { |chip| refute_includes response.body, chip }++ # Paused income is listed but defines no paydays: still no plan, no chips.+ income = declare_income(name: "Paycheck", amount: -1840, payday: Date.current + 3)+ income.update!(status: "paused")++ get bills_url(view: "paycheck")++ assert_response :success+ assert_match "Paycheck", response.body+ assert_match I18n.t("bills.paycheck.empty.title"), response.body+ chips.each { |chip| refute_includes response.body, chip }++ income.update!(status: "active")++ get bills_url(view: "paycheck")++ assert_response :success+ assert_no_match I18n.t("bills.paycheck.empty.title"), response.body+ chips.each { |chip| assert_includes response.body, chip }+ end+# Income was addable only from inside the Income plan tab, so a family that# had declared none had no way to discover the planning half of Bills# existed. Both halves are addable from every view, but only the half the