2019-07-25 05:24:42 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-08-29 07:56:52 +00:00
|
|
|
require 'spec_helper'
|
2016-07-27 14:55:12 +00:00
|
|
|
|
2020-06-16 18:09:01 +00:00
|
|
|
RSpec.describe 'Merge request > User sees versions', :js do
|
2022-02-15 15:15:04 +00:00
|
|
|
include MergeRequestDiffHelpers
|
|
|
|
|
2019-03-04 18:36:34 +00:00
|
|
|
let(:merge_request) do
|
|
|
|
create(:merge_request).tap do |mr|
|
2020-08-10 18:09:54 +00:00
|
|
|
mr.merge_request_diff.destroy!
|
2019-03-04 18:36:34 +00:00
|
|
|
end
|
|
|
|
end
|
2020-08-11 03:11:00 +00:00
|
|
|
|
2016-10-01 07:32:21 +00:00
|
|
|
let(:project) { merge_request.source_project }
|
2017-08-01 18:03:07 +00:00
|
|
|
let(:user) { project.creator }
|
2020-08-10 18:09:54 +00:00
|
|
|
let!(:merge_request_diff1) { merge_request.merge_request_diffs.create!(head_commit_sha: '6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9') }
|
|
|
|
let!(:merge_request_diff2) { merge_request.merge_request_diffs.create!(head_commit_sha: nil) }
|
|
|
|
let!(:merge_request_diff3) { merge_request.merge_request_diffs.create!(head_commit_sha: '5937ac0a7beb003549fc5fd26fc247adbce4a52e') }
|
2017-08-01 18:03:07 +00:00
|
|
|
let!(:params) { {} }
|
2016-10-01 07:32:21 +00:00
|
|
|
|
2016-07-27 14:55:12 +00:00
|
|
|
before do
|
2018-07-11 14:36:08 +00:00
|
|
|
project.add_maintainer(user)
|
2017-08-01 18:03:07 +00:00
|
|
|
sign_in(user)
|
2017-12-01 19:08:30 +00:00
|
|
|
visit diffs_project_merge_request_path(project, merge_request, params)
|
2016-07-27 14:55:12 +00:00
|
|
|
end
|
|
|
|
|
2022-07-19 09:08:45 +00:00
|
|
|
shared_examples 'allows commenting' do |file_name:, line_text:, comment:|
|
2017-12-01 19:08:30 +00:00
|
|
|
it do
|
2022-07-19 09:08:45 +00:00
|
|
|
page.within find_by_scrolling('.diff-file', text: file_name) do
|
|
|
|
line_code_element = page.find('.diff-grid-row', text: line_text)
|
2017-12-01 19:08:30 +00:00
|
|
|
|
2022-02-15 15:15:04 +00:00
|
|
|
# scrolling to element's bottom is required in order for .hover action to work
|
|
|
|
# otherwise, the element could be hidden underneath a sticky header
|
|
|
|
scroll_to_elements_bottom(line_code_element)
|
|
|
|
line_code_element.hover
|
2022-07-19 09:08:45 +00:00
|
|
|
page.find("[data-testid='left-comment-button']", visible: true).click
|
2017-12-01 19:08:30 +00:00
|
|
|
|
2022-07-19 09:08:45 +00:00
|
|
|
expect(page).to have_selector("form", count: 1)
|
|
|
|
|
|
|
|
fill_in("note[note]", with: comment)
|
|
|
|
click_button('Add comment now')
|
2017-12-01 19:08:30 +00:00
|
|
|
|
|
|
|
wait_for_requests
|
|
|
|
|
|
|
|
expect(page).to have_content(comment)
|
|
|
|
end
|
2016-07-27 14:55:12 +00:00
|
|
|
end
|
2017-12-01 19:08:30 +00:00
|
|
|
end
|
2016-07-27 14:55:12 +00:00
|
|
|
|
2017-12-01 19:08:30 +00:00
|
|
|
describe 'compare with the latest version' do
|
|
|
|
it 'show the latest version of the diff' do
|
|
|
|
page.within '.mr-version-dropdown' do
|
|
|
|
expect(page).to have_content 'latest version'
|
|
|
|
end
|
|
|
|
|
2020-02-05 09:08:43 +00:00
|
|
|
expect(page).to have_content '8 files'
|
2017-12-01 19:08:30 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'allows commenting',
|
2022-07-19 09:08:45 +00:00
|
|
|
file_name: '.gitmodules',
|
|
|
|
line_text: '[submodule "six"]',
|
2017-12-01 19:08:30 +00:00
|
|
|
comment: 'Typo, please fix.'
|
2016-07-27 14:55:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'switch between versions' do
|
|
|
|
before do
|
2016-09-01 12:23:39 +00:00
|
|
|
page.within '.mr-version-dropdown' do
|
2016-09-14 11:55:07 +00:00
|
|
|
find('.btn-default').click
|
2017-04-30 20:32:09 +00:00
|
|
|
click_link 'version 1'
|
|
|
|
end
|
|
|
|
|
|
|
|
# Wait for the page to load
|
|
|
|
page.within '.mr-version-dropdown' do
|
|
|
|
expect(page).to have_content 'version 1'
|
2016-07-27 14:55:12 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-12-31 16:48:44 +00:00
|
|
|
it 'shows the commit SHAs for every version in the dropdown' do
|
|
|
|
page.within '.mr-version-dropdown' do
|
2020-11-25 12:09:23 +00:00
|
|
|
find('.gl-dropdown-toggle').click
|
|
|
|
end
|
2018-12-31 16:48:44 +00:00
|
|
|
|
2020-11-25 12:09:23 +00:00
|
|
|
page.within '.mr-version-dropdown' do
|
|
|
|
shas = merge_request.merge_request_diffs.map { |diff| Commit.truncate_sha(diff.head_commit_sha) }
|
|
|
|
shas.each { |sha| expect(page).to have_content(sha) }
|
2018-12-31 16:48:44 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-01 18:03:07 +00:00
|
|
|
it 'shows comments that were last relevant at that version' do
|
2020-02-05 09:08:43 +00:00
|
|
|
expect(page).to have_content '5 files'
|
2017-04-10 20:17:47 +00:00
|
|
|
|
2020-02-17 18:09:00 +00:00
|
|
|
position = build(:text_diff_position, :added,
|
|
|
|
file: ".gitmodules",
|
2017-04-10 20:17:47 +00:00
|
|
|
new_line: 4,
|
|
|
|
diff_refs: merge_request_diff1.diff_refs
|
|
|
|
)
|
|
|
|
outdated_diff_note = create(:diff_note_on_merge_request, project: project, noteable: merge_request, position: position)
|
|
|
|
outdated_diff_note.position = outdated_diff_note.original_position
|
|
|
|
outdated_diff_note.save!
|
|
|
|
|
2017-08-01 18:03:07 +00:00
|
|
|
refresh
|
2022-06-08 09:09:42 +00:00
|
|
|
wait_for_requests
|
2017-04-30 20:32:09 +00:00
|
|
|
|
2017-04-10 20:17:47 +00:00
|
|
|
expect(page).to have_css(".diffs .notes[data-discussion-id='#{outdated_diff_note.discussion_id}']")
|
|
|
|
end
|
2017-04-30 20:32:09 +00:00
|
|
|
|
2017-12-01 19:08:30 +00:00
|
|
|
it_behaves_like 'allows commenting',
|
2022-07-19 09:08:45 +00:00
|
|
|
file_name: '.gitmodules',
|
|
|
|
line_text: 'path = six',
|
2017-12-01 19:08:30 +00:00
|
|
|
comment: 'Typo, please fix.'
|
2016-09-01 12:23:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'compare with older version' do
|
|
|
|
before do
|
|
|
|
page.within '.mr-version-compare-dropdown' do
|
2016-09-14 11:55:07 +00:00
|
|
|
find('.btn-default').click
|
2017-04-30 20:32:09 +00:00
|
|
|
click_link 'version 1'
|
|
|
|
end
|
|
|
|
|
|
|
|
# Wait for the page to load
|
|
|
|
page.within '.mr-version-compare-dropdown' do
|
|
|
|
expect(page).to have_content 'version 1'
|
2016-09-01 12:23:39 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-01 18:03:07 +00:00
|
|
|
it 'has a path with comparison context and shows comments that were last relevant at that version' do
|
2017-06-29 17:06:35 +00:00
|
|
|
expect(page).to have_current_path diffs_project_merge_request_path(
|
2016-10-01 07:32:21 +00:00
|
|
|
project,
|
|
|
|
merge_request.iid,
|
2016-11-18 13:33:42 +00:00
|
|
|
diff_id: merge_request_diff3.id,
|
2016-10-01 07:32:21 +00:00
|
|
|
start_sha: '6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9'
|
|
|
|
)
|
2020-02-05 09:08:43 +00:00
|
|
|
expect(page).to have_content '4 files'
|
2019-01-30 03:21:26 +00:00
|
|
|
|
2021-06-15 21:10:04 +00:00
|
|
|
additions_content = page.find('.diff-stats.is-compare-versions-header .diff-stats-group [data-testid="js-file-addition-line"]').text
|
|
|
|
deletions_content = page.find('.diff-stats.is-compare-versions-header .diff-stats-group [data-testid="js-file-deletion-line"]').text
|
2019-01-30 03:21:26 +00:00
|
|
|
|
|
|
|
expect(additions_content).to eq '15'
|
|
|
|
expect(deletions_content).to eq '6'
|
2017-04-30 20:32:09 +00:00
|
|
|
|
2020-02-17 18:09:00 +00:00
|
|
|
position = build(:text_diff_position,
|
|
|
|
file: ".gitmodules",
|
2017-04-30 20:32:09 +00:00
|
|
|
old_line: 4,
|
|
|
|
new_line: 4,
|
|
|
|
diff_refs: merge_request_diff3.compare_with(merge_request_diff1.head_commit_sha).diff_refs
|
|
|
|
)
|
|
|
|
outdated_diff_note = create(:diff_note_on_merge_request, project: project, noteable: merge_request, position: position)
|
2017-05-21 20:38:33 +00:00
|
|
|
outdated_diff_note.position = outdated_diff_note.original_position
|
|
|
|
outdated_diff_note.save!
|
2017-04-30 20:32:09 +00:00
|
|
|
|
2017-08-01 18:03:07 +00:00
|
|
|
refresh
|
2017-05-17 18:25:13 +00:00
|
|
|
wait_for_requests
|
2017-04-30 20:32:09 +00:00
|
|
|
|
|
|
|
expect(page).to have_css(".diffs .notes[data-discussion-id='#{outdated_diff_note.discussion_id}']")
|
|
|
|
end
|
|
|
|
|
2016-09-01 12:35:39 +00:00
|
|
|
it 'show diff between new and old version' do
|
2021-06-15 21:10:04 +00:00
|
|
|
additions_content = page.find('.diff-stats.is-compare-versions-header .diff-stats-group [data-testid="js-file-addition-line"]').text
|
|
|
|
deletions_content = page.find('.diff-stats.is-compare-versions-header .diff-stats-group [data-testid="js-file-deletion-line"]').text
|
2019-01-30 03:21:26 +00:00
|
|
|
|
2020-02-05 09:08:43 +00:00
|
|
|
expect(page).to have_content '4 files'
|
2019-01-30 03:21:26 +00:00
|
|
|
expect(additions_content).to eq '15'
|
|
|
|
expect(deletions_content).to eq '6'
|
2016-09-01 12:35:39 +00:00
|
|
|
end
|
|
|
|
|
2017-08-01 18:03:07 +00:00
|
|
|
it 'returns to latest version when "Show latest version" button is clicked' do
|
2016-09-14 11:55:07 +00:00
|
|
|
click_link 'Show latest version'
|
|
|
|
page.within '.mr-version-dropdown' do
|
|
|
|
expect(page).to have_content 'latest version'
|
|
|
|
end
|
2020-02-05 09:08:43 +00:00
|
|
|
expect(page).to have_content '8 files'
|
2016-09-14 11:55:07 +00:00
|
|
|
end
|
2017-12-01 19:08:30 +00:00
|
|
|
|
|
|
|
it_behaves_like 'allows commenting',
|
2022-07-19 09:08:45 +00:00
|
|
|
file_name: '.gitmodules',
|
|
|
|
line_text: '[submodule "gitlab-shell"]',
|
|
|
|
comment: 'Typo, please fix.'
|
2016-07-27 14:55:12 +00:00
|
|
|
end
|
2016-12-27 17:03:44 +00:00
|
|
|
|
|
|
|
describe 'compare with same version' do
|
|
|
|
before do
|
|
|
|
page.within '.mr-version-compare-dropdown' do
|
|
|
|
find('.btn-default').click
|
|
|
|
click_link 'version 1'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-01 18:03:07 +00:00
|
|
|
it 'has 0 chages between versions' do
|
2016-12-27 17:03:44 +00:00
|
|
|
page.within '.mr-version-compare-dropdown' do
|
2020-11-25 12:09:23 +00:00
|
|
|
expect(find('.gl-dropdown-toggle')).to have_content 'version 1'
|
2016-12-27 17:03:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
page.within '.mr-version-dropdown' do
|
|
|
|
find('.btn-default').click
|
2017-04-21 15:05:38 +00:00
|
|
|
click_link 'version 1'
|
2016-12-27 17:03:44 +00:00
|
|
|
end
|
2021-01-05 03:10:19 +00:00
|
|
|
expect(page).to have_content 'No changes between version 1 and version 1'
|
2016-12-27 17:03:44 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'compare with newer version' do
|
|
|
|
before do
|
|
|
|
page.within '.mr-version-compare-dropdown' do
|
|
|
|
find('.btn-default').click
|
|
|
|
click_link 'version 2'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-01 18:03:07 +00:00
|
|
|
it 'sets the compared versions to be the same' do
|
2016-12-27 17:03:44 +00:00
|
|
|
page.within '.mr-version-compare-dropdown' do
|
2020-11-25 12:09:23 +00:00
|
|
|
expect(find('.gl-dropdown-toggle')).to have_content 'version 2'
|
2016-12-27 17:03:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
page.within '.mr-version-dropdown' do
|
|
|
|
find('.btn-default').click
|
2017-04-21 15:05:38 +00:00
|
|
|
click_link 'version 1'
|
2016-12-27 17:03:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
page.within '.mr-version-compare-dropdown' do
|
|
|
|
expect(page).to have_content 'version 1'
|
|
|
|
end
|
|
|
|
|
2021-01-05 03:10:19 +00:00
|
|
|
expect(page).to have_content 'No changes between version 1 and version 1'
|
2016-12-27 17:03:44 +00:00
|
|
|
end
|
|
|
|
end
|
2017-12-01 19:08:30 +00:00
|
|
|
|
|
|
|
describe 'scoped in a commit' do
|
|
|
|
let(:params) { { commit_id: '570e7b2abdd848b95f2f578043fc23bd6f6fd24d' } }
|
|
|
|
|
|
|
|
before do
|
|
|
|
wait_for_requests
|
|
|
|
end
|
|
|
|
|
2019-04-05 08:43:27 +00:00
|
|
|
it 'only shows diffs from the commit' do
|
2022-07-29 21:08:53 +00:00
|
|
|
diff_commit_ids = find_all('.diff-file [data-commit-id]').map { |diff| diff['data-commit-id'] }
|
2017-12-01 19:08:30 +00:00
|
|
|
|
|
|
|
expect(diff_commit_ids).not_to be_empty
|
|
|
|
expect(diff_commit_ids).to all(eq(params[:commit_id]))
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'allows commenting',
|
2022-07-19 09:08:45 +00:00
|
|
|
file_name: 'files/ruby/popen.rb',
|
|
|
|
line_text: 'RuntimeError',
|
2017-12-01 19:08:30 +00:00
|
|
|
comment: 'Typo, please fix.'
|
|
|
|
end
|
2016-07-27 14:55:12 +00:00
|
|
|
end
|