diff --git a/app/assets/javascripts/app/controllers/ticket_zoom/article_view.coffee b/app/assets/javascripts/app/controllers/ticket_zoom/article_view.coffee
index de76f2f04..e4a8ccd7e 100644
--- a/app/assets/javascripts/app/controllers/ticket_zoom/article_view.coffee
+++ b/app/assets/javascripts/app/controllers/ticket_zoom/article_view.coffee
@@ -483,6 +483,10 @@ class ArticleViewItem extends App.ControllerObserver
@el.remove()
imageView: (e) ->
+ # take care of images surrounded by a link
+ if e.target && e.target.parentNode && e.target.parentNode.nodeName.toLowerCase() == 'a'
+ return false
+
e.preventDefault()
e.stopPropagation()
new App.TicketZoomArticleImageView(image: $(e.target).get(0).outerHTML, parentElement: $(e.currentTarget))
diff --git a/spec/system/ticket/zoom_spec.rb b/spec/system/ticket/zoom_spec.rb
index fbee57549..32cecfe3c 100644
--- a/spec/system/ticket/zoom_spec.rb
+++ b/spec/system/ticket/zoom_spec.rb
@@ -2613,4 +2613,56 @@ RSpec.describe 'Ticket zoom', type: :system do
expect(ticket.reload.customer_id).to eq(User.find_by(email: 'admin@example.com').id)
end
end
+
+ describe 'Image preview #4044' do
+ let(:ticket) { create(:ticket, group: Group.find_by(name: 'Users')) }
+
+ let(:image_as_base64) do
+ file = File.binread(Rails.root.join('spec/fixtures/files/image/squares.png'))
+ Base64.encode64(file).delete("\n")
+ end
+
+ let(:body) do
+ "
"
+ end
+
+ let(:article) { create(:ticket_article, ticket: ticket, body: body, content_type: 'text/html') }
+
+ before do
+ visit "#ticket/zoom/#{ticket.id}"
+ end
+
+ it 'does open the image preview for a common image' do
+ within :active_ticket_article, article do
+ find('img').click
+ end
+
+ in_modal do
+ expect(page).to have_css('div.imagePreview img')
+ expect(page).to have_css('.js-cancel')
+ expect(page).to have_css('.js-submit')
+
+ page.find('.js-cancel').click
+ end
+ end
+
+ context 'with image and embedded link' do
+ let(:body) do
+ "
+
+
"
+ end
+
+ it 'does open the link for an image with an embedded link' do
+ within :active_ticket_article, article do
+ find('img').click
+ end
+
+ within_window switch_to_window_index(2) do
+ expect(page).to have_css('a.logo')
+ end
+ close_window_index(2)
+ end
+ end
+ end
end