debian-mirror-gitlab/spec/lib/gitlab/string_range_marker_spec.rb

44 lines
1.3 KiB
Ruby
Raw Normal View History

2019-12-04 20:38:33 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::StringRangeMarker do
2017-09-10 17:25:29 +05:30
describe '#mark' do
2018-03-17 18:26:18 +05:30
def mark_diff(rich = nil)
raw = 'abc <def>'
inline_diffs = [2..5]
2021-04-17 20:07:23 +05:30
described_class.new(raw, rich).mark(inline_diffs) do |text, left:, right:, mode:|
2020-01-01 13:55:28 +05:30
"LEFT#{text}RIGHT".html_safe
2018-03-17 18:26:18 +05:30
end
end
2017-09-10 17:25:29 +05:30
context "when the rich text is html safe" do
let(:rich) { %{<span class="abc">abc</span><span class="space"> </span><span class="def">&lt;def&gt;</span>}.html_safe }
it 'marks the inline diffs' do
2018-03-17 18:26:18 +05:30
expect(mark_diff(rich)).to eq(%{<span class="abc">abLEFTcRIGHT</span><span class="space">LEFT RIGHT</span><span class="def">LEFT&lt;dRIGHTef&gt;</span>})
expect(mark_diff(rich)).to be_html_safe
2017-09-10 17:25:29 +05:30
end
end
context "when the rich text is not html safe" do
2018-03-17 18:26:18 +05:30
context 'when rich text equals raw text' do
it 'marks the inline diffs' do
expect(mark_diff).to eq(%{abLEFTc <dRIGHTef>})
expect(mark_diff).not_to be_html_safe
2017-09-10 17:25:29 +05:30
end
end
2018-03-17 18:26:18 +05:30
context 'when rich text doeas not equal raw text' do
let(:rich) { "abc <def> differs" }
it 'marks the inline diffs' do
expect(mark_diff(rich)).to eq(%{abLEFTc &lt;dRIGHTef&gt; differs})
expect(mark_diff(rich)).to be_html_safe
end
2017-09-10 17:25:29 +05:30
end
end
end
end