2019-07-25 05:24:42 +00:00
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2017-07-12 12:45:42 +00:00
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
2020-06-16 18:09:01 +00:00
|
|
|
|
RSpec.describe 'Projects > Files > User edits files', :js do
|
2022-07-25 12:09:06 +00:00
|
|
|
|
include Spec::Support::Helpers::Features::SourceEditorSpecHelpers
|
2017-10-06 10:36:34 +00:00
|
|
|
|
include ProjectForksHelper
|
2020-10-15 06:09:14 +00:00
|
|
|
|
include BlobSpecHelpers
|
|
|
|
|
|
2017-07-24 22:51:14 +00:00
|
|
|
|
let(:project) { create(:project, :repository, name: 'Shop') }
|
2017-07-12 12:45:42 +00:00
|
|
|
|
let(:project2) { create(:project, :repository, name: 'Another Project', path: 'another-project') }
|
|
|
|
|
let(:project_tree_path_root_ref) { project_tree_path(project, project.repository.root_ref) }
|
|
|
|
|
let(:project2_tree_path_root_ref) { project_tree_path(project2, project2.repository.root_ref) }
|
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
|
|
before do
|
2022-08-20 00:12:08 +00:00
|
|
|
|
stub_feature_flags(vscode_web_ide: false)
|
|
|
|
|
|
2017-07-12 12:45:42 +00:00
|
|
|
|
sign_in(user)
|
|
|
|
|
end
|
|
|
|
|
|
2020-10-15 06:09:14 +00:00
|
|
|
|
after do
|
|
|
|
|
unset_default_button
|
|
|
|
|
end
|
|
|
|
|
|
2018-04-06 10:47:52 +00:00
|
|
|
|
shared_examples 'unavailable for an archived project' do
|
|
|
|
|
it 'does not show the edit link for an archived project', :js do
|
|
|
|
|
project.update!(archived: true)
|
|
|
|
|
visit project_tree_path(project, project.repository.root_ref)
|
|
|
|
|
|
|
|
|
|
click_link('.gitignore')
|
|
|
|
|
|
|
|
|
|
aggregate_failures 'available edit buttons' do
|
2018-04-11 21:14:02 +00:00
|
|
|
|
expect(page).not_to have_text('Edit')
|
|
|
|
|
expect(page).not_to have_text('Web IDE')
|
|
|
|
|
|
|
|
|
|
expect(page).not_to have_text('Replace')
|
|
|
|
|
expect(page).not_to have_text('Delete')
|
2018-04-06 10:47:52 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2018-08-12 20:19:35 +00:00
|
|
|
|
context 'when an user has write access', :js do
|
2017-07-12 12:45:42 +00:00
|
|
|
|
before do
|
2018-07-11 14:36:08 +00:00
|
|
|
|
project.add_maintainer(user)
|
2017-07-12 12:45:42 +00:00
|
|
|
|
visit(project_tree_path_root_ref)
|
2018-08-12 20:19:35 +00:00
|
|
|
|
wait_for_requests
|
2017-07-12 12:45:42 +00:00
|
|
|
|
end
|
|
|
|
|
|
2018-08-12 20:19:35 +00:00
|
|
|
|
it 'inserts a content of a file' do
|
2020-10-15 06:09:14 +00:00
|
|
|
|
set_default_button('edit')
|
2017-07-12 12:45:42 +00:00
|
|
|
|
click_link('.gitignore')
|
2020-10-15 06:09:14 +00:00
|
|
|
|
click_link_or_button('Edit')
|
2017-09-18 00:20:57 +00:00
|
|
|
|
find('.file-editor', match: :first)
|
2017-08-09 07:54:32 +00:00
|
|
|
|
|
2022-07-25 12:09:06 +00:00
|
|
|
|
editor_set_value('*.rbca')
|
2017-07-12 12:45:42 +00:00
|
|
|
|
|
2022-07-25 12:09:06 +00:00
|
|
|
|
expect(find('.monaco-editor')).to have_content('*.rbca')
|
2017-07-12 12:45:42 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'does not show the edit link if a file is binary' do
|
|
|
|
|
binary_file = File.join(project.repository.root_ref, 'files/images/logo-black.png')
|
|
|
|
|
visit(project_blob_path(project, binary_file))
|
2018-08-12 20:19:35 +00:00
|
|
|
|
wait_for_requests
|
2017-07-12 12:45:42 +00:00
|
|
|
|
|
2018-01-04 18:31:05 +00:00
|
|
|
|
page.within '.content' do
|
|
|
|
|
expect(page).not_to have_link('edit')
|
|
|
|
|
end
|
2017-07-12 12:45:42 +00:00
|
|
|
|
end
|
|
|
|
|
|
2018-08-12 20:19:35 +00:00
|
|
|
|
it 'commits an edited file' do
|
2020-10-15 06:09:14 +00:00
|
|
|
|
set_default_button('edit')
|
2017-07-12 12:45:42 +00:00
|
|
|
|
click_link('.gitignore')
|
2020-10-15 06:09:14 +00:00
|
|
|
|
click_link_or_button('Edit')
|
2017-09-18 00:20:57 +00:00
|
|
|
|
find('.file-editor', match: :first)
|
2017-08-09 07:54:32 +00:00
|
|
|
|
|
2022-07-25 12:09:06 +00:00
|
|
|
|
editor_set_value('*.rbca')
|
2017-07-12 12:45:42 +00:00
|
|
|
|
fill_in(:commit_message, with: 'New commit message', visible: true)
|
|
|
|
|
click_button('Commit changes')
|
|
|
|
|
|
2022-03-03 15:16:42 +00:00
|
|
|
|
expect(page).to have_current_path(project_blob_path(project, 'master/.gitignore'), ignore_query: true)
|
2017-07-12 12:45:42 +00:00
|
|
|
|
|
|
|
|
|
wait_for_requests
|
|
|
|
|
|
|
|
|
|
expect(page).to have_content('*.rbca')
|
|
|
|
|
end
|
|
|
|
|
|
2018-08-12 20:19:35 +00:00
|
|
|
|
it 'commits an edited file to a new branch' do
|
2020-10-15 06:09:14 +00:00
|
|
|
|
set_default_button('edit')
|
2017-07-12 12:45:42 +00:00
|
|
|
|
click_link('.gitignore')
|
2020-10-15 06:09:14 +00:00
|
|
|
|
click_link_or_button('Edit')
|
2017-08-09 07:54:32 +00:00
|
|
|
|
|
2017-09-18 00:20:57 +00:00
|
|
|
|
find('.file-editor', match: :first)
|
2017-08-09 07:54:32 +00:00
|
|
|
|
|
2022-07-25 12:09:06 +00:00
|
|
|
|
editor_set_value('*.rbca')
|
2017-07-12 12:45:42 +00:00
|
|
|
|
fill_in(:commit_message, with: 'New commit message', visible: true)
|
|
|
|
|
fill_in(:branch_name, with: 'new_branch_name', visible: true)
|
|
|
|
|
click_button('Commit changes')
|
|
|
|
|
|
2022-03-03 15:16:42 +00:00
|
|
|
|
expect(page).to have_current_path(project_new_merge_request_path(project), ignore_query: true)
|
2017-07-12 12:45:42 +00:00
|
|
|
|
|
|
|
|
|
click_link('Changes')
|
|
|
|
|
|
|
|
|
|
expect(page).to have_content('*.rbca')
|
|
|
|
|
end
|
|
|
|
|
|
2022-08-19 15:11:58 +00:00
|
|
|
|
it 'shows loader on commit changes' do
|
|
|
|
|
set_default_button('edit')
|
|
|
|
|
click_link('.gitignore')
|
|
|
|
|
click_link_or_button('Edit')
|
|
|
|
|
|
|
|
|
|
# why: We don't want the form to actually submit, so that we can assert the button's changed state
|
|
|
|
|
page.execute_script("document.querySelector('.js-edit-blob-form').addEventListener('submit', e => e.preventDefault())")
|
|
|
|
|
|
|
|
|
|
find('.file-editor', match: :first)
|
|
|
|
|
editor_set_value('*.rbca')
|
|
|
|
|
click_button('Commit changes')
|
|
|
|
|
|
|
|
|
|
expect(page).to have_button('Commit changes', disabled: true, class: 'js-commit-button-loading')
|
|
|
|
|
end
|
|
|
|
|
|
2018-08-12 20:19:35 +00:00
|
|
|
|
it 'shows the diff of an edited file' do
|
2020-10-15 06:09:14 +00:00
|
|
|
|
set_default_button('edit')
|
2017-07-12 12:45:42 +00:00
|
|
|
|
click_link('.gitignore')
|
2020-10-15 06:09:14 +00:00
|
|
|
|
click_link_or_button('Edit')
|
2017-09-18 00:20:57 +00:00
|
|
|
|
find('.file-editor', match: :first)
|
2017-08-09 07:54:32 +00:00
|
|
|
|
|
2022-07-25 12:09:06 +00:00
|
|
|
|
editor_set_value('*.rbca')
|
2017-07-12 12:45:42 +00:00
|
|
|
|
click_link('Preview changes')
|
|
|
|
|
|
|
|
|
|
expect(page).to have_css('.line_holder.new')
|
|
|
|
|
end
|
2018-04-06 10:47:52 +00:00
|
|
|
|
|
|
|
|
|
it_behaves_like 'unavailable for an archived project'
|
2017-07-12 12:45:42 +00:00
|
|
|
|
end
|
|
|
|
|
|
2018-08-12 20:19:35 +00:00
|
|
|
|
context 'when an user does not have write access', :js do
|
2017-07-12 12:45:42 +00:00
|
|
|
|
before do
|
2017-12-22 08:18:28 +00:00
|
|
|
|
project2.add_reporter(user)
|
2017-07-12 12:45:42 +00:00
|
|
|
|
visit(project2_tree_path_root_ref)
|
2018-08-12 20:19:35 +00:00
|
|
|
|
wait_for_requests
|
2017-07-12 12:45:42 +00:00
|
|
|
|
end
|
|
|
|
|
|
2019-06-20 17:45:01 +00:00
|
|
|
|
def expect_fork_prompt
|
2020-10-15 06:09:14 +00:00
|
|
|
|
expect(page).to have_selector(:link_or_button, 'Fork')
|
|
|
|
|
expect(page).to have_selector(:link_or_button, 'Cancel')
|
2019-06-20 17:45:01 +00:00
|
|
|
|
expect(page).to have_content(
|
2021-05-11 18:10:36 +00:00
|
|
|
|
"You can’t edit files directly in this project. "\
|
|
|
|
|
"Fork this project and submit a merge request with your changes."
|
2019-06-20 17:45:01 +00:00
|
|
|
|
)
|
|
|
|
|
end
|
2017-07-12 12:45:42 +00:00
|
|
|
|
|
2019-06-20 17:45:01 +00:00
|
|
|
|
def expect_fork_status
|
2017-08-11 06:12:45 +00:00
|
|
|
|
expect(page).to have_content(
|
|
|
|
|
"You're not allowed to make changes to this project directly. "\
|
|
|
|
|
"A fork of this project has been created that you can make changes in, so you can submit a merge request."
|
|
|
|
|
)
|
2019-06-20 17:45:01 +00:00
|
|
|
|
end
|
|
|
|
|
|
2019-10-23 09:06:03 +00:00
|
|
|
|
it 'inserts a content of a file in a forked project', :sidekiq_might_not_need_inline do
|
2020-10-15 06:09:14 +00:00
|
|
|
|
set_default_button('edit')
|
2019-06-20 17:45:01 +00:00
|
|
|
|
click_link('.gitignore')
|
2020-10-15 06:09:14 +00:00
|
|
|
|
click_link_or_button('Edit')
|
2019-06-20 17:45:01 +00:00
|
|
|
|
|
|
|
|
|
expect_fork_prompt
|
|
|
|
|
|
2022-01-19 00:12:04 +00:00
|
|
|
|
click_link_or_button('Fork')
|
2019-06-20 17:45:01 +00:00
|
|
|
|
|
|
|
|
|
expect_fork_status
|
2017-07-12 12:45:42 +00:00
|
|
|
|
|
2017-09-18 00:20:57 +00:00
|
|
|
|
find('.file-editor', match: :first)
|
2017-08-09 07:54:32 +00:00
|
|
|
|
|
2022-07-25 12:09:06 +00:00
|
|
|
|
editor_set_value('*.rbca')
|
2017-07-12 12:45:42 +00:00
|
|
|
|
|
2022-07-25 12:09:06 +00:00
|
|
|
|
expect(find('.monaco-editor')).to have_content('*.rbca')
|
2017-07-12 12:45:42 +00:00
|
|
|
|
end
|
|
|
|
|
|
2019-10-23 09:06:03 +00:00
|
|
|
|
it 'opens the Web IDE in a forked project', :sidekiq_might_not_need_inline do
|
2020-10-15 06:09:14 +00:00
|
|
|
|
set_default_button('webide')
|
2019-06-20 17:45:01 +00:00
|
|
|
|
click_link('.gitignore')
|
2020-10-15 06:09:14 +00:00
|
|
|
|
click_link_or_button('Web IDE')
|
2019-06-20 17:45:01 +00:00
|
|
|
|
|
|
|
|
|
expect_fork_prompt
|
|
|
|
|
|
2022-01-19 00:12:04 +00:00
|
|
|
|
click_link_or_button('Fork')
|
2019-06-20 17:45:01 +00:00
|
|
|
|
|
|
|
|
|
expect_fork_status
|
|
|
|
|
|
2019-07-11 17:27:21 +00:00
|
|
|
|
expect(page).to have_css('.ide-sidebar-project-title', text: "#{project2.name} #{user.namespace.full_path}/#{project2.path}")
|
2019-06-20 17:45:01 +00:00
|
|
|
|
expect(page).to have_css('.ide .multi-file-tab', text: '.gitignore')
|
|
|
|
|
end
|
|
|
|
|
|
2019-10-23 09:06:03 +00:00
|
|
|
|
it 'commits an edited file in a forked project', :sidekiq_might_not_need_inline do
|
2020-10-15 06:09:14 +00:00
|
|
|
|
set_default_button('edit')
|
2017-07-12 12:45:42 +00:00
|
|
|
|
click_link('.gitignore')
|
2020-10-15 06:09:14 +00:00
|
|
|
|
click_link_or_button('Edit')
|
2017-07-12 12:45:42 +00:00
|
|
|
|
|
2019-06-20 17:45:01 +00:00
|
|
|
|
expect_fork_prompt
|
2022-01-19 00:12:04 +00:00
|
|
|
|
click_link_or_button('Fork')
|
2017-08-09 07:54:32 +00:00
|
|
|
|
|
2017-09-18 00:20:57 +00:00
|
|
|
|
find('.file-editor', match: :first)
|
2017-08-09 07:54:32 +00:00
|
|
|
|
|
2022-07-25 12:09:06 +00:00
|
|
|
|
editor_set_value('*.rbca')
|
2017-07-12 12:45:42 +00:00
|
|
|
|
fill_in(:commit_message, with: 'New commit message', visible: true)
|
|
|
|
|
click_button('Commit changes')
|
|
|
|
|
|
2017-10-06 10:36:34 +00:00
|
|
|
|
fork = user.fork_of(project2.reload)
|
2017-07-12 12:45:42 +00:00
|
|
|
|
|
2022-03-03 15:16:42 +00:00
|
|
|
|
expect(page).to have_current_path(project_new_merge_request_path(fork), ignore_query: true)
|
2017-07-12 12:45:42 +00:00
|
|
|
|
|
|
|
|
|
wait_for_requests
|
|
|
|
|
|
|
|
|
|
expect(page).to have_content('New commit message')
|
|
|
|
|
end
|
2017-10-06 10:36:34 +00:00
|
|
|
|
|
|
|
|
|
context 'when the user already had a fork of the project', :js do
|
|
|
|
|
let!(:forked_project) { fork_project(project2, user, namespace: user.namespace, repository: true) }
|
2019-12-17 18:07:48 +00:00
|
|
|
|
|
2017-10-06 10:36:34 +00:00
|
|
|
|
before do
|
|
|
|
|
visit(project2_tree_path_root_ref)
|
2018-08-12 20:19:35 +00:00
|
|
|
|
wait_for_requests
|
2017-10-06 10:36:34 +00:00
|
|
|
|
end
|
|
|
|
|
|
2019-10-23 09:06:03 +00:00
|
|
|
|
it 'links to the forked project for editing', :sidekiq_might_not_need_inline do
|
2020-10-15 06:09:14 +00:00
|
|
|
|
set_default_button('edit')
|
2017-10-06 10:36:34 +00:00
|
|
|
|
click_link('.gitignore')
|
2020-10-15 06:09:14 +00:00
|
|
|
|
click_link_or_button('Edit')
|
2017-10-06 10:36:34 +00:00
|
|
|
|
|
2022-01-19 00:12:04 +00:00
|
|
|
|
expect(page).not_to have_link('Fork')
|
2017-10-06 10:36:34 +00:00
|
|
|
|
|
2022-07-25 12:09:06 +00:00
|
|
|
|
editor_set_value('*.rbca')
|
2017-10-06 10:36:34 +00:00
|
|
|
|
fill_in(:commit_message, with: 'Another commit', visible: true)
|
|
|
|
|
click_button('Commit changes')
|
|
|
|
|
|
|
|
|
|
fork = user.fork_of(project2)
|
|
|
|
|
|
2022-03-03 15:16:42 +00:00
|
|
|
|
expect(page).to have_current_path(project_new_merge_request_path(fork), ignore_query: true)
|
2017-10-06 10:36:34 +00:00
|
|
|
|
|
|
|
|
|
wait_for_requests
|
|
|
|
|
|
|
|
|
|
expect(page).to have_content('Another commit')
|
|
|
|
|
expect(page).to have_content("From #{forked_project.full_path}")
|
|
|
|
|
expect(page).to have_content("into #{project2.full_path}")
|
|
|
|
|
end
|
2018-04-06 10:47:52 +00:00
|
|
|
|
|
|
|
|
|
it_behaves_like 'unavailable for an archived project' do
|
|
|
|
|
let(:project) { project2 }
|
|
|
|
|
end
|
2017-10-06 10:36:34 +00:00
|
|
|
|
end
|
2017-07-12 12:45:42 +00:00
|
|
|
|
end
|
|
|
|
|
end
|