blob: 7ed43db3d100eb43c553b3604760577dc1c91d86 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::StringRangeMarker do
describe '#mark' do
def mark_diff(rich = nil)
raw = 'abc <def>'
inline_diffs = [2..5]
described_class.new(raw, rich).mark(inline_diffs) do |text, left:, right:|
"LEFT#{text}RIGHT"
end
end
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
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
end
end
context "when the rich text is not html safe" do
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
end
end
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
end
end
end
end
|