Commit 00c63483 authored by Phil Hughes's avatar Phil Hughes

Merge branch '31859-fix-discarding-renamed-entry-with-changes' into 'master'

Resolve "Web IDE: Discarding changes on re-named entries"

See merge request gitlab-org/gitlab!22573
parents df64d5d2 f61f1e45
...@@ -197,6 +197,7 @@ export const discardFileChanges = ({ dispatch, state, commit, getters }, path) = ...@@ -197,6 +197,7 @@ export const discardFileChanges = ({ dispatch, state, commit, getters }, path) =
if (file.tempFile) { if (file.tempFile) {
dispatch('deleteEntry', file.path); dispatch('deleteEntry', file.path);
} else { } else {
commit(types.DISCARD_FILE_CHANGES, file.path);
dispatch('renameEntry', { dispatch('renameEntry', {
path: file.path, path: file.path,
name: file.prevName, name: file.prevName,
......
...@@ -132,7 +132,7 @@ export default { ...@@ -132,7 +132,7 @@ export default {
[types.DISCARD_FILE_CHANGES](state, path) { [types.DISCARD_FILE_CHANGES](state, path) {
const stagedFile = state.stagedFiles.find(f => f.path === path); const stagedFile = state.stagedFiles.find(f => f.path === path);
const entry = state.entries[path]; const entry = state.entries[path];
const { deleted, prevPath } = entry; const { deleted } = entry;
Object.assign(state.entries[path], { Object.assign(state.entries[path], {
content: stagedFile ? stagedFile.content : state.entries[path].raw, content: stagedFile ? stagedFile.content : state.entries[path].raw,
...@@ -146,12 +146,6 @@ export default { ...@@ -146,12 +146,6 @@ export default {
: state.trees[`${state.currentProjectId}/${state.currentBranchId}`]; : state.trees[`${state.currentProjectId}/${state.currentBranchId}`];
parent.tree = sortTree(parent.tree.concat(entry)); parent.tree = sortTree(parent.tree.concat(entry));
} else if (prevPath) {
const parent = entry.parentPath
? state.entries[entry.parentPath]
: state.trees[`${state.currentProjectId}/${state.currentBranchId}`];
parent.tree = parent.tree.filter(f => f.path !== path);
} }
}, },
[types.ADD_FILE_TO_CHANGED](state, path) { [types.ADD_FILE_TO_CHANGED](state, path) {
......
---
title: Update IDE discard of renamed entry to also discard file changes
merge_request: 22573
author:
type: fixed
...@@ -9,6 +9,7 @@ import router from '~/ide/ide_router'; ...@@ -9,6 +9,7 @@ import router from '~/ide/ide_router';
import eventHub from '~/ide/eventhub'; import eventHub from '~/ide/eventhub';
import { file } from '../../helpers'; import { file } from '../../helpers';
const ORIGINAL_CONTENT = 'original content';
const RELATIVE_URL_ROOT = '/gitlab'; const RELATIVE_URL_ROOT = '/gitlab';
describe('IDE store file actions', () => { describe('IDE store file actions', () => {
...@@ -583,6 +584,7 @@ describe('IDE store file actions', () => { ...@@ -583,6 +584,7 @@ describe('IDE store file actions', () => {
tmpFile = file('tempFile'); tmpFile = file('tempFile');
tmpFile.content = 'testing'; tmpFile.content = 'testing';
tmpFile.raw = ORIGINAL_CONTENT;
store.state.changedFiles.push(tmpFile); store.state.changedFiles.push(tmpFile);
store.state.entries[tmpFile.path] = tmpFile; store.state.entries[tmpFile.path] = tmpFile;
...@@ -594,7 +596,7 @@ describe('IDE store file actions', () => { ...@@ -594,7 +596,7 @@ describe('IDE store file actions', () => {
store store
.dispatch('discardFileChanges', tmpFile.path) .dispatch('discardFileChanges', tmpFile.path)
.then(() => { .then(() => {
expect(tmpFile.content).not.toBe('testing'); expect(tmpFile.content).toBe(ORIGINAL_CONTENT);
done(); done();
}) })
...@@ -624,22 +626,30 @@ describe('IDE store file actions', () => { ...@@ -624,22 +626,30 @@ describe('IDE store file actions', () => {
expect(store.dispatch).toHaveBeenCalledWith('deleteEntry', tmpFile.path); expect(store.dispatch).toHaveBeenCalledWith('deleteEntry', tmpFile.path);
}); });
it('renames the file to its original name and closes it if it was open', () => { describe('with renamed file', () => {
Object.assign(tmpFile, { beforeEach(() => {
prevPath: 'parentPath/old_name', Object.assign(tmpFile, {
prevName: 'old_name', prevPath: 'parentPath/old_name',
prevParentPath: 'parentPath', prevName: 'old_name',
}); prevParentPath: 'parentPath',
});
store.state.entries.parentPath = file('parentPath'); store.state.entries.parentPath = file('parentPath');
actions.discardFileChanges(store, tmpFile.path); actions.discardFileChanges(store, tmpFile.path);
});
expect(store.dispatch).toHaveBeenCalledWith('closeFile', tmpFile); it('renames the file to its original name and closes it if it was open', () => {
expect(store.dispatch).toHaveBeenCalledWith('renameEntry', { expect(store.dispatch).toHaveBeenCalledWith('closeFile', tmpFile);
path: 'tempFile', expect(store.dispatch).toHaveBeenCalledWith('renameEntry', {
name: 'old_name', path: 'tempFile',
parentPath: 'parentPath', name: 'old_name',
parentPath: 'parentPath',
});
});
it('resets file content', () => {
expect(tmpFile.content).toBe(ORIGINAL_CONTENT);
}); });
}); });
......
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