statuses_helper_spec.rb 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 'fa_visibility_icon' do
  25. context 'with a status that is public' do
  26. let(:status) { Status.new(visibility: 'public') }
  27. it 'returns the correct fa icon' do
  28. result = helper.fa_visibility_icon(status)
  29. expect(result).to match('fa-globe')
  30. end
  31. end
  32. context 'with a status that is unlisted' do
  33. let(:status) { Status.new(visibility: 'unlisted') }
  34. it 'returns the correct fa icon' do
  35. result = helper.fa_visibility_icon(status)
  36. expect(result).to match('fa-unlock')
  37. end
  38. end
  39. context 'with a status that is private' do
  40. let(:status) { Status.new(visibility: 'private') }
  41. it 'returns the correct fa icon' do
  42. result = helper.fa_visibility_icon(status)
  43. expect(result).to match('fa-lock')
  44. end
  45. end
  46. context 'with a status that is direct' do
  47. let(:status) { Status.new(visibility: 'direct') }
  48. it 'returns the correct fa icon' do
  49. result = helper.fa_visibility_icon(status)
  50. expect(result).to match('fa-at')
  51. end
  52. end
  53. end
  54. describe '#stream_link_target' do
  55. it 'returns nil if it is not an embedded view' do
  56. set_not_embedded_view
  57. expect(helper.stream_link_target).to be_nil
  58. end
  59. it 'returns _blank if it is an embedded view' do
  60. set_embedded_view
  61. expect(helper.stream_link_target).to eq '_blank'
  62. end
  63. end
  64. def set_not_embedded_view
  65. params[:controller] = "not_#{StatusesHelper::EMBEDDED_CONTROLLER}"
  66. params[:action] = "not_#{StatusesHelper::EMBEDDED_ACTION}"
  67. end
  68. def set_embedded_view
  69. params[:controller] = StatusesHelper::EMBEDDED_CONTROLLER
  70. params[:action] = StatusesHelper::EMBEDDED_ACTION
  71. end
  72. end