inline_image_adjustments_spec.rb 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Channel::EmailBuild > Inline Images Adjustments', aggregate_failures: true, type: :model do
  4. let(:html_body) do
  5. <<~HTML.chomp
  6. <!DOCTYPE html>
  7. <html>
  8. <head>
  9. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  10. </head>
  11. <body style="font-family:Geneva,Helvetica,Arial,sans-serif; font-size: 12px;">
  12. <img style="width: 125px; max-width: 100%; height: 187.5px;" src="cid:1.e83460e9-7e36-48f7-97db-dc7f0ba7c51f@zammad.example.com">
  13. <br><br>
  14. <div data-signature="true" data-signature-id="1">
  15. Test Admin Agent<br><br>
  16. --<br>
  17. Super Support - Waterford Business Park<br>
  18. 5201 Blue Lagoon Drive - 8th Floor &amp; 9th Floor - Miami, 33126 USA<br>
  19. Email: hot@example.com - Web: <a href="http://www.example.com/" rel="nofollow noreferrer noopener" target="_blank">http://www.example.com/</a><br>
  20. --
  21. </div>
  22. </body>
  23. </html>
  24. HTML
  25. end
  26. let(:mail) do
  27. Channel::EmailBuild.build(
  28. from: 'sender@example.com',
  29. to: 'recipient@example.com',
  30. body: html_body,
  31. content_type: 'text/html',
  32. )
  33. end
  34. context 'when an email is built with inline images' do
  35. it 'adjusts the inline images width and height' do
  36. expect(mail.html_part.body.to_s).to include('<!DOCTYPE html>')
  37. expect(mail.html_part.body.to_s).to include('font-family:Geneva,Helvetica,Arial,sans-serif; font-size: 12px;')
  38. expect(mail.html_part.body.to_s).to include('<img style="width: 125px; max-width: 100%; height: 187.5px;" src="cid:1.e83460e9-7e36-48f7-97db-dc7f0ba7c51f@zammad.example.com" height="187.5" width="125">')
  39. end
  40. end
  41. context 'when no complete HTML document is provided' do
  42. let(:html_body) do
  43. <<~HTML.chomp
  44. <img style="width: 125px; max-width: 100%; height: 187.5px;" src="cid:1.e83460e9-7e36-48f7-97db-dc7f0ba7c51f@zammad.example.com">
  45. <br><br>
  46. <div data-signature="true" data-signature-id="1">
  47. Test Admin Agent<br><br>
  48. --<br>
  49. Super Support - Waterford Business Park<br>
  50. 5201 Blue Lagoon Drive - 8th Floor &amp; 9th Floor - Miami, 33126 USA<br>
  51. Email: hot@example.com - Web: <a href="http://www.example.com/" rel="nofollow noreferrer noopener" target="_blank">http://www.example.com/</a><br>
  52. --
  53. </div>
  54. HTML
  55. end
  56. it 'completes the HTML document and adjusts the inline images width and height' do
  57. expect(mail.html_part.body.to_s).to include('<!DOCTYPE html>')
  58. expect(mail.html_part.body.to_s).to include("font-family:'Helvetica Neue', Helvetica, Arial, Geneva, sans-serif; font-size: 12px;")
  59. expect(mail.html_part.body.to_s).to include('<img style="width: 125px; max-width: 100%; height: 187.5px;" src="cid:1.e83460e9-7e36-48f7-97db-dc7f0ba7c51f@zammad.example.com" height="187.5" width="125">')
  60. end
  61. end
  62. end