2022-12-15 16:39:41 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
2024-09-04 07:12:25 +02:00
|
|
|
RSpec.describe FormattingHelper do
|
2022-12-15 16:39:41 +01:00
|
|
|
include Devise::Test::ControllerHelpers
|
|
|
|
|
|
|
|
describe '#rss_status_content_format' do
|
2024-10-15 16:12:54 +02:00
|
|
|
subject { helper.rss_status_content_format(status) }
|
2022-12-15 16:39:41 +01:00
|
|
|
|
2024-10-15 16:12:54 +02:00
|
|
|
context 'with a simple status' do
|
|
|
|
let(:status) { Fabricate.build :status, text: 'Hello world' }
|
|
|
|
|
|
|
|
it 'renders the formatted elements' do
|
|
|
|
expect(parsed_result.css('p').first.text)
|
|
|
|
.to eq('Hello world')
|
|
|
|
end
|
2022-12-15 16:39:41 +01:00
|
|
|
end
|
|
|
|
|
2024-10-15 16:12:54 +02:00
|
|
|
context 'with a spoiler and an emoji and a poll' do
|
|
|
|
let(:status) { Fabricate(:status, text: 'Hello :world: <>', spoiler_text: 'This is a spoiler<>', poll: Fabricate(:poll, options: %w(Yes<> No))) }
|
|
|
|
|
|
|
|
before { Fabricate :custom_emoji, shortcode: 'world' }
|
|
|
|
|
|
|
|
it 'renders the formatted elements' do
|
|
|
|
expect(spoiler_node.css('strong').text)
|
|
|
|
.to eq('Content warning:')
|
|
|
|
expect(spoiler_node.text)
|
|
|
|
.to include('This is a spoiler<>')
|
|
|
|
expect(content_node.text)
|
|
|
|
.to eq('Hello <>')
|
|
|
|
expect(content_node.css('img').first.to_h.symbolize_keys)
|
|
|
|
.to include(
|
|
|
|
rel: 'emoji',
|
|
|
|
title: ':world:'
|
|
|
|
)
|
|
|
|
expect(poll_node.css('radio').first.text)
|
|
|
|
.to eq('Yes<>')
|
|
|
|
expect(poll_node.css('radio').first.to_h.symbolize_keys)
|
|
|
|
.to include(
|
|
|
|
disabled: 'disabled'
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def spoiler_node
|
|
|
|
parsed_result.css('p').first
|
|
|
|
end
|
|
|
|
|
|
|
|
def content_node
|
|
|
|
parsed_result.css('p')[1]
|
|
|
|
end
|
|
|
|
|
|
|
|
def poll_node
|
|
|
|
parsed_result.css('p').last
|
|
|
|
end
|
2022-12-15 16:39:41 +01:00
|
|
|
end
|
|
|
|
|
2024-10-15 16:12:54 +02:00
|
|
|
def parsed_result
|
|
|
|
Nokogiri::HTML.fragment(subject)
|
2022-12-15 16:39:41 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|