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 {
<project-avatar-default :project="project" :size="48" />
<span class="ide-sidebar-project-title">
<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 }}
</span>
</span>
......
#modal-confirm-fork.modal.qa-confirm-fork-modal
#modal-confirm-fork.modal{ data: { qa_selector: 'confirm_fork_modal' } }
.modal-dialog
.modal-content
.modal-header
......@@ -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: ''}
.modal-footer
= 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
module MergeRequest
class New < Page::Issuable::New
view 'app/views/shared/issuable/_form.html.haml' do
element :issuable_create_button
element :issuable_create_button, required: true
end
def create_merge_request
......
......@@ -143,6 +143,10 @@ module QA
click_element :web_ide_button
end
def has_edit_fork_button?
has_element?(:web_ide_button, text: 'Edit fork in Web IDE')
end
def project_name
find_element(:project_name_content).text
end
......
......@@ -59,12 +59,25 @@ module QA
element :rename_move_button
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)
within_element(:file_list) do
page.has_content? file_name
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)
click_element(:new_file, Page::Component::WebIDE::Modal::CreateNewFile)
......@@ -91,7 +104,7 @@ module QA
end
end
def commit_changes
def commit_changes(open_merge_request: false)
# Clicking :begin_commit_button switches from the
# edit to the commit view
click_element :begin_commit_button
......@@ -107,19 +120,23 @@ module QA
has_element?(:commit_button)
end
# Click :commit_button and keep retrying just in case part of the
# animation is still in process even when the buttons have the
# expected visibility.
commit_success_msg_shown = retry_until(sleep_interval: 5) do
click_element(:commit_to_current_branch_radio) if has_element?(:commit_to_current_branch_radio)
click_element(:commit_button) if has_element?(:commit_button)
wait_until(reload: false) do
has_text?('Your changes have been committed')
if open_merge_request
click_element(:commit_button, Page::MergeRequest::New)
else
# Click :commit_button and keep retrying just in case part of the
# animation is still in process even when the buttons have the
# expected visibility.
commit_success_msg_shown = retry_until(sleep_interval: 5) do
click_element(:commit_to_current_branch_radio) if has_element?(:commit_to_current_branch_radio)
click_element(:commit_button) if has_element?(:commit_button)
wait_until(reload: false) do
has_text?('Your changes have been committed')
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
def add_to_modified_content(content)
......@@ -141,6 +158,16 @@ module QA
click_button('Create file')
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)
click_element(:file_name_content, text: file_name)
click_element(:dropdown_button)
......@@ -148,6 +175,17 @@ module QA
fill_element(:file_name_field, new_file_name)
click_button('Rename file')
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
......
# 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