From a9b57e571907731f406467072f88740fcfad6d63 Mon Sep 17 00:00:00 2001 From: Mantas Masalskis Date: Fri, 12 Nov 2021 14:35:39 +0100 Subject: [PATCH] Fixes #3825 - Reply all: Duplicate email on changing recipient and cc in a certain way --- .../app/lib/base/bootstrap-tokenfield.js | 5 ++++ spec/system/ticket/create_spec.rb | 29 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/app/assets/javascripts/app/lib/base/bootstrap-tokenfield.js b/app/assets/javascripts/app/lib/base/bootstrap-tokenfield.js index 08339f039..73d95b996 100644 --- a/app/assets/javascripts/app/lib/base/bootstrap-tokenfield.js +++ b/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) diff --git a/spec/system/ticket/create_spec.rb b/spec/system/ticket/create_spec.rb index f7eef74a4..cdecb5545 100644 --- a/spec/system/ticket/create_spec.rb +++ b/spec/system/ticket/create_spec.rb @@ -784,4 +784,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