# frozen_string_literal: true require 'rails_helper' RSpec.describe PlainTextFormatter do describe '#to_s' do subject { described_class.new(status.text, status.local?).to_s } context 'when status is local' do let(:status) { Fabricate(:status, text: '

a text by a nerd who uses an HTML tag in text

', uri: nil) } it 'returns the raw text' do expect(subject).to eq '

a text by a nerd who uses an HTML tag in text

' end end context 'when status is remote' do let(:remote_account) { Fabricate(:account, domain: 'remote.test', username: 'bob', url: 'https://remote.test/') } context 'when text contains inline HTML tags' do let(:status) { Fabricate(:status, account: remote_account, text: 'Lorem ipsum') } it 'strips the tags' do expect(subject).to eq 'Lorem ipsum' end end context 'when text contains

tags' do let(:status) { Fabricate(:status, account: remote_account, text: '

Lorem

ipsum

') } it 'inserts a newline' do expect(subject).to eq "Lorem\nipsum" end end context 'when text contains a single
tag' do let(:status) { Fabricate(:status, account: remote_account, text: 'Lorem
ipsum') } it 'inserts a newline' do expect(subject).to eq "Lorem\nipsum" end end context 'when text contains consecutive
tag' do let(:status) { Fabricate(:status, account: remote_account, text: 'Lorem


ipsum') } it 'inserts a single newline' do expect(subject).to eq "Lorem\nipsum" end end context 'when text contains HTML entity' do let(:status) { Fabricate(:status, account: remote_account, text: 'Lorem & ipsum ❤') } it 'unescapes the entity' do expect(subject).to eq 'Lorem & ipsum ❤' end end context 'when text contains ipsum') } it 'strips the tag and its contents' do expect(subject).to eq 'Lorem ipsum' end end context 'when text contains an HTML comment tags' do let(:status) { Fabricate(:status, account: remote_account, text: 'Lorem ipsum') } it 'strips the comment' do expect(subject).to eq 'Lorem ipsum' end end context 'when text contains HTML ruby tags' do let(:status) { Fabricate(:status, account: remote_account, text: '

Lorem 明日 (Ashita) ipsum

') } it 'strips the comment' do expect(subject).to eq 'Lorem 明日 (Ashita) ipsum' end end end end end