Commit 33e17d8e authored by Mark Lapierre's avatar Mark Lapierre

Merge branch 'qa-e2e-fork-in-web-ide' into 'master'

Add E2E for working with forks in Web IDE

See merge request gitlab-org/gitlab!38259
parents ab38e6c7 0325beac
...@@ -20,7 +20,11 @@ export default { ...@@ -20,7 +20,11 @@ export default {
<project-avatar-default :project="project" :size="48" /> <project-avatar-default :project="project" :size="48" />
<span class="ide-sidebar-project-title"> <span class="ide-sidebar-project-title">
<span class="sidebar-context-title"> {{ project.name }} </span> <span class="sidebar-context-title"> {{ project.name }} </span>
<span class="sidebar-context-title text-secondary"> <span
class="sidebar-context-title text-secondary"
data-qa-selector="project_path_content"
:data-qa-project-path="project.path_with_namespace"
>
{{ project.path_with_namespace }} {{ project.path_with_namespace }}
</span> </span>
</span> </span>
......
#modal-confirm-fork.modal.qa-confirm-fork-modal #modal-confirm-fork.modal{ data: { qa_selector: 'confirm_fork_modal' } }
.modal-dialog .modal-dialog
.modal-content .modal-content
.modal-header .modal-header
...@@ -9,4 +9,4 @@ ...@@ -9,4 +9,4 @@
%p= _("You're not allowed to %{tag_start}edit%{tag_end} files in this project directly. Please fork this project, make your changes there, and submit a merge request.") % { tag_start: '', tag_end: ''} %p= _("You're not allowed to %{tag_start}edit%{tag_end} files in this project directly. Please fork this project, make your changes there, and submit a merge request.") % { tag_start: '', tag_end: ''}
.modal-footer .modal-footer
= link_to _('Cancel'), '#', class: "btn btn-cancel", "data-dismiss" => "modal" = link_to _('Cancel'), '#', class: "btn btn-cancel", "data-dismiss" => "modal"
= link_to _('Fork project'), fork_path, class: 'btn btn-success', method: :post = link_to _('Fork project'), fork_path, class: 'btn btn-success', data: { qa_selector: 'fork_project_button' }, method: :post
...@@ -5,7 +5,7 @@ module QA ...@@ -5,7 +5,7 @@ module QA
module MergeRequest module MergeRequest
class New < Page::Issuable::New class New < Page::Issuable::New
view 'app/views/shared/issuable/_form.html.haml' do view 'app/views/shared/issuable/_form.html.haml' do
element :issuable_create_button element :issuable_create_button, required: true
end end
def create_merge_request def create_merge_request
......
...@@ -143,6 +143,10 @@ module QA ...@@ -143,6 +143,10 @@ module QA
click_element :web_ide_button click_element :web_ide_button
end end
def has_edit_fork_button?
has_element?(:web_ide_button, text: 'Edit fork in Web IDE')
end
def project_name def project_name
find_element(:project_name_content).text find_element(:project_name_content).text
end end
......
...@@ -59,12 +59,25 @@ module QA ...@@ -59,12 +59,25 @@ module QA
element :rename_move_button element :rename_move_button
end end
view 'app/views/shared/_confirm_fork_modal.html.haml' do
element :fork_project_button
element :confirm_fork_modal
end
view 'app/assets/javascripts/ide/components/ide_project_header.vue' do
element :project_path_content
end
def has_file?(file_name) def has_file?(file_name)
within_element(:file_list) do within_element(:file_list) do
page.has_content? file_name page.has_content? file_name
end end
end end
def has_project_path?(project_path)
has_element?(:project_path_content, project_path: project_path)
end
def create_new_file_from_template(file_name, template) def create_new_file_from_template(file_name, template)
click_element(:new_file, Page::Component::WebIDE::Modal::CreateNewFile) click_element(:new_file, Page::Component::WebIDE::Modal::CreateNewFile)
...@@ -91,7 +104,7 @@ module QA ...@@ -91,7 +104,7 @@ module QA
end end
end end
def commit_changes def commit_changes(open_merge_request: false)
# Clicking :begin_commit_button switches from the # Clicking :begin_commit_button switches from the
# edit to the commit view # edit to the commit view
click_element :begin_commit_button click_element :begin_commit_button
...@@ -107,19 +120,23 @@ module QA ...@@ -107,19 +120,23 @@ module QA
has_element?(:commit_button) has_element?(:commit_button)
end end
# Click :commit_button and keep retrying just in case part of the if open_merge_request
# animation is still in process even when the buttons have the click_element(:commit_button, Page::MergeRequest::New)
# expected visibility. else
commit_success_msg_shown = retry_until(sleep_interval: 5) do # Click :commit_button and keep retrying just in case part of the
click_element(:commit_to_current_branch_radio) if has_element?(:commit_to_current_branch_radio) # animation is still in process even when the buttons have the
click_element(:commit_button) if has_element?(:commit_button) # expected visibility.
commit_success_msg_shown = retry_until(sleep_interval: 5) do
wait_until(reload: false) do click_element(:commit_to_current_branch_radio) if has_element?(:commit_to_current_branch_radio)
has_text?('Your changes have been committed') click_element(:commit_button) if has_element?(:commit_button)
wait_until(reload: false) do
has_text?('Your changes have been committed')
end
end end
end
raise "The changes do not appear to have been committed successfully." unless commit_success_msg_shown raise "The changes do not appear to have been committed successfully." unless commit_success_msg_shown
end
end end
def add_to_modified_content(content) def add_to_modified_content(content)
...@@ -141,6 +158,16 @@ module QA ...@@ -141,6 +158,16 @@ module QA
click_button('Create file') click_button('Create file')
end end
def add_file(file_name, file_text)
click_element(:new_file, Page::Component::WebIDE::Modal::CreateNewFile)
fill_element(:file_name_field, file_name)
click_button('Create file')
wait_until(reload: false) { has_file?(file_name) }
within_element(:editor_container) do
find('textarea.inputarea').click.set(file_text)
end
end
def rename_file(file_name, new_file_name) def rename_file(file_name, new_file_name)
click_element(:file_name_content, text: file_name) click_element(:file_name_content, text: file_name)
click_element(:dropdown_button) click_element(:dropdown_button)
...@@ -148,6 +175,17 @@ module QA ...@@ -148,6 +175,17 @@ module QA
fill_element(:file_name_field, new_file_name) fill_element(:file_name_field, new_file_name)
click_button('Rename file') click_button('Rename file')
end end
def fork_project!
wait_until(reload: false) do
has_element?(:confirm_fork_modal)
end
click_element(:fork_project_button)
# wait for the fork to be created
wait_until(reload: true) do
has_element?(:file_list)
end
end
end end
end end
end end
......
# frozen_string_literal: true
module QA
RSpec.describe 'Create' do
describe 'Open a fork in Web IDE' do
let(:parent_project) do
Resource::Project.fabricate_via_api! do |project|
project.name = 'parent-project'
project.initialize_with_readme = true
end
end
context 'when a user does not have permissions to commit to the project' do
let(:user) { Resource::User.fabricate_or_use(Runtime::Env.gitlab_qa_username_1, Runtime::Env.gitlab_qa_password_1) }
context 'when no fork is present' do
it 'suggests to create a fork when a user clicks Web IDE in the main project' do
Flow::Login.sign_in(as: user)
parent_project.visit!
Page::Project::Show.perform(&:open_web_ide!)
Page::Project::WebIDE::Edit.perform(&:fork_project!)
submit_merge_request_upstream
end
end
context 'when a fork is already created' do
let(:fork_project) do
Resource::Fork.fabricate_via_api! do |fork|
fork.user = user
fork.upstream = parent_project
end
end
it 'opens the fork when a user clicks Web IDE in the main project' do
Flow::Login.sign_in(as: user)
fork_project.upstream.visit!
Page::Project::Show.perform do |project_page|
expect(project_page).to have_edit_fork_button
project_page.open_web_ide!
end
submit_merge_request_upstream
end
end
def submit_merge_request_upstream
Page::Project::WebIDE::Edit.perform do |ide|
expect(ide).to have_project_path("#{user.username}/#{parent_project.name}")
ide.add_file('new file', 'some random text')
ide.commit_changes(open_merge_request: true)
end
Page::MergeRequest::New.perform(&:create_merge_request)
parent_project.visit!
Page::Project::Menu.perform(&:click_merge_requests)
expect(page).to have_content('Update new file')
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