statuses_helper_spec.rb 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe StatusesHelper do
  4. describe 'status_text_summary' do
  5. context 'with blank text' do
  6. let(:status) { Status.new(spoiler_text: '') }
  7. it 'returns immediately with nil' do
  8. result = helper.status_text_summary(status)
  9. expect(result).to be_nil
  10. end
  11. end
  12. context 'with present text' do
  13. let(:status) { Status.new(spoiler_text: 'SPOILERS!!!') }
  14. it 'returns the content warning' do
  15. result = helper.status_text_summary(status)
  16. expect(result).to eq(I18n.t('statuses.content_warning', warning: 'SPOILERS!!!'))
  17. end
  18. end
  19. end
  20. def status_text_summary(status)
  21. return if status.spoiler_text.blank?
  22. I18n.t('statuses.content_warning', warning: status.spoiler_text)
  23. end
  24. describe 'link_to_newer' do
  25. it 'returns a link to newer content' do
  26. url = 'https://example.com'
  27. result = helper.link_to_newer(url)
  28. expect(result).to match('load-more')
  29. expect(result).to match(I18n.t('statuses.show_newer'))
  30. end
  31. end
  32. describe 'link_to_older' do
  33. it 'returns a link to older content' do
  34. url = 'https://example.com'
  35. result = helper.link_to_older(url)
  36. expect(result).to match('load-more')
  37. expect(result).to match(I18n.t('statuses.show_older'))
  38. end
  39. end
  40. describe 'fa_visibility_icon' do
  41. context 'with a status that is public' do
  42. let(:status) { Status.new(visibility: 'public') }
  43. it 'returns the correct fa icon' do
  44. result = helper.fa_visibility_icon(status)
  45. expect(result).to match('fa-globe')
  46. end
  47. end
  48. context 'with a status that is unlisted' do
  49. let(:status) { Status.new(visibility: 'unlisted') }
  50. it 'returns the correct fa icon' do
  51. result = helper.fa_visibility_icon(status)
  52. expect(result).to match('fa-unlock')
  53. end
  54. end
  55. context 'with a status that is private' do
  56. let(:status) { Status.new(visibility: 'private') }
  57. it 'returns the correct fa icon' do
  58. result = helper.fa_visibility_icon(status)
  59. expect(result).to match('fa-lock')
  60. end
  61. end
  62. context 'with a status that is direct' do
  63. let(:status) { Status.new(visibility: 'direct') }
  64. it 'returns the correct fa icon' do
  65. result = helper.fa_visibility_icon(status)
  66. expect(result).to match('fa-at')
  67. end
  68. end
  69. end
  70. describe '#stream_link_target' do
  71. it 'returns nil if it is not an embedded view' do
  72. set_not_embedded_view
  73. expect(helper.stream_link_target).to be_nil
  74. end
  75. it 'returns _blank if it is an embedded view' do
  76. set_embedded_view
  77. expect(helper.stream_link_target).to eq '_blank'
  78. end
  79. end
  80. def set_not_embedded_view
  81. params[:controller] = "not_#{StatusesHelper::EMBEDDED_CONTROLLER}"
  82. params[:action] = "not_#{StatusesHelper::EMBEDDED_ACTION}"
  83. end
  84. def set_embedded_view
  85. params[:controller] = StatusesHelper::EMBEDDED_CONTROLLER
  86. params[:action] = StatusesHelper::EMBEDDED_ACTION
  87. end
  88. end