added feature spec

This commit is contained in:
Phil Hughes 2017-10-20 10:47:45 +01:00
parent 4c186f99f2
commit 4699cf77b6
No known key found for this signature in database
GPG key ID: 32245528C52E0F9F
5 changed files with 107 additions and 4 deletions

View file

@ -98,8 +98,8 @@ const RepoHelper = {
.then((response) => { .then((response) => {
const data = response.data; const data = response.data;
if (response.headers && response.headers['page-title']) data.pageTitle = decodeURI(response.headers['page-title']); if (response.headers && response.headers['page-title']) data.pageTitle = decodeURI(response.headers['page-title']);
if (response.headers && response.headers['is-root'] && !Store.isInitialRoot) { if (data.path && !Store.isInitialRoot) {
Store.isRoot = convertPermissionToBoolean(response.headers['is-root']); Store.isRoot = data.path === '/';
Store.isInitialRoot = Store.isRoot; Store.isInitialRoot = Store.isRoot;
} }
@ -140,6 +140,10 @@ const RepoHelper = {
addToDirectory(file, data) { addToDirectory(file, data) {
const tree = file || Store; 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)); const files = tree.files.concat(this.dataToListOfFiles(data, file ? file.level + 1 : 0));
tree.files = files; tree.files = files;
@ -236,7 +240,8 @@ const RepoHelper = {
return Store.openedFiles.find(file => file.url === path); return Store.openedFiles.find(file => file.url === path);
}, },
loadingError() { loadingError(e) {
console.log(e);
Flash('Unable to load this content at this time.'); Flash('Unable to load this content at this time.');
}, },

View file

@ -36,7 +36,6 @@ class Projects::TreeController < Projects::ApplicationController
format.json do format.json do
page_title @path.presence || _("Files"), @ref, @project.name_with_namespace 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 # n+1: https://gitlab.com/gitlab-org/gitlab-ce/issues/38261
Gitlab::GitalyClient.allow_n_plus_1_calls do Gitlab::GitalyClient.allow_n_plus_1_calls do

View file

@ -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

View file

@ -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

View file

@ -71,6 +71,22 @@ describe('new file modal component', () => {
expect(RepoStore.openedFiles.length).toBe(1); 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 = '';
});
}); });
}); });