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

229 lines
6.8 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
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
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
2017-09-10 17:25:29 +05:30
click_link('.gitignore')
find('.js-edit-blob').click
2018-03-17 18:26:18 +05:30
find('.file-editor', match: :first)
find('#editor')
2020-07-28 23:09:34 +05:30
execute_script("monaco.editor.getModels()[0].setValue('*.rbca')")
2017-09-10 17:25:29 +05:30
2020-07-28 23:09:34 +05:30
expect(evaluate_script('monaco.editor.getModels()[0].getValue()')).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
2017-09-10 17:25:29 +05:30
click_link('.gitignore')
find('.js-edit-blob').click
2018-03-17 18:26:18 +05:30
find('.file-editor', match: :first)
find('#editor')
2020-07-28 23:09:34 +05:30
execute_script("monaco.editor.getModels()[0].setValue('*.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
2017-09-10 17:25:29 +05:30
click_link('.gitignore')
find('.js-edit-blob').click
2018-03-17 18:26:18 +05:30
find('.file-editor', match: :first)
find('#editor')
2020-07-28 23:09:34 +05:30
execute_script("monaco.editor.getModels()[0].setValue('*.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
2017-09-10 17:25:29 +05:30
click_link('.gitignore')
find('.js-edit-blob').click
2018-03-17 18:26:18 +05:30
find('.file-editor', match: :first)
find('#editor')
2020-07-28 23:09:34 +05:30
execute_script("monaco.editor.getModels()[0].setValue('*.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
2017-09-10 17:25:29 +05:30
expect(page).to have_link('Fork')
expect(page).to have_button('Cancel')
2019-09-30 21:07:59 +05:30
expect(page).to have_content(
"You're not allowed to edit files in this project directly. "\
"Please fork this project, make your changes there, and submit a merge request."
)
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
2019-09-30 21:07:59 +05:30
click_link('.gitignore')
click_button('Edit')
expect_fork_prompt
click_link('Fork')
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')
2020-07-28 23:09:34 +05:30
execute_script("monaco.editor.getModels()[0].setValue('*.rbca')")
2017-09-10 17:25:29 +05:30
2020-07-28 23:09:34 +05:30
expect(evaluate_script('monaco.editor.getModels()[0].getValue()')).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
2019-09-30 21:07:59 +05:30
click_link('.gitignore')
click_button('Web IDE')
expect_fork_prompt
click_link('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
2019-12-26 22:10:19 +05:30
it 'commits an edited file in a forked project', :sidekiq_might_not_need_inline do
2017-09-10 17:25:29 +05:30
click_link('.gitignore')
find('.js-edit-blob').click
2019-09-30 21:07:59 +05:30
expect_fork_prompt
2017-09-10 17:25:29 +05:30
click_link('Fork')
2018-03-17 18:26:18 +05:30
find('.file-editor', match: :first)
find('#editor')
2020-07-28 23:09:34 +05:30
execute_script("monaco.editor.getModels()[0].setValue('*.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
2018-03-17 18:26:18 +05:30
click_link('.gitignore')
find('.js-edit-blob').click
expect(page).not_to have_link('Fork')
expect(page).not_to have_button('Cancel')
find('#editor')
2020-07-28 23:09:34 +05:30
execute_script("monaco.editor.getModels()[0].setValue('*.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
2017-09-10 17:25:29 +05:30
end
end