Commit edbbf705 authored by Himanshu Kapoor's avatar Himanshu Kapoor

Fix issue with renaming files

Fix a regression caused by https://gitlab.com/gitlab-org/gitlab/-/merge_requests/30969
that prevented rename from working at all.
parent b9471e57
...@@ -52,7 +52,7 @@ export default { ...@@ -52,7 +52,7 @@ export default {
...mapActions(['createTempEntry', 'renameEntry']), ...mapActions(['createTempEntry', 'renameEntry']),
submitForm() { submitForm() {
if (this.modalType === modalTypes.rename) { if (this.modalType === modalTypes.rename) {
if (!this.entries[this.entryName]?.deleted) { if (this.entries[this.entryName] && !this.entries[this.entryName].deleted) {
flash( flash(
sprintf(s__('The name "%{name}" is already taken in this directory.'), { sprintf(s__('The name "%{name}" is already taken in this directory.'), {
name: this.entryName, name: this.entryName,
......
...@@ -121,8 +121,10 @@ describe('new file modal component', () => { ...@@ -121,8 +121,10 @@ describe('new file modal component', () => {
}); });
describe('submitForm', () => { describe('submitForm', () => {
it('throws an error when target entry exists', () => { let store;
const store = createStore(); beforeEach(() => {
store = createStore();
store.state.entries = { store.state.entries = {
'test-path/test': { 'test-path/test': {
name: 'test', name: 'test',
...@@ -131,6 +133,9 @@ describe('new file modal component', () => { ...@@ -131,6 +133,9 @@ describe('new file modal component', () => {
}; };
vm = createComponentWithStore(Component, store).$mount(); vm = createComponentWithStore(Component, store).$mount();
});
it('throws an error when target entry exists', () => {
vm.open('rename', 'test-path/test'); vm.open('rename', 'test-path/test');
expect(createFlash).not.toHaveBeenCalled(); expect(createFlash).not.toHaveBeenCalled();
...@@ -146,5 +151,15 @@ describe('new file modal component', () => { ...@@ -146,5 +151,15 @@ describe('new file modal component', () => {
true, true,
); );
}); });
it('does not throw error when target entry does not exist', () => {
jest.spyOn(vm, 'renameEntry').mockImplementation();
vm.open('rename', 'test-path/test');
vm.entryName = 'test-path/test2';
vm.submitForm();
expect(createFlash).not.toHaveBeenCalled();
});
}); });
}); });
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