statuses_helper_spec.rb 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.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. describe '#media_summary' do
  21. it 'describes the media on a status' do
  22. status = Fabricate :status
  23. Fabricate :media_attachment, status: status, type: :video
  24. Fabricate :media_attachment, status: status, type: :audio
  25. Fabricate :media_attachment, status: status, type: :image
  26. result = helper.media_summary(status)
  27. expect(result).to eq('Attached: 1 image · 1 video · 1 audio')
  28. end
  29. end
  30. describe 'visibility_icon' do
  31. context 'with a status that is public' do
  32. let(:status) { Status.new(visibility: 'public') }
  33. it 'returns the correct fa icon' do
  34. result = helper.visibility_icon(status)
  35. expect(result).to match('globe')
  36. end
  37. end
  38. context 'with a status that is unlisted' do
  39. let(:status) { Status.new(visibility: 'unlisted') }
  40. it 'returns the correct fa icon' do
  41. result = helper.visibility_icon(status)
  42. expect(result).to match('lock_open')
  43. end
  44. end
  45. context 'with a status that is private' do
  46. let(:status) { Status.new(visibility: 'private') }
  47. it 'returns the correct fa icon' do
  48. result = helper.visibility_icon(status)
  49. expect(result).to match('lock')
  50. end
  51. end
  52. context 'with a status that is direct' do
  53. let(:status) { Status.new(visibility: 'direct') }
  54. it 'returns the correct fa icon' do
  55. result = helper.visibility_icon(status)
  56. expect(result).to match('alternate_email')
  57. end
  58. end
  59. end
  60. describe '#stream_link_target' do
  61. it 'returns nil if it is not an embedded view' do
  62. set_not_embedded_view
  63. expect(helper.stream_link_target).to be_nil
  64. end
  65. it 'returns _blank if it is an embedded view' do
  66. set_embedded_view
  67. expect(helper.stream_link_target).to eq '_blank'
  68. end
  69. end
  70. def set_not_embedded_view
  71. params[:controller] = "not_#{StatusesHelper::EMBEDDED_CONTROLLER}"
  72. params[:action] = "not_#{StatusesHelper::EMBEDDED_ACTION}"
  73. end
  74. def set_embedded_view
  75. params[:controller] = StatusesHelper::EMBEDDED_CONTROLLER
  76. params[:action] = StatusesHelper::EMBEDDED_ACTION
  77. end
  78. end