2019-08-22 10:57:44 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-07-10 20:10:59 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 18:09:03 +00:00
|
|
|
RSpec.describe Gitlab::StringRangeMarker do
|
2016-07-10 20:10:59 +00:00
|
|
|
describe '#mark' do
|
2017-08-15 05:09:05 +00:00
|
|
|
def mark_diff(rich = nil)
|
|
|
|
raw = 'abc <def>'
|
|
|
|
inline_diffs = [2..5]
|
|
|
|
|
2021-03-11 15:09:10 +00:00
|
|
|
described_class.new(raw, rich).mark(inline_diffs) do |text, left:, right:, mode:|
|
2019-11-26 15:06:50 +00:00
|
|
|
"LEFT#{text}RIGHT".html_safe
|
2017-08-15 05:09:05 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-10 20:10:59 +00:00
|
|
|
context "when the rich text is html safe" do
|
|
|
|
let(:rich) { %{<span class="abc">abc</span><span class="space"> </span><span class="def"><def></span>}.html_safe }
|
|
|
|
|
|
|
|
it 'marks the inline diffs' do
|
2017-08-15 05:09:05 +00:00
|
|
|
expect(mark_diff(rich)).to eq(%{<span class="abc">abLEFTcRIGHT</span><span class="space">LEFT RIGHT</span><span class="def">LEFT<dRIGHTef></span>})
|
|
|
|
expect(mark_diff(rich)).to be_html_safe
|
2016-07-10 20:10:59 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the rich text is not html safe" do
|
2017-08-15 05:09:05 +00:00
|
|
|
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
|
2016-07-10 20:10:59 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-15 05:09:05 +00:00
|
|
|
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 <dRIGHTef> differs})
|
|
|
|
expect(mark_diff(rich)).to be_html_safe
|
|
|
|
end
|
2016-07-10 20:10:59 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|