diff --git a/app/assets/javascripts/repo/helpers/repo_helper.js b/app/assets/javascripts/repo/helpers/repo_helper.js index 8b73a1020a0..9e53ffe9a6f 100644 --- a/app/assets/javascripts/repo/helpers/repo_helper.js +++ b/app/assets/javascripts/repo/helpers/repo_helper.js @@ -98,8 +98,8 @@ const RepoHelper = { .then((response) => { const data = response.data; if (response.headers && response.headers['page-title']) data.pageTitle = decodeURI(response.headers['page-title']); - if (response.headers && response.headers['is-root'] && !Store.isInitialRoot) { - Store.isRoot = convertPermissionToBoolean(response.headers['is-root']); + if (data.path && !Store.isInitialRoot) { + Store.isRoot = data.path === '/'; Store.isInitialRoot = Store.isRoot; } @@ -140,6 +140,10 @@ const RepoHelper = { addToDirectory(file, data) { const tree = file || Store; + + // TODO: Figure out why `popstate` is being trigger in the specs + if (!tree.files) return; + const files = tree.files.concat(this.dataToListOfFiles(data, file ? file.level + 1 : 0)); tree.files = files; @@ -236,7 +240,8 @@ const RepoHelper = { return Store.openedFiles.find(file => file.url === path); }, - loadingError() { + loadingError(e) { + console.log(e); Flash('Unable to load this content at this time.'); }, diff --git a/app/controllers/projects/tree_controller.rb b/app/controllers/projects/tree_controller.rb index 756f7e5df8c..f3719059f88 100644 --- a/app/controllers/projects/tree_controller.rb +++ b/app/controllers/projects/tree_controller.rb @@ -36,7 +36,6 @@ class Projects::TreeController < Projects::ApplicationController format.json do page_title @path.presence || _("Files"), @ref, @project.name_with_namespace - response.header['is-root'] = @path.empty? # n+1: https://gitlab.com/gitlab-org/gitlab-ce/issues/38261 Gitlab::GitalyClient.allow_n_plus_1_calls do diff --git a/spec/features/projects/tree/create_directory_spec.rb b/spec/features/projects/tree/create_directory_spec.rb new file mode 100644 index 00000000000..4c1fa5a666e --- /dev/null +++ b/spec/features/projects/tree/create_directory_spec.rb @@ -0,0 +1,43 @@ +require 'spec_helper' + +feature 'Multi-file editor new directory', :js do + include WaitForRequests + + let(:user) { create(:user) } + let(:project) { create(:project, :repository) } + + before do + project.add_master(user) + sign_in(user) + + page.driver.set_cookie('new_repo', 'true') + + visit project_tree_path(project, :master) + + wait_for_requests + end + + it 'creates directory in current directory' do + find('.add-to-tree').click + + click_link('New directory') + + page.within('.popup-dialog') do + find('.form-control').set('foldername') + + click_button('Create directory') + end + + fill_in('commit-message', with: 'commit message') + + click_button('Commit 1 file') + + expect(page).to have_content('Your changes have been committed') + expect(page).to have_selector('td', text: 'commit message') + + click_link('foldername') + + expect(page).to have_selector('td', text: 'commit message', count: 2) + expect(page).to have_selector('td', text: '.gitkeep') + end +end diff --git a/spec/features/projects/tree/create_file_spec.rb b/spec/features/projects/tree/create_file_spec.rb new file mode 100644 index 00000000000..a67ec891e7c --- /dev/null +++ b/spec/features/projects/tree/create_file_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +feature 'Multi-file editor new file', :js do + include WaitForRequests + + let(:user) { create(:user) } + let(:project) { create(:project, :repository) } + + before do + project.add_master(user) + sign_in(user) + + page.driver.set_cookie('new_repo', 'true') + + visit project_tree_path(project, :master) + + wait_for_requests + end + + it 'creates file in current directory' do + find('.add-to-tree').click + + click_link('New file') + + page.within('.popup-dialog') do + find('.form-control').set('filename') + + click_button('Create file') + end + + find('.inputarea').send_keys('file content') + + fill_in('commit-message', with: 'commit message') + + click_button('Commit 1 file') + + expect(page).to have_content('Your changes have been committed') + expect(page).to have_selector('td', text: 'commit message') + end +end diff --git a/spec/javascripts/repo/components/new_dropdown/modal_spec.js b/spec/javascripts/repo/components/new_dropdown/modal_spec.js index 4be92e9d944..671dca93a09 100644 --- a/spec/javascripts/repo/components/new_dropdown/modal_spec.js +++ b/spec/javascripts/repo/components/new_dropdown/modal_spec.js @@ -71,6 +71,22 @@ describe('new file modal component', () => { expect(RepoStore.openedFiles.length).toBe(1); }); + + it(`creates ${type} in the current stores path`, () => { + RepoStore.path = 'testing'; + vm.entryName = 'testing/app'; + + vm.$el.querySelector('.btn-success').click(); + + expect(RepoStore.files[0].path).toBe('testing/app'); + expect(RepoStore.files[0].name).toBe('app'); + + if (type === 'tree') { + expect(RepoStore.files[0].files.length).toBe(1); + } + + RepoStore.path = ''; + }); }); });