2016-07-10 20:10:59 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 14:24:02 +00:00
|
|
|
describe Gitlab::StringRangeMarker do
|
2016-07-10 20:10:59 +00:00
|
|
|
describe '#mark' do
|
|
|
|
context "when the rich text is html safe" do
|
|
|
|
let(:raw) { "abc <def>" }
|
|
|
|
let(:rich) { %{<span class="abc">abc</span><span class="space"> </span><span class="def"><def></span>}.html_safe }
|
|
|
|
let(:inline_diffs) { [2..5] }
|
2016-07-10 20:17:20 +00:00
|
|
|
subject do
|
2016-07-10 20:10:59 +00:00
|
|
|
described_class.new(raw, rich).mark(inline_diffs) do |text, left:, right:|
|
|
|
|
"LEFT#{text}RIGHT"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'marks the inline diffs' do
|
|
|
|
expect(subject).to eq(%{<span class="abc">abLEFTcRIGHT</span><span class="space">LEFT RIGHT</span><span class="def">LEFT<dRIGHTef></span>})
|
|
|
|
expect(subject).to be_html_safe
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the rich text is not html safe" do
|
|
|
|
let(:raw) { "abc <def>" }
|
|
|
|
let(:inline_diffs) { [2..5] }
|
2016-07-10 20:17:20 +00:00
|
|
|
subject do
|
2016-07-10 20:10:59 +00:00
|
|
|
described_class.new(raw).mark(inline_diffs) do |text, left:, right:|
|
|
|
|
"LEFT#{text}RIGHT"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'marks the inline diffs' do
|
|
|
|
expect(subject).to eq(%{abLEFTc <dRIGHTef>})
|
|
|
|
expect(subject).to be_html_safe
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|