Commit 5bcd56e6 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'templates-current-folder-fix' into 'master'

Create template files in the folder from which new file request was made

See merge request gitlab-org/gitlab!33585
parents e15a71bc 107333e3
......@@ -4,7 +4,7 @@ import flash from '~/flash';
import { __, sprintf, s__ } from '~/locale';
import { GlModal } from '@gitlab/ui';
import { modalTypes } from '../../constants';
import { trimPathComponents } from '../../utils';
import { trimPathComponents, getPathParent } from '../../utils';
export default {
components: {
......@@ -85,8 +85,10 @@ export default {
}
},
createFromTemplate(template) {
const parent = getPathParent(this.entryName);
const name = parent ? `${parent}/${template.name}` : template.name;
this.createTempEntry({
name: template.name,
name,
type: this.modalType,
});
......
---
title: "Web IDE: Create template files in the folder from which new file request was made"
merge_request: 33585
author: Ashesh Vidyut
type: fixed
......@@ -120,6 +120,46 @@ describe('new file modal component', () => {
});
});
describe('createFromTemplate', () => {
let store;
beforeEach(() => {
store = createStore();
store.state.entries = {
'test-path/test': {
name: 'test',
deleted: false,
},
};
vm = createComponentWithStore(Component, store).$mount();
vm.open('blob');
jest.spyOn(vm, 'createTempEntry').mockImplementation();
});
it.each`
entryName | newFilePath
${''} | ${'.gitignore'}
${'README.md'} | ${'.gitignore'}
${'test-path/test/'} | ${'test-path/test/.gitignore'}
${'test-path/test'} | ${'test-path/.gitignore'}
${'test-path/test/abc.md'} | ${'test-path/test/.gitignore'}
`(
'creates a new file with the given template name in appropriate directory for path: $path',
({ entryName, newFilePath }) => {
vm.entryName = entryName;
vm.createFromTemplate({ name: '.gitignore' });
expect(vm.createTempEntry).toHaveBeenCalledWith({
name: newFilePath,
type: 'blob',
});
},
);
});
describe('submitForm', () => {
let store;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment