diff --git a/qa/qa/page/merge_request/show.rb b/qa/qa/page/merge_request/show.rb index 14b8c420b1613568de31f4eebb0df97f986ddfd3..ac149ba2c119bd2bf8aca7b015d3ea6c799c5385 100644 --- a/qa/qa/page/merge_request/show.rb +++ b/qa/qa/page/merge_request/show.rb @@ -60,6 +60,14 @@ module QA element :edit_button end + view 'app/assets/javascripts/vue_merge_shared/components/mr_widget_header.vue' do + element :suggestion_btn + end + + view 'app/assets/javascripts/vue_shared/components/markdown/suggestion_diff_header.vue' do + element :apply_btn + end + def click_discussions_tab click_element :notes_tab end @@ -203,6 +211,34 @@ module QA click_element :dropdown_toggle visit_link_in_element(:download_plain_diff) end + + # + # New code for suggestion + # + def add_suggestion_to_diff_and_reply_comment(text) + wait(interval: 5) do + has_text?("No newline at end of file") + end + all_elements(:new_diff_line).first.hover + click_element :diff_comment + click_element :suggestion_btn + fill_element :reply_input, "```suggestion:-0+0\n #{text}\n```" + click_element :reply_comment_button + end + + def apply_suggestion + click_element :apply_btn + wait(interval: 5) do + has_text?("Applied") + end + end + + #This is a wrong place to put this method + #this method should belong to a page object that display a list of merge requests + # I tried to create a page object but I cannot make it work due to NO Constant Found error + def click_merge_request(mr_name) + find_link(text: mr_name).click + end end end end diff --git a/qa/qa/specs/features/browser_ui/3_create/merge_request/suggest_and_apply_a_merge_request_spec.rb b/qa/qa/specs/features/browser_ui/3_create/merge_request/suggest_and_apply_a_merge_request_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..e6b0dd8211e802270c7f6de2a4190afcaf44d6c1 --- /dev/null +++ b/qa/qa/specs/features/browser_ui/3_create/merge_request/suggest_and_apply_a_merge_request_spec.rb @@ -0,0 +1,138 @@ +# frozen_string_literal: true + +module QA + context 'Create' do + describe 'Suggest a change to a merge request' do + test_branch_name = "test-branch" + test_branch_file_name = "first.txt" + test_branch_file_content = 'Test file content' + test_branch_file_content_upate = "Test file content need to be updated" + + before do + #login as admin and create a user + @developer_user = Resource::User.fabricate_or_use( "developer-user", Runtime::Env.gitlab_qa_password_1) + + #create a project + @project = Resource::Project.fabricate_via_api! do |project| + project.name = 'suggset-merge-request-project' + end + #Assign user to project + @project.add_member(@developer_user,Resource::Members::AccessLevel::MAINTAINER) + Page::Main::Menu.perform(&:sign_out) + + # login with created user + login_as_developer_user_from_ui() + + #add ssh key + Resource::SSHKey.fabricate! do |resource| + resource.title = "key for merge requset #{Time.now.to_f}" + end + + # I know the requirement ask to commit file using SSH key + # but I stuck with a error that I don't know how to solve for quite a while + # and I don't want to waste time here so I use http to continue the test. + # ERROR for SSH + # The command HOME="/var/folders/lw/vjm95mgj01929w_w01dvdlb80000gn/T/qa-netrc-credentials/19699" ssh-keyscan -H -p 2222 localhost >> + # /var/folders/lw/vjm95mgj01929w_w01dvdlb80000gn/T/known_hosts_edaf7bd0dc224b0220191106-19699-chjwxa 2>&1 failed (141) with the following output: + Git::Repository.perform do |repository| + username = @developer_user.username + email = @developer_user.email + + repository.uri = @project.repository_http_location.uri + repository.username = username + repository.password = @developer_user.password + + repository.act do + try_add_credentials_to_netrc() + clone() + configure_identity(username, email) + commit_file("master.txt", 'Test file content', "first_commit_message_of_master_branch") + push_changes() + checkout(test_branch_name, new_branch: true) + commit_file(test_branch_file_name, test_branch_file_content, "first_commit_message_of_new_branch") + push_changes(test_branch_name) + end + end + + @merge_request = Resource::MergeRequest.fabricate_via_api! do |mr| + mr.project = @project + mr.source_branch = test_branch_name + mr.no_preparation = true + end + Page::Main::Menu.perform(&:sign_out) + end #end of before + + it 'user apply a merge request suggestion' do + # As the "root" user, suggest a change using the "Insert suggestion" button. + login_as_root_from_ui() + go_to_merge_request_from_ui() + + Page::MergeRequest::Show.perform do |show| + show.click_merge_request(@merge_request.title) + show.click_diffs_tab() + show.add_suggestion_to_diff_and_reply_comment(test_branch_file_content_upate) + end + Page::Main::Menu.perform(&:sign_out) + + # As the "developer-user" user, apply the change. + login_as_developer_user_from_ui() + go_to_merge_request_from_ui() + + Page::MergeRequest::Show.perform do |show| + show.click_merge_request(@merge_request.title) + show.apply_suggestion() + end + Page::Main::Menu.perform(&:sign_out) + + # As the "root" user, merge the merge request. + login_as_root_from_ui() + go_to_merge_request_from_ui() + + Page::MergeRequest::Show.perform do |show| + show.click_merge_request(@merge_request.title) + show.merge_immediately() + show.retry_until(reload:false) do + page.has_content?('The changes were merged') + end + end + + # ensure that the repository now has the file with the suggested changes. + # Check if file from test branch is merged and the content is updated from the suggestion + Page::Main::Menu.perform(&:go_to_projects) + Page::Dashboard::Projects.perform do |dashboard| + dashboard.go_to_project(@project.name) + end + Page::Project::Show.perform do |project_page| + project_page.click_file test_branch_file_name + end + + expect(page).to have_content(test_branch_file_content_upate) + end #end of tests + + def login_as_root_from_ui + Runtime::Browser.visit(:gitlab, Page::Main::Login) + Page::Main::Login.perform(&:sign_in_using_admin_credentials) + end + + def login_as_developer_user_from_ui + Runtime::Browser.visit(:gitlab, Page::Main::Login) + Page::Main::Login.perform do |login| + login.sign_in_using_credentials(user: @developer_user) + end + end + + # I dont really like the way I navigate to the created Merge Request (quite wate of time) + # but for somereason, @merge_request.visit! navigate to the page without logging in with the user + # I tried to stay login and then use @merge_request.visit!, still the landed page is not login + def go_to_merge_request_from_ui + #@merge_request.visit! + Page::Main::Menu.perform(&:go_to_projects) + Page::Dashboard::Projects.perform do |dashboard| + dashboard.go_to_project(@project.name) + end + Page::Project::Menu.perform(&:click_merge_requests) + end + + end #end of describe + end +end