Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Name each side's transaction in the transfer drawer (#5000)

Yong Cong Sinaea428b7f2d3
diff --git a/app/controllers/transfers_controller.rb b/app/controllers/transfers_controller.rb
index d5901ab9d0..cd50480b8c 100644
--- a/app/controllers/transfers_controller.rb
+++ b/app/controllers/transfers_controller.rb
@@ -26,6 +26,9 @@ class TransfersController < ApplicationController
# CTA that the controller would reject via `require_account_permission!`
# for read-only sharers.
endpoint_ids = [ @transfer.from_account&.id, @transfer.to_account&.id ].compact
+ # The drawer opens with access to the inflow side only; each side's own
+ # transaction name is shown only to a user who can see that side's account.
+ @readable_account_ids = Account.accessible_by(Current.user).where(id: endpoint_ids).distinct.pluck(:id)
writable_endpoint_count = Account.writable_by(Current.user).where(id: endpoint_ids).distinct.count
both_endpoints_writable = endpoint_ids.size == 2 && writable_endpoint_count == 2
@can_mark_as_recurring_transfer = !Current.family.recurring_transactions_disabled? && both_endpoints_writable
diff --git a/app/views/transfers/show.html.erb b/app/views/transfers/show.html.erb
index dbb4111066..43584cf81b 100644
--- a/app/views/transfers/show.html.erb
+++ b/app/views/transfers/show.html.erb
@@ -33,6 +33,15 @@
<dt class="text-secondary"><%= t(".date") %></dt>
<dd class="font-medium"><%= l(@transfer.outflow_transaction.entry.date, format: :long) %></dd>
</dl>
+ <%# Each side's own name, beside its amount: what tells a suggested match
+ (the transaction list's "Match?" pill opens this) apart from another.
+ DS::DetailRow wraps it rather than truncating, so it can be read in
+ full on a phone too. %>
+ <% if @readable_account_ids.include?(@transfer.from_account&.id) %>
+ <dl>
+ <%= render DS::DetailRow.new(label: t(".transaction"), value: @transfer.outflow_transaction.entry.name, value_class: "font-medium") %>
+ </dl>
+ <% end %>
<dl class="flex items-center gap-2 justify-between">
<dt class="text-secondary"><%= t(".transfer_amount") %></dt>
<dd class="font-medium text-destructive privacy-sensitive"><%= format_money @transfer.outflow_transaction.entry.amount_money * -1 %></dd>
@@ -63,6 +72,11 @@
<dt class="text-secondary"><%= t(".date") %></dt>
<dd class="font-medium"><%= l(@transfer.inflow_transaction.entry.date, format: :long) %></dd>
</dl>
+ <% if @readable_account_ids.include?(@transfer.to_account&.id) %>
+ <dl>
+ <%= render DS::DetailRow.new(label: t(".transaction"), value: @transfer.inflow_transaction.entry.name, value_class: "font-medium") %>
+ </dl>
+ <% end %>
<dl class="flex items-center gap-2 justify-between">
<dt class="text-secondary"><%= t(".transfer_amount") %></dt>
<dd class="font-medium text-success privacy-sensitive">+<%= format_money @transfer.inflow_transaction.entry.amount_money * -1 %></dd>
diff --git a/config/locales/views/transfers/en.yml b/config/locales/views/transfers/en.yml
index 77163afb69..e3973092b6 100644
--- a/config/locales/views/transfers/en.yml
+++ b/config/locales/views/transfers/en.yml
@@ -49,6 +49,7 @@ en:
to: To
date: Date
transfer_amount: Transfer amount
+ transaction: Transaction
total: Total
bank_charges: Bank Charges
source_fee: Source fee
diff --git a/test/controllers/transfers_controller_test.rb b/test/controllers/transfers_controller_test.rb
index 8177cb0ee6..f455f95f1b 100644
--- a/test/controllers/transfers_controller_test.rb
+++ b/test/controllers/transfers_controller_test.rb
@@ -1016,6 +1016,33 @@ class TransfersControllerTest < ActionDispatch::IntegrationTest
assert_response :not_found
end
+ test "show names each side's transaction beside its amount" do
+ transfer = transfers(:one)
+ transfer.outflow_transaction.entry.update!(name: "Card bill sent from checking")
+ transfer.inflow_transaction.entry.update!(name: "Payment received, thank you")
+
+ get transfer_url(transfer)
+
+ assert_response :success
+ assert_select "dt", text: I18n.t("transfers.show.transaction"), count: 2
+ assert_select "dd", text: "Card bill sent from checking"
+ assert_select "dd", text: "Payment received, thank you"
+ end
+
+ test "show leaves out the name of a side whose account the user cannot see" do
+ transfer = cross_owner_transfer(outflow_account: member_loan, inflow_account: accounts(:depository))
+ transfer.outflow_transaction.entry.update!(name: "Private loan payment")
+ transfer.inflow_transaction.entry.update!(name: "Money in")
+
+ get transfer_url(transfer)
+
+ assert_response :success
+ assert_select "dt", text: I18n.t("transfers.show.transaction"), count: 1
+ assert_select "dd", text: "Money in"
+ assert_select "dd", text: "Private loan payment", count: 0
+ assert_no_match "Private loan payment", response.body
+ end
+
test "show offers the investment contribution switch only for transfers into an investment account" do
contribution = create_confirmed_transfer(to: accounts(:investment))
payment = create_confirmed_transfer(to: accounts(:credit_card))
diff --git a/test/system/transactions_test.rb b/test/system/transactions_test.rb
index a28873535b..6125fa6527 100644
--- a/test/system/transactions_test.rb
+++ b/test/system/transactions_test.rb
@@ -199,6 +199,50 @@ class TransactionsTest < ApplicationSystemTestCase
end
end
+ test "the Match? pill opens the suggested transfer with both transactions' names and amounts" do
+ @user.update!(show_ai_sidebar: false)
+ page.current_window.resize_to(1440, 900)
+ outflow = create_transaction("Card bill sent from checking", Date.current, 100)
+ inflow = create_transaction("Payment received, thank you", Date.current, -100, account: accounts(:credit_card))
+ Transfer.create!(outflow_transaction: outflow.entryable, inflow_transaction: inflow.entryable)
+ visit transactions_url(per_page: @page_size)
+
+ find("##{dom_id(outflow.entryable, :transfer_match)} [data-testid='transfer-match-pill']", visible: true).click
+
+ within "dialog[open]" do
+ [ outflow, inflow ].each do |entry|
+ row = find("dd", exact_text: entry.name).find(:xpath, "ancestor::div[contains(@class, 'space-y-3')][1]")
+ assert row.has_selector?("dd", exact_text: entry.name)
+ assert row.has_selector?("dd.privacy-sensitive", text: entry.amount_money.abs.format), "#{entry.name}'s amount is not beside it"
+ end
+ end
+ end
+
+ test "a long transaction name wraps inside the transfer drawer instead of being cut off" do
+ @user.update!(show_ai_sidebar: false)
+ page.current_window.resize_to(390, 900)
+ long_reference = "SUNDAY*QUALITYWINESLONDONGBR-REF-0001234567890ABCDEF0123456789GHIJKLMNOPQRSTUVWXYZ-TXN-9876543210"
+ outflow = create_transaction(long_reference, Date.current, 100)
+ inflow = create_transaction("Payment received", Date.current, -100, account: accounts(:credit_card))
+ Transfer.create!(outflow_transaction: outflow.entryable, inflow_transaction: inflow.entryable)
+ visit transactions_url(per_page: @page_size)
+
+ find("##{dom_id(outflow.entryable, :transfer_match)} [data-testid='transfer-match-pill']", visible: true).click
+
+ name = find("dialog[open] dd", exact_text: long_reference)
+ fit = name.evaluate_script(<<~JS)
+ (() => {
+ const drawer = this.closest("dialog").getBoundingClientRect();
+ const box = this.getBoundingClientRect();
+ return { cut: this.scrollWidth > this.clientWidth + 1, inside: box.left >= drawer.left && box.right <= drawer.right + 0.5,
+ pageScrolls: document.documentElement.scrollWidth > document.documentElement.clientWidth };
+ })()
+ JS
+ assert_not fit["cut"], "the name is cut off; on a phone there is no way to read the rest"
+ assert fit["inside"], "the name runs out of the drawer"
+ assert_not fit["pageScrolls"], "the long name makes the page scroll sideways"
+ end
+
test "confirms an auto-matched transfer from beside the amount" do
@user.update!(show_ai_sidebar: false)
page.current_window.resize_to(1440, 900)