]> git.openstreetmap.org Git - rails.git/commitdiff
Fix messages heading update when message is deleted
authorAnton Khorev <tony29@yandex.ru>
Tue, 26 Dec 2023 01:46:35 +0000 (04:46 +0300)
committerAnton Khorev <tony29@yandex.ru>
Tue, 26 Dec 2023 01:46:35 +0000 (04:46 +0300)
app/assets/javascripts/messages.js
app/views/messages/_inbox_count.html.erb [moved from app/views/messages/_message_count.html.erb with 91% similarity]
app/views/messages/_muted_count.html.erb [new file with mode: 0644]
app/views/messages/_outbox_count.html.erb [new file with mode: 0644]
app/views/messages/destroy.json.jbuilder
app/views/messages/inbox.html.erb
app/views/messages/mark.json.jbuilder
app/views/messages/muted.html.erb
app/views/messages/outbox.html.erb
test/system/messages_test.rb [new file with mode: 0644]

index 5accc1a6036fb94ec958eaf8f5c803832ecf3c09..cc86da05ea38365abaaa39a75f7dd25f94007dc6 100644 (file)
@@ -22,6 +22,8 @@ $(document).ready(function () {
     $(".user-button").before(data.inboxanchor);
 
     $("#inbox-count").replaceWith(data.inbox_count);
+    $("#outbox-count").replaceWith(data.outbox_count);
+    $("#muted-count").replaceWith(data.muted_count);
   }
 
   function updateReadState(target, isRead) {
similarity index 91%
rename from app/views/messages/_message_count.html.erb
rename to app/views/messages/_inbox_count.html.erb
index 33a3b52f3917c400cb1bedbe16e44de4692e66ba..86bb2c474d8bf005e290ce7a5e80a47d3d31ad3d 100644 (file)
@@ -1,7 +1,7 @@
-<p id="inbox-count">
+<h4 id="inbox-count">
 <%= t "messages.inbox.messages",
       :new_messages => t("messages.inbox.new_messages",
                          :count => current_user.new_messages.size),
       :old_messages => t("messages.inbox.old_messages",
                          :count => current_user.messages.size - current_user.new_messages.size) %>
-</p>
+</h4>
diff --git a/app/views/messages/_muted_count.html.erb b/app/views/messages/_muted_count.html.erb
new file mode 100644 (file)
index 0000000..207973d
--- /dev/null
@@ -0,0 +1,3 @@
+<h4 id="muted-count">
+<%= t "messages.muted.messages", :count => current_user.muted_messages.size %>
+</h4>
diff --git a/app/views/messages/_outbox_count.html.erb b/app/views/messages/_outbox_count.html.erb
new file mode 100644 (file)
index 0000000..5b27f1d
--- /dev/null
@@ -0,0 +1,3 @@
+<h4 id="outbox-count">
+<%= t "messages.outbox.messages", :count => current_user.sent_messages.size %>
+</h4>
index 3403ac888e27210467629afc2dba0532c98e4c64..65bfd6a6b70a97d9c5e06107d0ee076ea4e86931 100644 (file)
@@ -1,2 +1,4 @@
 json.inboxanchor render(:partial => "layouts/inbox")
-json.inbox_count render(:partial => "message_count")
+json.inbox_count render(:partial => "inbox_count")
+json.outbox_count render(:partial => "outbox_count")
+json.muted_count render(:partial => "muted_count")
index db807d2dfc732fd744335abf2234eb29ccd13dff..4d6be787b93fa5866404c8fc5721afe505382a12 100644 (file)
@@ -4,7 +4,7 @@
 
 <%= render :partial => "heading", :locals => { :active_link_path => inbox_messages_path } %>
 
-<h4><%= render :partial => "message_count" %></h4>
+<%= render :partial => "inbox_count" %>
 
 <% if current_user.messages.size > 0 %>
   <%= render :partial => "messages_table", :locals => { :columns => %w[from subject date], :messages => current_user.messages, :inner_partial => "message_summary" } %>
index 3403ac888e27210467629afc2dba0532c98e4c64..65bfd6a6b70a97d9c5e06107d0ee076ea4e86931 100644 (file)
@@ -1,2 +1,4 @@
 json.inboxanchor render(:partial => "layouts/inbox")
-json.inbox_count render(:partial => "message_count")
+json.inbox_count render(:partial => "inbox_count")
+json.outbox_count render(:partial => "outbox_count")
+json.muted_count render(:partial => "muted_count")
index 40c74e915762cb918a76233ff6faec6943528cdd..8e97abc7f2ff701d4cd9f67d266856cf7d36bc49 100644 (file)
@@ -4,6 +4,6 @@
 
 <%= render :partial => "heading", :locals => { :active_link_path => muted_messages_path } %>
 
-<h4><%= t ".messages", :count => current_user.muted_messages.size %></h4>
+<%= render :partial => "muted_count" %>
 
 <%= render :partial => "messages_table", :locals => { :columns => %w[from subject date], :messages => current_user.muted_messages, :inner_partial => "message_summary" } %>
index ae8a899c484850b7ab6ec52cc3425dc57a38be9e..65fbaf3261c818aa79613e6b6a3c6b546b69a9b3 100644 (file)
@@ -4,7 +4,7 @@
 
 <%= render :partial => "heading", :locals => { :active_link_path => outbox_messages_path } %>
 
-<h4><%= t ".messages", :count => current_user.sent_messages.size %></h4>
+<%= render :partial => "outbox_count" %>
 
 <% if current_user.sent_messages.size > 0 %>
   <%= render :partial => "messages_table", :locals => { :columns => %w[to subject date], :messages => current_user.sent_messages, :inner_partial => "sent_message_summary" } %>
diff --git a/test/system/messages_test.rb b/test/system/messages_test.rb
new file mode 100644 (file)
index 0000000..87021dd
--- /dev/null
@@ -0,0 +1,41 @@
+require "application_system_test_case"
+
+class NoteCommentsTest < ApplicationSystemTestCase
+  def test_delete_received_message
+    user = create(:user)
+    create(:message, :recipient => user)
+    sign_in_as(user)
+
+    visit inbox_messages_path
+    assert_text "You have 1 new message and 0 old messages"
+
+    click_button "Delete"
+    assert_text "You have 0 new messages and 0 old messages"
+  end
+
+  def test_delete_sent_message
+    user = create(:user)
+    create(:message, :sender => user)
+    sign_in_as(user)
+
+    visit outbox_messages_path
+    assert_text "You have 1 sent message"
+
+    click_button "Delete"
+    assert_text "You have 0 sent messages"
+  end
+
+  def test_delete_muted_message
+    user = create(:user)
+    muted_user = create(:user)
+    create(:user_mute, :owner => user, :subject => muted_user)
+    create(:message, :sender => muted_user, :recipient => user)
+    sign_in_as(user)
+
+    visit muted_messages_path
+    assert_text "1 muted message"
+
+    click_button "Delete"
+    assert_text "0 muted messages"
+  end
+end