2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-01-15 13:20:01 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
RSpec.describe 'Editing file blob', :js, feature_category: :projects do
|
2023-06-20 00:43:36 +05:30
|
|
|
include Features::SourceEditorSpecHelpers
|
2017-08-17 22:00:37 +05:30
|
|
|
include TreeHelper
|
2023-06-20 00:43:36 +05:30
|
|
|
include Features::BlobSpecHelpers
|
2017-01-15 13:20:01 +05:30
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
let_it_be(:project) { create(:project, :public, :repository) }
|
|
|
|
let_it_be(:merge_request) { create(:merge_request, source_project: project, source_branch: 'feature', target_branch: 'master') }
|
2017-08-17 22:00:37 +05:30
|
|
|
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
|
|
|
|
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
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
def edit_and_commit(commit_changes: true, is_diff: false)
|
|
|
|
set_default_button('edit')
|
|
|
|
refresh
|
2017-09-10 17:25:29 +05:30
|
|
|
wait_for_requests
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
if is_diff
|
|
|
|
first('.js-diff-more-actions').click
|
|
|
|
click_link('Edit in single-file editor')
|
|
|
|
else
|
|
|
|
click_link('Edit')
|
|
|
|
end
|
|
|
|
|
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
|
2022-08-27 11:52:29 +05:30
|
|
|
editor_set_value(content)
|
2018-11-20 20:47:30 +05:30
|
|
|
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)
|
2021-01-03 14:25:43 +05:30
|
|
|
edit_and_commit(is_diff: true)
|
2017-08-17 22:00:37 +05:30
|
|
|
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
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
it 'updating file path updates syntax highlighting' do
|
|
|
|
visit project_edit_blob_path(project, tree_join(branch, readme_file_path))
|
|
|
|
expect(find('#editor')['data-mode-id']).to eq('markdown')
|
|
|
|
|
|
|
|
find('#file_path').send_keys('foo.txt') do
|
|
|
|
expect(find('#editor')['data-mode-id']).to eq('plaintext')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
context 'blob edit toolbar' do
|
|
|
|
toolbar_buttons = [
|
|
|
|
"Add bold text",
|
|
|
|
"Add italic text",
|
|
|
|
"Add strikethrough text",
|
|
|
|
"Insert a quote",
|
|
|
|
"Insert code",
|
|
|
|
"Add a link",
|
|
|
|
"Add a bullet list",
|
|
|
|
"Add a numbered list",
|
|
|
|
"Add a checklist",
|
|
|
|
"Add a collapsible section",
|
|
|
|
"Add a table"
|
|
|
|
]
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
it "does not have any buttons" do
|
|
|
|
stub_feature_flags(source_editor_toolbar: true)
|
2022-11-25 23:54:43 +05:30
|
|
|
visit project_edit_blob_path(project, tree_join(branch, readme_file_path))
|
2023-03-04 22:38:38 +05:30
|
|
|
buttons = page.all('.file-buttons .md-header-toolbar button[type="button"]')
|
|
|
|
expect(buttons.length).to eq(0)
|
2022-11-25 23:54:43 +05:30
|
|
|
end
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
it "has defined set of toolbar buttons when the flag is off" do
|
|
|
|
stub_feature_flags(source_editor_toolbar: false)
|
|
|
|
visit project_edit_blob_path(project, tree_join(branch, readme_file_path))
|
2022-11-25 23:54:43 +05:30
|
|
|
buttons = page.all('.file-buttons .md-header-toolbar button[type="button"]')
|
|
|
|
expect(buttons.length).to eq(toolbar_buttons.length)
|
|
|
|
toolbar_buttons.each_with_index do |button_title, i|
|
|
|
|
expect(buttons[i]['title']).to include(button_title)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
context 'from blob file path' do
|
|
|
|
before do
|
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
|
|
|
|
|
|
|
|
new_line_count = page.all('.line_holder.new').size
|
|
|
|
|
|
|
|
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
|
2022-11-25 23:54:43 +05:30
|
|
|
let_it_be(:user) { create(:user) }
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:protected_branch) { 'protected-branch' }
|
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
before_all do
|
2018-03-17 18:26:18 +05:30
|
|
|
project.add_developer(user)
|
2022-11-25 23:54:43 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
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
|
|
|
|
it 'shows blob editor with patch branch' do
|
2021-01-29 00:20:46 +05:30
|
|
|
freeze_time do
|
|
|
|
visit project_edit_blob_path(project, tree_join(protected_branch, file_path))
|
|
|
|
|
2022-05-07 20:08:51 +05:30
|
|
|
epoch = Time.zone.now.strftime('%s%L').last(5)
|
2021-01-29 00:20:46 +05:30
|
|
|
|
|
|
|
expect(find('.js-branch-name').value).to eq "#{user.username}-protected-branch-patch-#{epoch}"
|
|
|
|
end
|
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
|