media_component_helper_spec.rb 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe MediaComponentHelper do
  4. before { helper.extend controller_helpers }
  5. describe 'render_video_component' do
  6. let(:media) { Fabricate(:media_attachment, type: :video, status: Fabricate(:status)) }
  7. let(:result) { helper.render_video_component(media.status) }
  8. it 'renders a react component for the video' do
  9. expect(parsed_html.div['data-component']).to eq('Video')
  10. end
  11. end
  12. describe 'render_audio_component' do
  13. let(:media) { Fabricate(:media_attachment, type: :audio, status: Fabricate(:status)) }
  14. let(:result) { helper.render_audio_component(media.status) }
  15. it 'renders a react component for the audio' do
  16. expect(parsed_html.div['data-component']).to eq('Audio')
  17. end
  18. end
  19. describe 'render_media_gallery_component' do
  20. let(:media) { Fabricate(:media_attachment, type: :audio, status: Fabricate(:status)) }
  21. let(:result) { helper.render_media_gallery_component(media.status) }
  22. it 'renders a react component for the media gallery' do
  23. expect(parsed_html.div['data-component']).to eq('MediaGallery')
  24. end
  25. end
  26. describe 'render_card_component' do
  27. let(:status) { Fabricate(:status) }
  28. let(:result) { helper.render_card_component(status) }
  29. before do
  30. PreviewCardsStatus.create(status: status, preview_card: Fabricate(:preview_card))
  31. end
  32. it 'returns the correct react component markup' do
  33. expect(parsed_html.div['data-component']).to eq('Card')
  34. end
  35. end
  36. describe 'render_poll_component' do
  37. let(:status) { Fabricate(:status, poll: Fabricate(:poll)) }
  38. let(:result) { helper.render_poll_component(status) }
  39. it 'returns the correct react component markup' do
  40. expect(parsed_html.div['data-component']).to eq('Poll')
  41. end
  42. end
  43. private
  44. def parsed_html
  45. Nokogiri::Slop(result)
  46. end
  47. def controller_helpers
  48. Module.new do
  49. def current_account = Account.last
  50. end
  51. end
  52. end