Welcome to mirror list, hosted at ThFree Co, Russian Federation.

string_range_marker_spec.rb « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 45b4d4af20613b81b2e5389e4bf87383e01666b0 (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
require 'spec_helper'

describe Gitlab::StringRangeMarker, lib: true do
  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">&lt;def&gt;</span>}.html_safe }
      let(:inline_diffs) { [2..5] }
      let(:subject) do
        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&lt;dRIGHTef&gt;</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] }
      let(:subject) do
        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 &lt;dRIGHTef&gt;})
        expect(subject).to be_html_safe
      end
    end
  end
end