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 {
...mapActions(['createTempEntry', 'renameEntry']),
submitForm() {
if (this.modalType === modalTypes.rename) {
if (!this.entries[this.entryName]?.deleted) {
if (this.entries[this.entryName] && !this.entries[this.entryName].deleted) {
flash(
sprintf(s__('The name "%{name}" is already taken in this directory.'), {
name: this.entryName,
......
......@@ -121,8 +121,10 @@ describe('new file modal component', () => {
});
describe('submitForm', () => {
it('throws an error when target entry exists', () => {
const store = createStore();
let store;
beforeEach(() => {
store = createStore();
store.state.entries = {
'test-path/test': {
name: 'test',
......@@ -131,6 +133,9 @@ describe('new file modal component', () => {
};
vm = createComponentWithStore(Component, store).$mount();
});
it('throws an error when target entry exists', () => {
vm.open('rename', 'test-path/test');
expect(createFlash).not.toHaveBeenCalled();
......@@ -146,5 +151,15 @@ describe('new file modal component', () => {
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