debian-mirror-gitlab/spec/features/projects/files/user_edits_files_spec.rb

352 lines
10 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
require 'spec_helper'
2020-06-23 00:09:42 +05:30
RSpec.describe 'Projects > Files > User edits files', :js do
2018-03-17 18:26:18 +05:30
include ProjectForksHelper
2021-01-03 14:25:43 +05:30
include BlobSpecHelpers
2017-09-10 17:25:29 +05:30
let(:project) { create(:project, :repository, name: 'Shop') }
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
sign_in(user)
end
2021-01-03 14:25:43 +05:30
after do
unset_default_button
end
2018-05-09 12:01:36 +05:30
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
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')
end
end
end
2018-11-20 20:47:30 +05:30
context 'when an user has write access', :js do
2017-09-10 17:25:29 +05:30
before do
2018-11-18 11:00:15 +05:30
project.add_maintainer(user)
2017-09-10 17:25:29 +05:30
visit(project_tree_path_root_ref)
2018-11-20 20:47:30 +05:30
wait_for_requests
2017-09-10 17:25:29 +05:30
end
2018-11-20 20:47:30 +05:30
it 'inserts a content of a file' do
2021-01-03 14:25:43 +05:30
set_default_button('edit')
2017-09-10 17:25:29 +05:30
click_link('.gitignore')
2021-01-03 14:25:43 +05:30
click_link_or_button('Edit')
2018-03-17 18:26:18 +05:30
find('.file-editor', match: :first)
find('#editor')
2021-01-03 14:25:43 +05:30
set_editor_value('*.rbca')
2017-09-10 17:25:29 +05:30
2021-01-03 14:25:43 +05:30
expect(editor_value).to eq('*.rbca')
2017-09-10 17:25:29 +05:30
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-11-20 20:47:30 +05:30
wait_for_requests
2017-09-10 17:25:29 +05:30
2018-03-17 18:26:18 +05:30
page.within '.content' do
expect(page).not_to have_link('edit')
end
2017-09-10 17:25:29 +05:30
end
2018-11-20 20:47:30 +05:30
it 'commits an edited file' do
2021-01-03 14:25:43 +05:30
set_default_button('edit')
2017-09-10 17:25:29 +05:30
click_link('.gitignore')
2021-01-03 14:25:43 +05:30
click_link_or_button('Edit')
2018-03-17 18:26:18 +05:30
find('.file-editor', match: :first)
find('#editor')
2021-01-03 14:25:43 +05:30
set_editor_value('*.rbca')
2017-09-10 17:25:29 +05:30
fill_in(:commit_message, with: 'New commit message', visible: true)
click_button('Commit changes')
expect(current_path).to eq(project_blob_path(project, 'master/.gitignore'))
wait_for_requests
expect(page).to have_content('*.rbca')
end
2018-11-20 20:47:30 +05:30
it 'commits an edited file to a new branch' do
2021-01-03 14:25:43 +05:30
set_default_button('edit')
2017-09-10 17:25:29 +05:30
click_link('.gitignore')
2021-01-03 14:25:43 +05:30
click_link_or_button('Edit')
2018-03-17 18:26:18 +05:30
find('.file-editor', match: :first)
find('#editor')
2021-01-03 14:25:43 +05:30
set_editor_value('*.rbca')
2017-09-10 17:25:29 +05:30
fill_in(:commit_message, with: 'New commit message', visible: true)
fill_in(:branch_name, with: 'new_branch_name', visible: true)
click_button('Commit changes')
expect(current_path).to eq(project_new_merge_request_path(project))
click_link('Changes')
expect(page).to have_content('*.rbca')
end
2018-11-20 20:47:30 +05:30
it 'shows the diff of an edited file' do
2021-01-03 14:25:43 +05:30
set_default_button('edit')
2017-09-10 17:25:29 +05:30
click_link('.gitignore')
2021-01-03 14:25:43 +05:30
click_link_or_button('Edit')
2018-03-17 18:26:18 +05:30
find('.file-editor', match: :first)
find('#editor')
2021-01-03 14:25:43 +05:30
set_editor_value('*.rbca')
2017-09-10 17:25:29 +05:30
click_link('Preview changes')
expect(page).to have_css('.line_holder.new')
end
2018-05-09 12:01:36 +05:30
it_behaves_like 'unavailable for an archived project'
2017-09-10 17:25:29 +05:30
end
2018-11-20 20:47:30 +05:30
context 'when an user does not have write access', :js do
2017-09-10 17:25:29 +05:30
before do
2018-03-17 18:26:18 +05:30
project2.add_reporter(user)
2017-09-10 17:25:29 +05:30
visit(project2_tree_path_root_ref)
2018-11-20 20:47:30 +05:30
wait_for_requests
2017-09-10 17:25:29 +05:30
end
2019-09-30 21:07:59 +05:30
def expect_fork_prompt
2021-01-03 14:25:43 +05:30
expect(page).to have_selector(:link_or_button, 'Fork')
expect(page).to have_selector(:link_or_button, 'Cancel')
2019-09-30 21:07:59 +05:30
expect(page).to have_content(
2021-06-08 01:23:25 +05:30
"You cant edit files directly in this project. "\
"Fork this project and submit a merge request with your changes."
2019-09-30 21:07:59 +05:30
)
end
2017-09-10 17:25:29 +05:30
2019-09-30 21:07:59 +05:30
def expect_fork_status
2018-03-17 18:26:18 +05:30
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-09-30 21:07:59 +05:30
end
2019-12-26 22:10:19 +05:30
it 'inserts a content of a file in a forked project', :sidekiq_might_not_need_inline do
2021-01-03 14:25:43 +05:30
set_default_button('edit')
2019-09-30 21:07:59 +05:30
click_link('.gitignore')
2021-01-03 14:25:43 +05:30
click_link_or_button('Edit')
2019-09-30 21:07:59 +05:30
expect_fork_prompt
2021-01-03 14:25:43 +05:30
click_link_or_button('Fork project')
2019-09-30 21:07:59 +05:30
expect_fork_status
2018-03-17 18:26:18 +05:30
find('.file-editor', match: :first)
2017-09-10 17:25:29 +05:30
2018-03-17 18:26:18 +05:30
find('#editor')
2021-01-03 14:25:43 +05:30
set_editor_value('*.rbca')
2017-09-10 17:25:29 +05:30
2021-01-03 14:25:43 +05:30
expect(editor_value).to eq('*.rbca')
2017-09-10 17:25:29 +05:30
end
2019-12-26 22:10:19 +05:30
it 'opens the Web IDE in a forked project', :sidekiq_might_not_need_inline do
2021-01-03 14:25:43 +05:30
set_default_button('webide')
2019-09-30 21:07:59 +05:30
click_link('.gitignore')
2021-01-03 14:25:43 +05:30
click_link_or_button('Web IDE')
2019-09-30 21:07:59 +05:30
expect_fork_prompt
2021-01-03 14:25:43 +05:30
click_link_or_button('Fork project')
2019-09-30 21:07:59 +05:30
expect_fork_status
expect(page).to have_css('.ide-sidebar-project-title', text: "#{project2.name} #{user.namespace.full_path}/#{project2.path}")
expect(page).to have_css('.ide .multi-file-tab', text: '.gitignore')
end
2019-12-26 22:10:19 +05:30
it 'commits an edited file in a forked project', :sidekiq_might_not_need_inline do
2021-01-03 14:25:43 +05:30
set_default_button('edit')
2017-09-10 17:25:29 +05:30
click_link('.gitignore')
2021-01-03 14:25:43 +05:30
click_link_or_button('Edit')
2017-09-10 17:25:29 +05:30
2019-09-30 21:07:59 +05:30
expect_fork_prompt
2021-01-03 14:25:43 +05:30
click_link_or_button('Fork project')
2018-03-17 18:26:18 +05:30
find('.file-editor', match: :first)
find('#editor')
2021-01-03 14:25:43 +05:30
set_editor_value('*.rbca')
2017-09-10 17:25:29 +05:30
fill_in(:commit_message, with: 'New commit message', visible: true)
click_button('Commit changes')
2018-03-17 18:26:18 +05:30
fork = user.fork_of(project2.reload)
2017-09-10 17:25:29 +05:30
expect(current_path).to eq(project_new_merge_request_path(fork))
wait_for_requests
expect(page).to have_content('New commit message')
end
2018-03-17 18:26:18 +05:30
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) }
2020-01-01 13:55:28 +05:30
2018-03-17 18:26:18 +05:30
before do
visit(project2_tree_path_root_ref)
2018-11-20 20:47:30 +05:30
wait_for_requests
2018-03-17 18:26:18 +05:30
end
2019-12-26 22:10:19 +05:30
it 'links to the forked project for editing', :sidekiq_might_not_need_inline do
2021-01-03 14:25:43 +05:30
set_default_button('edit')
2018-03-17 18:26:18 +05:30
click_link('.gitignore')
2021-01-03 14:25:43 +05:30
click_link_or_button('Edit')
2018-03-17 18:26:18 +05:30
2021-01-03 14:25:43 +05:30
expect(page).not_to have_link('Fork project')
2018-03-17 18:26:18 +05:30
find('#editor')
2021-01-03 14:25:43 +05:30
set_editor_value('*.rbca')
2018-03-17 18:26:18 +05:30
fill_in(:commit_message, with: 'Another commit', visible: true)
click_button('Commit changes')
fork = user.fork_of(project2)
expect(current_path).to eq(project_new_merge_request_path(fork))
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-05-09 12:01:36 +05:30
it_behaves_like 'unavailable for an archived project' do
let(:project) { project2 }
end
2018-03-17 18:26:18 +05:30
end
2021-01-03 14:25:43 +05:30
context 'when feature flag :consolidated_edit_button is off' do
before do
stub_feature_flags(consolidated_edit_button: false)
end
context 'when an user does not have write access', :js do
before do
project2.add_reporter(user)
visit(project2_tree_path_root_ref)
wait_for_requests
end
it 'inserts a content of a file in a forked project', :sidekiq_might_not_need_inline do
set_default_button('edit')
click_link('.gitignore')
click_link_or_button('Edit')
expect_fork_prompt
click_link_or_button('Fork')
expect_fork_status
find('.file-editor', match: :first)
find('#editor')
set_editor_value('*.rbca')
expect(editor_value).to eq('*.rbca')
end
it 'opens the Web IDE in a forked project', :sidekiq_might_not_need_inline do
set_default_button('webide')
click_link('.gitignore')
click_link_or_button('Web IDE')
expect_fork_prompt
click_link_or_button('Fork')
expect_fork_status
expect(page).to have_css('.ide-sidebar-project-title', text: "#{project2.name} #{user.namespace.full_path}/#{project2.path}")
expect(page).to have_css('.ide .multi-file-tab', text: '.gitignore')
end
it 'commits an edited file in a forked project', :sidekiq_might_not_need_inline do
set_default_button('edit')
click_link('.gitignore')
click_link_or_button('Edit')
expect_fork_prompt
click_link_or_button('Fork')
expect_fork_status
find('.file-editor', match: :first)
find('#editor')
set_editor_value('*.rbca')
fill_in(:commit_message, with: 'New commit message', visible: true)
click_button('Commit changes')
fork = user.fork_of(project2.reload)
expect(current_path).to eq(project_new_merge_request_path(fork))
wait_for_requests
expect(page).to have_content('New commit message')
end
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) }
before do
visit(project2_tree_path_root_ref)
wait_for_requests
end
it 'links to the forked project for editing', :sidekiq_might_not_need_inline do
set_default_button('edit')
click_link('.gitignore')
click_link_or_button('Edit')
expect(page).not_to have_link('Fork')
find('#editor')
set_editor_value('*.rbca')
fill_in(:commit_message, with: 'Another commit', visible: true)
click_button('Commit changes')
fork = user.fork_of(project2)
expect(current_path).to eq(project_new_merge_request_path(fork))
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
it_behaves_like 'unavailable for an archived project' do
let(:project) { project2 }
end
end
end
end
2017-09-10 17:25:29 +05:30
end
end