notification_factory_template_test.rb 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # rubocop:disable Lint/InterpolationCheck
  2. require 'test_helper'
  3. class NotificationFactoryTemplateTest < ActiveSupport::TestCase
  4. # RSpec incoming!
  5. def described_class
  6. NotificationFactory::Template
  7. end
  8. test 'regular browser html' do
  9. # ensures https://github.com/zammad/zammad/issues/385
  10. template_before = '#{<a href="http://ticket.id" title="http://ticket.id" target="_blank">ticket.id</a>}'
  11. template_after = '<%= d "ticket.id", true %>'
  12. result = described_class.new(template_before, true).to_s
  13. assert_equal(template_after, result)
  14. template_before = '#{<a href="http://ticket.id" title="http://ticket.id" target="_blank">config.fqdn</a>}'
  15. template_after = '<%= d "config.fqdn", true %>'
  16. result = described_class.new(template_before, true).to_s
  17. assert_equal(template_after, result)
  18. end
  19. test 'spaced browser html' do
  20. # ensures https://github.com/zammad/zammad/issues/385
  21. template_before = '#{ <a href="http://ticket.id" title="http://ticket.id" target="_blank">ticket.id </a> }'
  22. template_after = '<%= d "ticket.id", true %>'
  23. result = described_class.new(template_before, true).to_s
  24. assert_equal(template_after, result)
  25. end
  26. test 'broken browser html' do
  27. # ensures https://github.com/zammad/zammad/issues/385
  28. template_before = '#{<a href="http://ticket.id" title="http://ticket.id" target="_blank">ticket.id }'
  29. template_after = '<%= d "ticket.id", true %>'
  30. result = described_class.new(template_before, true).to_s
  31. assert_equal(template_after, result)
  32. end
  33. test 'empty tag' do
  34. template_before = '#{}'
  35. template_after = '<%= d "", true %>'
  36. result = described_class.new(template_before, true).to_s
  37. assert_equal(template_after, result)
  38. end
  39. test 'empty tag with space' do
  40. template_before = '#{ }'
  41. template_after = '<%= d "", false %>'
  42. result = described_class.new(template_before, false).to_s
  43. assert_equal(template_after, result)
  44. end
  45. test 'translation' do
  46. template_before = "\#{t('some text')}"
  47. template_after = '<%= t "some text", false %>'
  48. result = described_class.new(template_before, false).to_s
  49. assert_equal(template_after, result)
  50. template_before = "\#{t('some \"text\"')}"
  51. template_after = '<%= t "some \"text\"", false %>'
  52. result = described_class.new(template_before, false).to_s
  53. assert_equal(template_after, result)
  54. end
  55. end