formatting_helper_spec.rb 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe FormattingHelper do
  4. include Devise::Test::ControllerHelpers
  5. describe '#rss_status_content_format' do
  6. subject { helper.rss_status_content_format(status) }
  7. context 'with a simple status' do
  8. let(:status) { Fabricate.build :status, text: 'Hello world' }
  9. it 'renders the formatted elements' do
  10. expect(parsed_result.css('p').first.text)
  11. .to eq('Hello world')
  12. end
  13. end
  14. context 'with a spoiler and an emoji and a poll' do
  15. let(:status) { Fabricate(:status, text: 'Hello :world: <>', spoiler_text: 'This is a spoiler<>', poll: Fabricate(:poll, options: %w(Yes<> No))) }
  16. before { Fabricate :custom_emoji, shortcode: 'world' }
  17. it 'renders the formatted elements' do
  18. expect(spoiler_node.css('strong').text)
  19. .to eq('Content warning:')
  20. expect(spoiler_node.text)
  21. .to include('This is a spoiler<>')
  22. expect(content_node.text)
  23. .to eq('Hello <>')
  24. expect(content_node.css('img').first.to_h.symbolize_keys)
  25. .to include(
  26. rel: 'emoji',
  27. title: ':world:'
  28. )
  29. expect(poll_node.css('radio').first.text)
  30. .to eq('Yes<>')
  31. expect(poll_node.css('radio').first.to_h.symbolize_keys)
  32. .to include(
  33. disabled: 'disabled'
  34. )
  35. end
  36. def spoiler_node
  37. parsed_result.css('p').first
  38. end
  39. def content_node
  40. parsed_result.css('p')[1]
  41. end
  42. def poll_node
  43. parsed_result.css('p').last
  44. end
  45. end
  46. def parsed_result
  47. Nokogiri::HTML.fragment(subject)
  48. end
  49. end
  50. end