Browse Source

Fixes #3825 - Reply all: Duplicate email on changing recipient and cc in a certain way

Mantas Masalskis 3 years ago
parent
commit
6a6b19b4e6

+ 5 - 0
app/assets/javascripts/app/lib/base/bootstrap-tokenfield.js

@@ -654,6 +654,11 @@
       var tokensBefore = this.getTokensList()
       this.setTokens( this.$input.val(), true )
 
+      // remove token text was cleared while editing
+      if (this.$input.data( 'edit' ) && !this.$input.val()) {
+        this.$element.val( this.getTokensList() )
+      }
+
       if (tokensBefore == this.getTokensList() && this.$input.val().length)
         return false // No tokens were added, do nothing (prevent form submit)
 

+ 29 - 0
spec/system/ticket/create_spec.rb

@@ -833,4 +833,33 @@ RSpec.describe 'Ticket Create', type: :system do
       expect(page.all('select[name=owner_id] option').count).to eq(1)
     end
   end
+
+  # https://github.com/zammad/zammad/issues/3825
+  describe 'CC token field' do
+    before do
+      visit 'ticket/create'
+
+      find('[data-type=email-out]').click
+    end
+
+    it 'can be cleared by cutting out text' do
+      add_email 'asd@example.com'
+      add_email 'def@example.com'
+
+      find('.token', text: 'def@example.com').double_click
+
+      meta_key = Gem::Platform.local.os == 'darwin' ? :command : :control
+      send_keys([meta_key, 'x'])
+
+      find('.token').click # trigger blur
+
+      expect(find('[name="cc"]', visible: :all).value).to eq 'asd@example.com'
+    end
+
+    def add_email(input)
+      fill_in 'Cc', with: input
+      send_keys(:enter) # trigger blur
+      find '.token', text: input # wait for email to tokenize
+    end
+  end
 end