2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-01-15 13:20:01 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
describe 'Editing file blob', :js do
|
2017-08-17 22:00:37 +05:30
|
|
|
include TreeHelper
|
2017-01-15 13:20:01 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:project) { create(:project, :public, :repository) }
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:merge_request) { create(:merge_request, source_project: project, source_branch: 'feature', target_branch: 'master') }
|
|
|
|
let(:branch) { 'master' }
|
|
|
|
let(:file_path) { project.repository.ls_files(project.repository.root_ref)[1] }
|
2018-11-20 20:47:30 +05:30
|
|
|
let(:readme_file_path) { 'README.md' }
|
2017-01-15 13:20:01 +05:30
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
before do
|
2020-03-13 15:44:24 +05:30
|
|
|
stub_feature_flags(web_ide_default: false)
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
context 'as a developer' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:role) { :developer }
|
2017-01-15 13:20:01 +05:30
|
|
|
|
|
|
|
before do
|
2018-03-17 18:26:18 +05:30
|
|
|
project.add_role(user, role)
|
2017-09-10 17:25:29 +05:30
|
|
|
sign_in(user)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def edit_and_commit(commit_changes: true)
|
2017-09-10 17:25:29 +05:30
|
|
|
wait_for_requests
|
2017-08-17 22:00:37 +05:30
|
|
|
find('.js-edit-blob').click
|
2019-12-26 22:10:19 +05:30
|
|
|
fill_editor(content: 'class NextFeature\\nend\\n')
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
if commit_changes
|
|
|
|
click_button 'Commit changes'
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
def fill_editor(content: 'class NextFeature\\nend\\n')
|
2018-11-20 20:47:30 +05:30
|
|
|
wait_for_requests
|
|
|
|
find('#editor')
|
|
|
|
execute_script("ace.edit('editor').setValue('#{content}')")
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
context 'from MR diff' do
|
|
|
|
before do
|
2017-09-10 17:25:29 +05:30
|
|
|
visit diffs_project_merge_request_path(project, merge_request)
|
2017-08-17 22:00:37 +05:30
|
|
|
edit_and_commit
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns me to the mr' do
|
|
|
|
expect(page).to have_content(merge_request.title)
|
|
|
|
end
|
2017-01-15 13:20:01 +05:30
|
|
|
end
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
it 'updates the content of file with a number as file path' do
|
|
|
|
project.repository.create_file(user, '1', 'test', message: 'testing', branch_name: branch)
|
|
|
|
visit project_blob_path(project, tree_join(branch, '1'))
|
|
|
|
|
|
|
|
edit_and_commit
|
|
|
|
|
|
|
|
expect(page).to have_content 'NextFeature'
|
|
|
|
end
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
it 'editing a template file in a sub directory does not change path' do
|
|
|
|
project.repository.create_file(user, 'ci/.gitlab-ci.yml', 'test', message: 'testing', branch_name: branch)
|
|
|
|
visit project_edit_blob_path(project, tree_join(branch, 'ci/.gitlab-ci.yml'))
|
|
|
|
|
|
|
|
expect(find_by_id('file_path').value).to eq('ci/.gitlab-ci.yml')
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
context 'from blob file path' do
|
|
|
|
before do
|
2020-03-13 15:44:24 +05:30
|
|
|
stub_feature_flags(code_navigation: false)
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
visit project_blob_path(project, tree_join(branch, file_path))
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates content' do
|
2018-03-17 18:26:18 +05:30
|
|
|
edit_and_commit
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(page).to have_content 'successfully committed'
|
|
|
|
expect(page).to have_content 'NextFeature'
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
it 'previews content' do
|
|
|
|
edit_and_commit(commit_changes: false)
|
|
|
|
click_link 'Preview changes'
|
|
|
|
wait_for_requests
|
|
|
|
|
|
|
|
old_line_count = page.all('.line_holder.old').size
|
|
|
|
new_line_count = page.all('.line_holder.new').size
|
|
|
|
|
|
|
|
expect(old_line_count).to be > 0
|
|
|
|
expect(new_line_count).to be > 0
|
|
|
|
end
|
2017-01-15 13:20:01 +05:30
|
|
|
end
|
2018-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
context 'when rendering the preview' do
|
|
|
|
it 'renders content with CommonMark' do
|
|
|
|
visit project_edit_blob_path(project, tree_join(branch, readme_file_path))
|
2019-12-26 22:10:19 +05:30
|
|
|
fill_editor(content: '1. one\\n - sublist\\n')
|
2018-11-20 20:47:30 +05:30
|
|
|
click_link 'Preview'
|
|
|
|
wait_for_requests
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
# the above generates two separate lists (not embedded) in CommonMark
|
2019-12-26 22:10:19 +05:30
|
|
|
expect(page).to have_content('sublist')
|
|
|
|
expect(page).not_to have_xpath('//ol//li//ul')
|
2018-11-20 20:47:30 +05:30
|
|
|
end
|
|
|
|
end
|
2017-01-15 13:20:01 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
context 'visit blob edit' do
|
|
|
|
context 'redirects to sign in and returns' do
|
|
|
|
context 'as developer' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
2018-03-17 18:26:18 +05:30
|
|
|
project.add_developer(user)
|
2017-09-10 17:25:29 +05:30
|
|
|
visit project_edit_blob_path(project, tree_join(branch, file_path))
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'redirects to sign in and returns' do
|
|
|
|
expect(page).to have_current_path(new_user_session_path)
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
gitlab_sign_in(user)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(page).to have_current_path(project_edit_blob_path(project, tree_join(branch, file_path)))
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'as guest' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
2017-09-10 17:25:29 +05:30
|
|
|
visit project_edit_blob_path(project, tree_join(branch, file_path))
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'redirects to sign in and returns' do
|
|
|
|
expect(page).to have_current_path(new_user_session_path)
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
gitlab_sign_in(user)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(page).to have_current_path(project_blob_path(project, tree_join(branch, file_path)))
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'as developer' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:protected_branch) { 'protected-branch' }
|
|
|
|
|
|
|
|
before do
|
2018-03-17 18:26:18 +05:30
|
|
|
project.add_developer(user)
|
2017-08-17 22:00:37 +05:30
|
|
|
project.repository.add_branch(user, protected_branch, 'master')
|
|
|
|
create(:protected_branch, project: project, name: protected_branch)
|
2017-09-10 17:25:29 +05:30
|
|
|
sign_in(user)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'on some branch' do
|
|
|
|
before do
|
2017-09-10 17:25:29 +05:30
|
|
|
visit project_edit_blob_path(project, tree_join(branch, file_path))
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows blob editor with same branch' do
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(page).to have_current_path(project_edit_blob_path(project, tree_join(branch, file_path)))
|
|
|
|
expect(find('.js-branch-name').value).to eq(branch)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with protected branch' do
|
|
|
|
before do
|
2017-09-10 17:25:29 +05:30
|
|
|
visit project_edit_blob_path(project, tree_join(protected_branch, file_path))
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows blob editor with patch branch' do
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(find('.js-branch-name').value).to eq('patch-1')
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
2017-01-15 13:20:01 +05:30
|
|
|
end
|
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
context 'as maintainer' do
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
2018-11-18 11:00:15 +05:30
|
|
|
project.add_maintainer(user)
|
2017-09-10 17:25:29 +05:30
|
|
|
sign_in(user)
|
|
|
|
visit project_edit_blob_path(project, tree_join(branch, file_path))
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows blob editor with same branch' do
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(page).to have_current_path(project_edit_blob_path(project, tree_join(branch, file_path)))
|
|
|
|
expect(find('.js-branch-name').value).to eq(branch)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2017-01-15 13:20:01 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|