2015-04-26 12:48:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe DiffHelper do
|
|
|
|
include RepoHelpers
|
|
|
|
|
|
|
|
let(:project) { create(:project) }
|
2016-01-29 22:53:50 +05:30
|
|
|
let(:repository) { project.repository }
|
2015-09-11 14:41:01 +05:30
|
|
|
let(:commit) { project.commit(sample_commit.id) }
|
|
|
|
let(:diffs) { commit.diffs }
|
|
|
|
let(:diff) { diffs.first }
|
2016-01-29 22:53:50 +05:30
|
|
|
let(:diff_refs) { [commit.parent, commit] }
|
|
|
|
let(:diff_file) { Gitlab::Diff::File.new(diff, diff_refs) }
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
describe 'diff_view' do
|
|
|
|
it 'returns a valid value when cookie is set' do
|
|
|
|
helper.request.cookies[:diff_view] = 'parallel'
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
expect(helper.diff_view).to eq 'parallel'
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
it 'returns a default value when cookie is invalid' do
|
|
|
|
helper.request.cookies[:diff_view] = 'invalid'
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
expect(helper.diff_view).to eq 'inline'
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
it 'returns a default value when cookie is nil' do
|
|
|
|
expect(helper.request.cookies).to be_empty
|
2015-09-11 14:41:01 +05:30
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
expect(helper.diff_view).to eq 'inline'
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
describe 'diff_hard_limit_enabled?' do
|
|
|
|
it 'should return true if param is provided' do
|
2015-09-11 14:41:01 +05:30
|
|
|
allow(controller).to receive(:params) { { force_show_diff: true } }
|
2016-06-02 11:05:42 +05:30
|
|
|
expect(diff_hard_limit_enabled?).to be_truthy
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
it 'should return false if param is not provided' do
|
|
|
|
expect(diff_hard_limit_enabled?).to be_falsey
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
2015-09-11 14:41:01 +05:30
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
describe 'diff_options' do
|
|
|
|
it 'should return hard limit for a diff if force diff is true' do
|
2015-09-11 14:41:01 +05:30
|
|
|
allow(controller).to receive(:params) { { force_show_diff: true } }
|
2016-06-02 11:05:42 +05:30
|
|
|
expect(diff_options).to include(Commit.max_diff_options)
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
it 'should return safe limit for a diff if force diff is false' do
|
|
|
|
expect(diff_options).not_to include(:max_lines, :max_files)
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'unfold_bottom_class' do
|
|
|
|
it 'should return empty string when bottom line shouldnt be unfolded' do
|
|
|
|
expect(unfold_bottom_class(false)).to eq('')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return js class when bottom lines should be unfolded' do
|
|
|
|
expect(unfold_bottom_class(true)).to eq('js-unfold-bottom')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-09-11 14:41:01 +05:30
|
|
|
describe 'unfold_class' do
|
|
|
|
it 'returns empty on false' do
|
|
|
|
expect(unfold_class(false)).to eq('')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a class on true' do
|
|
|
|
expect(unfold_class(true)).to eq('unfold js-unfold')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
describe '#diff_line_content' do
|
2015-04-26 12:48:37 +05:30
|
|
|
it 'should return non breaking space when line is empty' do
|
|
|
|
expect(diff_line_content(nil)).to eq(' ')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return the line itself' do
|
|
|
|
expect(diff_line_content(diff_file.diff_lines.first.text)).
|
|
|
|
to eq('@@ -6,12 +6,18 @@ module Popen')
|
|
|
|
expect(diff_line_content(diff_file.diff_lines.first.type)).to eq('match')
|
2016-01-29 22:53:50 +05:30
|
|
|
expect(diff_file.diff_lines.first.new_pos).to eq(6)
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe "#mark_inline_diffs" do
|
|
|
|
let(:old_line) { %{abc 'def'} }
|
|
|
|
let(:new_line) { %{abc "def"} }
|
|
|
|
|
|
|
|
it "returns strings with marked inline diffs" do
|
|
|
|
marked_old_line, marked_new_line = mark_inline_diffs(old_line, new_line)
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
expect(marked_old_line).to eq("abc <span class='idiff left right deletion'>'def'</span>")
|
2016-04-02 18:10:28 +05:30
|
|
|
expect(marked_old_line).to be_html_safe
|
2016-06-02 11:05:42 +05:30
|
|
|
expect(marked_new_line).to eq("abc <span class='idiff left right addition'>"def"</span>")
|
2016-04-02 18:10:28 +05:30
|
|
|
expect(marked_new_line).to be_html_safe
|
2016-01-29 22:53:50 +05:30
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
end
|