Browse Source

Fixes #5118 - Article notes text is greyed out

Mantas Masalskis 11 months ago
parent
commit
affaf7aff7

+ 7 - 3
app/assets/javascripts/app/controllers/ticket_zoom/article_new.coffee

@@ -880,13 +880,17 @@ class App.TicketZoomArticleNew extends App.Controller
     file.type || file.contentType || file.preferences?['Content-Type'] || file.preferences?['Mime-Type']
 
   checkBodyEnsureNoCaption: =>
-    @bodyEnsureNoCaption?(@attachments.map (file) => @attachmentContentType(file))
+    return false if !@bodyEnsureNoCaption
+
+    @bodyEnsureNoCaption(@attachments.map (file) => @attachmentContentType(file))
 
   checkBodyAllowNoCaption: =>
-    @bodyAllowNoCaption?(@attachments)
+    return false if !@bodyAllowNoCaption
+
+    @bodyAllowNoCaption(@attachments)
 
   checkBodyAllowEmpty: =>
-    !!@checkBodyEnsureNoCaption() || @checkBodyAllowNoCaption()
+    @checkBodyEnsureNoCaption() || @checkBodyAllowNoCaption()
 
   evaluateAttachmentsList: =>
     @toggleBodyEnsureNoCaption @checkBodyEnsureNoCaption()

+ 37 - 0
spec/system/ticket/zoom/whatsapp_reply_spec.rb

@@ -63,6 +63,8 @@ RSpec.describe 'Ticket Zoom > Whatsapp reply', :use_vcr, authenticated_as: :user
         within first('.attachment--row') do |elem|
           elem.execute_script('$(".attachment-delete", this).trigger("click")')
         end
+
+        expect(page).to have_no_text('Only 1 attachment allowed')
       end
     end
 
@@ -88,6 +90,41 @@ RSpec.describe 'Ticket Zoom > Whatsapp reply', :use_vcr, authenticated_as: :user
     end
   end
 
+  describe 'caption disabling' do
+    let(:audio_file) do
+      # Tempfile does not work, because it appends auto-generated extension and breaks mimetype check
+      tmp_file_path = Rails.root.join('tmp', "#{SecureRandom.uuid}.mp3")
+
+      file = File.new(tmp_file_path, 'w')
+      file.write(sample_text)
+      file.close
+
+      file
+    end
+
+    after { File.unlink audio_file.path }
+
+    it 'disables caption when specific Whatsapp attachment is present' do
+      within(:active_content) do
+        find(:richtext).send_keys(sample_text)
+        expect(find(:richtext)).to not_match_css('.text-muted')
+
+        find('input#fileUpload_1', visible: :all).set(audio_file.path)
+
+        click '.js-selectableTypes'
+        click '.js-articleTypeItem[data-value="whatsapp message"]'
+
+        expect(find(:richtext)).to match_css('.text-muted')
+
+        within first('.attachment--row') do |elem|
+          elem.execute_script('$(".attachment-delete", this).trigger("click")')
+        end
+
+        expect(find(:richtext)).to not_match_css('.text-muted')
+      end
+    end
+  end
+
   describe 'with the customer service window information' do
     let(:article) do
       create(:whatsapp_article,