Commit 0acf5944 authored by Mark Lapierre's avatar Mark Lapierre

Merge branch 'ml-add-merge-ref-diff-tests' into 'master'

Add merge-ref diff e2e tests

See merge request gitlab-org/gitlab!42661
parents b572d086 a562cd92
...@@ -32,7 +32,7 @@ export default { ...@@ -32,7 +32,7 @@ export default {
<gl-icon :size="12" name="angle-down" class="position-absolute" /> <gl-icon :size="12" name="angle-down" class="position-absolute" />
</a> </a>
<div class="dropdown-menu dropdown-select dropdown-menu-selectable"> <div class="dropdown-menu dropdown-select dropdown-menu-selectable">
<div class="dropdown-content"> <div class="dropdown-content" data-qa-selector="dropdown_content">
<ul> <ul>
<li v-for="version in versions" :key="version.id"> <li v-for="version in versions" :key="version.id">
<a :class="{ 'is-active': version.selected }" :href="version.href"> <a :class="{ 'is-active': version.selected }" :href="version.href">
......
...@@ -100,6 +100,7 @@ export default { ...@@ -100,6 +100,7 @@ export default {
<compare-dropdown-layout <compare-dropdown-layout
:versions="diffCompareDropdownTargetVersions" :versions="diffCompareDropdownTargetVersions"
class="mr-version-compare-dropdown" class="mr-version-compare-dropdown"
data-qa-selector="target_version_dropdown"
/> />
</template> </template>
<template #source> <template #source>
......
...@@ -245,7 +245,14 @@ export default { ...@@ -245,7 +245,14 @@ export default {
></strong> ></strong>
</span> </span>
<strong v-else v-gl-tooltip :title="filePath" class="file-title-name" data-container="body"> <strong
v-else
v-gl-tooltip
:title="filePath"
class="file-title-name"
data-container="body"
data-qa-selector="file_name_content"
>
{{ filePath }} {{ filePath }}
</strong> </strong>
</a> </a>
......
...@@ -49,6 +49,18 @@ module QA ...@@ -49,6 +49,18 @@ module QA
element :diffs_tab element :diffs_tab
end end
view 'app/assets/javascripts/diffs/components/compare_dropdown_layout.vue' do
element :dropdown_content
end
view 'app/assets/javascripts/diffs/components/compare_versions.vue' do
element :target_version_dropdown
end
view 'app/assets/javascripts/diffs/components/diff_file_header.vue' do
element :file_name_content
end
view 'app/assets/javascripts/diffs/components/inline_diff_table_row.vue' do view 'app/assets/javascripts/diffs/components/inline_diff_table_row.vue' do
element :new_diff_line element :new_diff_line
end end
...@@ -79,46 +91,54 @@ module QA ...@@ -79,46 +91,54 @@ module QA
end end
def start_review def start_review
click_element :start_review_button click_element(:start_review_button)
# After clicking the button, wait for it to disappear # After clicking the button, wait for it to disappear
# before moving on to the next part of the test # before moving on to the next part of the test
has_no_element? :start_review_button has_no_element?(:start_review_button)
end
def click_target_version_dropdown
click_element(:target_version_dropdown)
end end
def comment_now def comment_now
click_element :comment_now_button click_element(:comment_now_button)
# After clicking the button, wait for it to disappear # After clicking the button, wait for it to disappear
# before moving on to the next part of the test # before moving on to the next part of the test
has_no_element? :comment_now_button has_no_element?(:comment_now_button)
end
def version_dropdown_content
find_element(:dropdown_content).text
end end
def submit_pending_reviews def submit_pending_reviews
within_element :review_bar do within_element(:review_bar) do
click_element :review_preview_toggle click_element(:review_preview_toggle)
click_element :submit_review click_element(:submit_review)
# After clicking the button, wait for it to disappear # After clicking the button, wait for it to disappear
# before moving on to the next part of the test # before moving on to the next part of the test
has_no_element? :submit_review has_no_element?(:submit_review)
end end
end end
def discard_pending_reviews def discard_pending_reviews
within_element :review_bar do within_element(:review_bar) do
click_element :discard_review click_element(:discard_review)
end end
click_element :modal_delete_pending_comments click_element(:modal_delete_pending_comments)
end end
def resolve_review_discussion def resolve_review_discussion
scroll_to_element :start_review_button scroll_to_element(:start_review_button)
check_element :resolve_review_discussion_checkbox check_element(:resolve_review_discussion_checkbox)
end end
def unresolve_review_discussion def unresolve_review_discussion
check_element :unresolve_review_discussion_checkbox check_element(:unresolve_review_discussion_checkbox)
end end
def add_comment_to_diff(text) def add_comment_to_diff(text)
...@@ -156,6 +176,10 @@ module QA ...@@ -156,6 +176,10 @@ module QA
has_no_text?('Fast-forward merge is not possible') has_no_text?('Fast-forward merge is not possible')
end end
def has_file?(file_name)
has_element?(:file_name_content, text: file_name)
end
def has_merge_button? def has_merge_button?
refresh refresh
...@@ -186,7 +210,7 @@ module QA ...@@ -186,7 +210,7 @@ module QA
!find_element(:squash_checkbox).disabled? !find_element(:squash_checkbox).disabled?
end end
click_element :squash_checkbox click_element(:squash_checkbox)
end end
def merge! def merge!
...@@ -231,7 +255,7 @@ module QA ...@@ -231,7 +255,7 @@ module QA
!find_element(:mr_rebase_button).disabled? !find_element(:mr_rebase_button).disabled?
end end
click_element :mr_rebase_button click_element(:mr_rebase_button)
success = wait_until do success = wait_until do
has_text?('Fast-forward merge without a merge commit') has_text?('Fast-forward merge without a merge commit')
...@@ -247,12 +271,12 @@ module QA ...@@ -247,12 +271,12 @@ module QA
end end
def view_email_patches def view_email_patches
click_element :download_dropdown click_element(:download_dropdown)
visit_link_in_element(:download_email_patches) visit_link_in_element(:download_email_patches)
end end
def view_plain_diff def view_plain_diff
click_element :download_dropdown click_element(:download_dropdown)
visit_link_in_element(:download_plain_diff) visit_link_in_element(:download_plain_diff)
end end
......
# frozen_string_literal: true
module QA
RSpec.describe 'Create' do
describe 'View merge request merge-ref diff' do
let(:merge_request) do
Resource::MergeRequest.fabricate_via_api! do |merge_request|
merge_request.title = 'This is a merge request'
merge_request.description = '... for viewing merge-ref and merge-base diffs'
merge_request.file_content = 'This exists on the source branch only'
end
end
let(:new_file_name) { "added_file-#{SecureRandom.hex(8)}.txt" }
before do
commit_to_branch(merge_request.target_branch, new_file_name)
commit_to_branch(merge_request.source_branch, new_file_name)
Flow::Login.sign_in
end
context 'when the feature flag default_merge_ref_for_diffs is enabled' do
before do
Runtime::Feature.enable('default_merge_ref_for_diffs', project: merge_request.project)
merge_request.visit!
end
it 'views the merge-ref diff by default' do
Page::MergeRequest::Show.perform do |mr_page|
mr_page.click_diffs_tab
mr_page.click_target_version_dropdown
expect(mr_page.version_dropdown_content).to include('master (HEAD)')
expect(mr_page.version_dropdown_content).not_to include('master (base)')
expect(mr_page).to have_file(merge_request.file_name)
expect(mr_page).not_to have_file(new_file_name)
end
end
end
context 'when the feature flag default_merge_ref_for_diffs is disabled' do
before do
Runtime::Feature.disable('default_merge_ref_for_diffs', project: merge_request.project)
merge_request.visit!
end
it 'views the merge-base diff by default' do
Page::MergeRequest::Show.perform do |mr_page|
mr_page.click_diffs_tab
mr_page.click_target_version_dropdown
expect(mr_page.version_dropdown_content).to include('master (HEAD)')
expect(mr_page.version_dropdown_content).to include('master (base)')
expect(mr_page).to have_file(merge_request.file_name)
expect(mr_page).to have_file(new_file_name)
end
end
end
def commit_to_branch(branch, file)
Resource::Repository::Commit.fabricate_via_api! do |commit|
commit.project = merge_request.project
commit.branch = branch
commit.commit_message = "Add new file on #{branch}"
commit.add_files(
[
{
file_path: file,
content: "This exists on source and target branches"
}
]
)
end
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment