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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

252 lines
7.5 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'
2023-03-04 22:38:38 +05:30
RSpec.describe 'Projects > Files > User edits files', :js, feature_category: :projects do
2023-06-20 00:43:36 +05:30
include Features::SourceEditorSpecHelpers
2018-03-17 18:26:18 +05:30
include ProjectForksHelper
2023-06-20 00:43:36 +05:30
include Features::BlobSpecHelpers
2021-01-03 14:25:43 +05:30
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
2022-10-11 01:57:18 +05:30
stub_feature_flags(vscode_web_ide: false)
2017-09-10 17:25:29 +05:30
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)
2022-08-27 11:52:29 +05:30
editor_set_value('*.rbca')
2017-09-10 17:25:29 +05:30
2022-08-27 11:52:29 +05:30
expect(find('.monaco-editor')).to have_content('*.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)
2022-08-27 11:52:29 +05:30
editor_set_value('*.rbca')
2017-09-10 17:25:29 +05:30
fill_in(:commit_message, with: 'New commit message', visible: true)
click_button('Commit changes')
2022-05-07 20:08:51 +05:30
expect(page).to have_current_path(project_blob_path(project, 'master/.gitignore'), ignore_query: true)
2017-09-10 17:25:29 +05:30
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)
2022-08-27 11:52:29 +05:30
editor_set_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')
2022-05-07 20:08:51 +05:30
expect(page).to have_current_path(project_new_merge_request_path(project), ignore_query: true)
2017-09-10 17:25:29 +05:30
click_link('Changes')
expect(page).to have_content('*.rbca')
end
2022-10-11 01:57:18 +05:30
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-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)
2022-08-27 11:52:29 +05:30
editor_set_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
2022-03-02 08:16:31 +05:30
click_link_or_button('Fork')
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
2022-08-27 11:52:29 +05:30
editor_set_value('*.rbca')
2017-09-10 17:25:29 +05:30
2022-08-27 11:52:29 +05:30
expect(find('.monaco-editor')).to have_content('*.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
2022-03-02 08:16:31 +05:30
click_link_or_button('Fork')
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
2022-03-02 08:16:31 +05:30
click_link_or_button('Fork')
2018-03-17 18:26:18 +05:30
find('.file-editor', match: :first)
2022-08-27 11:52:29 +05:30
editor_set_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
2022-05-07 20:08:51 +05:30
expect(page).to have_current_path(project_new_merge_request_path(fork), ignore_query: true)
2017-09-10 17:25:29 +05:30
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
2022-03-02 08:16:31 +05:30
expect(page).not_to have_link('Fork')
2018-03-17 18:26:18 +05:30
2022-08-27 11:52:29 +05:30
editor_set_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)
2022-05-07 20:08:51 +05:30
expect(page).to have_current_path(project_new_merge_request_path(fork), ignore_query: true)
2018-03-17 18:26:18 +05:30
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