statuses_helper_spec.rb 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe Admin::Trends::StatusesHelper do
  4. describe '.one_line_preview' do
  5. before do
  6. allow(helper).to receive(:current_user).and_return(Fabricate.build(:user))
  7. end
  8. context 'with a local status' do
  9. let(:status) { Fabricate.build(:status, text: 'Test local status') }
  10. it 'renders a correct preview text' do
  11. result = helper.one_line_preview(status)
  12. expect(result).to eq 'Test local status'
  13. end
  14. end
  15. context 'with a remote status' do
  16. let(:status) { Fabricate.build(:status, uri: 'https://sfd.sdf', text: '<html><body><p>Test remote status</p><p>text</p></body></html>') }
  17. it 'renders a correct preview text' do
  18. result = helper.one_line_preview(status)
  19. expect(result).to eq 'Test remote status'
  20. end
  21. end
  22. context 'with a status that has empty text' do
  23. let(:status) { Fabricate.build(:status, text: '') }
  24. it 'renders a correct preview text' do
  25. result = helper.one_line_preview(status)
  26. expect(result).to eq ''
  27. end
  28. end
  29. context 'with a status that has emoji' do
  30. before { Fabricate(:custom_emoji, shortcode: 'florpy') }
  31. let(:status) { Fabricate(:status, text: 'hello there :florpy:') }
  32. it 'renders a correct preview text' do
  33. result = helper.one_line_preview(status)
  34. expect(result).to match 'hello there'
  35. expect(result).to match '<img rel="emoji"'
  36. end
  37. end
  38. end
  39. end