2019-12-06 19:07:51 -05:00
|
|
|
import { TEST_HOST } from 'helpers/test_constants';
|
2018-03-20 10:16:38 -04:00
|
|
|
import mutations from '~/ide/stores/mutations';
|
|
|
|
import state from '~/ide/stores/state';
|
2018-03-20 10:12:48 -04:00
|
|
|
import { file } from '../helpers';
|
|
|
|
|
|
|
|
describe('Multi-file store mutations', () => {
|
|
|
|
let localState;
|
|
|
|
let entry;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
localState = state();
|
|
|
|
entry = file();
|
|
|
|
|
|
|
|
localState.entries[entry.path] = entry;
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('SET_INITIAL_DATA', () => {
|
|
|
|
it('sets all initial data', () => {
|
|
|
|
mutations.SET_INITIAL_DATA(localState, {
|
|
|
|
test: 'test',
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(localState.test).toBe('test');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('TOGGLE_LOADING', () => {
|
|
|
|
it('toggles loading of entry', () => {
|
2019-12-06 19:07:51 -05:00
|
|
|
mutations.TOGGLE_LOADING(localState, {
|
|
|
|
entry,
|
|
|
|
});
|
2018-03-20 10:12:48 -04:00
|
|
|
|
|
|
|
expect(entry.loading).toBeTruthy();
|
|
|
|
|
2019-12-06 19:07:51 -05:00
|
|
|
mutations.TOGGLE_LOADING(localState, {
|
|
|
|
entry,
|
|
|
|
});
|
2018-03-20 10:12:48 -04:00
|
|
|
|
|
|
|
expect(entry.loading).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('toggles loading of entry and sets specific value', () => {
|
2019-12-06 19:07:51 -05:00
|
|
|
mutations.TOGGLE_LOADING(localState, {
|
|
|
|
entry,
|
|
|
|
});
|
2018-03-20 10:12:48 -04:00
|
|
|
|
|
|
|
expect(entry.loading).toBeTruthy();
|
|
|
|
|
2019-12-06 19:07:51 -05:00
|
|
|
mutations.TOGGLE_LOADING(localState, {
|
|
|
|
entry,
|
|
|
|
forceValue: true,
|
|
|
|
});
|
2018-03-20 10:12:48 -04:00
|
|
|
|
|
|
|
expect(entry.loading).toBeTruthy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-03-21 06:05:08 -04:00
|
|
|
describe('CLEAR_STAGED_CHANGES', () => {
|
|
|
|
it('clears stagedFiles array', () => {
|
|
|
|
localState.stagedFiles.push('a');
|
|
|
|
|
|
|
|
mutations.CLEAR_STAGED_CHANGES(localState);
|
|
|
|
|
|
|
|
expect(localState.stagedFiles.length).toBe(0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-03-20 10:12:48 -04:00
|
|
|
describe('UPDATE_VIEWER', () => {
|
|
|
|
it('sets viewer state', () => {
|
|
|
|
mutations.UPDATE_VIEWER(localState, 'diff');
|
|
|
|
|
|
|
|
expect(localState.viewer).toBe('diff');
|
|
|
|
});
|
|
|
|
});
|
2018-04-18 06:29:40 -04:00
|
|
|
|
|
|
|
describe('UPDATE_ACTIVITY_BAR_VIEW', () => {
|
|
|
|
it('updates currentActivityBar', () => {
|
|
|
|
mutations.UPDATE_ACTIVITY_BAR_VIEW(localState, 'test');
|
|
|
|
|
|
|
|
expect(localState.currentActivityView).toBe('test');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('SET_EMPTY_STATE_SVGS', () => {
|
|
|
|
it('updates empty state SVGs', () => {
|
|
|
|
mutations.SET_EMPTY_STATE_SVGS(localState, {
|
|
|
|
emptyStateSvgPath: 'emptyState',
|
|
|
|
noChangesStateSvgPath: 'noChanges',
|
2021-10-28 11:09:42 -04:00
|
|
|
committedStateSvgPath: 'committed',
|
2018-04-18 06:29:40 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(localState.emptyStateSvgPath).toBe('emptyState');
|
|
|
|
expect(localState.noChangesStateSvgPath).toBe('noChanges');
|
2021-10-28 11:09:42 -04:00
|
|
|
expect(localState.committedStateSvgPath).toBe('committed');
|
2018-04-18 06:29:40 -04:00
|
|
|
});
|
|
|
|
});
|
2018-04-25 05:38:06 -04:00
|
|
|
|
2019-07-02 07:12:16 -04:00
|
|
|
describe('CREATE_TMP_ENTRY', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
localState.currentProjectId = 'gitlab-ce';
|
2021-06-14 20:10:11 -04:00
|
|
|
localState.currentBranchId = 'main';
|
|
|
|
localState.trees['gitlab-ce/main'] = {
|
2019-07-02 07:12:16 -04:00
|
|
|
tree: [],
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
it('creates temp entry in the tree', () => {
|
|
|
|
const tmpFile = file('test');
|
|
|
|
mutations.CREATE_TMP_ENTRY(localState, {
|
|
|
|
data: {
|
|
|
|
entries: {
|
2019-12-06 19:07:51 -05:00
|
|
|
test: { ...tmpFile, tempFile: true, changed: true },
|
2019-07-02 07:12:16 -04:00
|
|
|
},
|
|
|
|
treeList: [tmpFile],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-06-14 20:10:11 -04:00
|
|
|
expect(localState.trees['gitlab-ce/main'].tree.length).toEqual(1);
|
2019-07-02 07:12:16 -04:00
|
|
|
expect(localState.entries.test.tempFile).toEqual(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-04-10 06:10:16 -04:00
|
|
|
describe('UPDATE_TEMP_FLAG', () => {
|
|
|
|
beforeEach(() => {
|
2019-12-06 19:07:51 -05:00
|
|
|
localState.entries.test = { ...file(), tempFile: true, changed: true };
|
2018-04-10 06:10:16 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('updates tempFile flag', () => {
|
2019-12-06 19:07:51 -05:00
|
|
|
mutations.UPDATE_TEMP_FLAG(localState, {
|
|
|
|
path: 'test',
|
|
|
|
tempFile: false,
|
|
|
|
});
|
2018-04-10 06:10:16 -04:00
|
|
|
|
|
|
|
expect(localState.entries.test.tempFile).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('updates changed flag', () => {
|
2019-12-06 19:07:51 -05:00
|
|
|
mutations.UPDATE_TEMP_FLAG(localState, {
|
|
|
|
path: 'test',
|
|
|
|
tempFile: false,
|
|
|
|
});
|
2018-04-10 06:10:16 -04:00
|
|
|
|
|
|
|
expect(localState.entries.test.changed).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
2018-04-25 05:51:41 -04:00
|
|
|
|
2018-04-13 05:43:16 -04:00
|
|
|
describe('TOGGLE_FILE_FINDER', () => {
|
|
|
|
it('updates fileFindVisible', () => {
|
|
|
|
mutations.TOGGLE_FILE_FINDER(localState, true);
|
|
|
|
|
|
|
|
expect(localState.fileFindVisible).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
2018-05-03 04:30:44 -04:00
|
|
|
|
2018-06-26 11:51:57 -04:00
|
|
|
describe('SET_ERROR_MESSAGE', () => {
|
|
|
|
it('updates error message', () => {
|
|
|
|
mutations.SET_ERROR_MESSAGE(localState, 'error');
|
|
|
|
|
|
|
|
expect(localState.errorMessage).toBe('error');
|
|
|
|
});
|
|
|
|
});
|
2018-07-26 10:56:56 -04:00
|
|
|
|
|
|
|
describe('DELETE_ENTRY', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
localState.currentProjectId = 'gitlab-ce';
|
2021-06-14 20:10:11 -04:00
|
|
|
localState.currentBranchId = 'main';
|
|
|
|
localState.trees['gitlab-ce/main'] = {
|
2018-07-26 10:56:56 -04:00
|
|
|
tree: [],
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets deleted flag', () => {
|
|
|
|
localState.entries.filePath = {
|
|
|
|
deleted: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
mutations.DELETE_ENTRY(localState, 'filePath');
|
|
|
|
|
|
|
|
expect(localState.entries.filePath.deleted).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('removes from root tree', () => {
|
|
|
|
localState.entries.filePath = {
|
|
|
|
path: 'filePath',
|
|
|
|
deleted: false,
|
|
|
|
};
|
2021-06-14 20:10:11 -04:00
|
|
|
localState.trees['gitlab-ce/main'].tree.push(localState.entries.filePath);
|
2018-07-26 10:56:56 -04:00
|
|
|
|
|
|
|
mutations.DELETE_ENTRY(localState, 'filePath');
|
|
|
|
|
2021-06-14 20:10:11 -04:00
|
|
|
expect(localState.trees['gitlab-ce/main'].tree).toEqual([]);
|
2018-07-26 10:56:56 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('removes from parent tree', () => {
|
|
|
|
localState.entries.filePath = {
|
|
|
|
path: 'filePath',
|
|
|
|
deleted: false,
|
|
|
|
parentPath: 'parentPath',
|
|
|
|
};
|
|
|
|
localState.entries.parentPath = {
|
|
|
|
tree: [localState.entries.filePath],
|
|
|
|
};
|
|
|
|
|
|
|
|
mutations.DELETE_ENTRY(localState, 'filePath');
|
|
|
|
|
|
|
|
expect(localState.entries.parentPath.tree).toEqual([]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('adds to changedFiles', () => {
|
|
|
|
localState.entries.filePath = {
|
|
|
|
deleted: false,
|
2018-08-02 03:49:10 -04:00
|
|
|
type: 'blob',
|
2018-07-26 10:56:56 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
mutations.DELETE_ENTRY(localState, 'filePath');
|
|
|
|
|
|
|
|
expect(localState.changedFiles).toEqual([localState.entries.filePath]);
|
|
|
|
});
|
2018-08-15 09:17:44 -04:00
|
|
|
|
|
|
|
it('does not add tempFile into changedFiles', () => {
|
|
|
|
localState.entries.filePath = {
|
|
|
|
deleted: false,
|
|
|
|
type: 'blob',
|
|
|
|
tempFile: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
mutations.DELETE_ENTRY(localState, 'filePath');
|
|
|
|
|
|
|
|
expect(localState.changedFiles).toEqual([]);
|
|
|
|
});
|
|
|
|
|
2020-04-22 17:10:00 -04:00
|
|
|
it('removes tempFile from changedFiles and stagedFiles when deleted', () => {
|
2018-08-15 09:17:44 -04:00
|
|
|
localState.entries.filePath = {
|
|
|
|
path: 'filePath',
|
|
|
|
deleted: false,
|
|
|
|
type: 'blob',
|
|
|
|
tempFile: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
localState.changedFiles.push({ ...localState.entries.filePath });
|
2020-04-22 17:10:00 -04:00
|
|
|
localState.stagedFiles.push({ ...localState.entries.filePath });
|
2018-08-15 09:17:44 -04:00
|
|
|
|
|
|
|
mutations.DELETE_ENTRY(localState, 'filePath');
|
|
|
|
|
|
|
|
expect(localState.changedFiles).toEqual([]);
|
2020-04-22 17:10:00 -04:00
|
|
|
expect(localState.stagedFiles).toEqual([]);
|
2018-08-15 09:17:44 -04:00
|
|
|
});
|
2018-07-26 10:56:56 -04:00
|
|
|
});
|
2018-07-31 04:18:24 -04:00
|
|
|
|
|
|
|
describe('UPDATE_FILE_AFTER_COMMIT', () => {
|
|
|
|
it('updates URLs if prevPath is set', () => {
|
|
|
|
const f = {
|
2019-10-04 11:06:38 -04:00
|
|
|
...file('test'),
|
2018-07-31 04:18:24 -04:00
|
|
|
prevPath: 'testing-123',
|
2019-12-06 19:07:51 -05:00
|
|
|
rawPath: `${TEST_HOST}/testing-123`,
|
2018-07-31 04:18:24 -04:00
|
|
|
};
|
|
|
|
localState.entries.test = f;
|
|
|
|
localState.changedFiles.push(f);
|
|
|
|
|
2019-12-06 19:07:51 -05:00
|
|
|
mutations.UPDATE_FILE_AFTER_COMMIT(localState, {
|
|
|
|
file: f,
|
|
|
|
lastCommit: {
|
|
|
|
commit: {},
|
|
|
|
},
|
|
|
|
});
|
2018-07-31 04:18:24 -04:00
|
|
|
|
2019-10-04 11:06:38 -04:00
|
|
|
expect(f).toEqual(
|
2019-12-06 19:07:51 -05:00
|
|
|
expect.objectContaining({
|
|
|
|
rawPath: `${TEST_HOST}/test`,
|
2019-10-04 11:06:38 -04:00
|
|
|
prevId: undefined,
|
|
|
|
prevPath: undefined,
|
|
|
|
prevName: undefined,
|
|
|
|
prevKey: undefined,
|
|
|
|
}),
|
|
|
|
);
|
2018-07-31 04:18:24 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('RENAME_ENTRY', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
localState.trees = {
|
2021-06-14 20:10:11 -04:00
|
|
|
'gitlab-ce/main': {
|
2019-12-06 19:07:51 -05:00
|
|
|
tree: [],
|
|
|
|
},
|
2018-07-31 04:18:24 -04:00
|
|
|
};
|
|
|
|
localState.currentProjectId = 'gitlab-ce';
|
2021-06-14 20:10:11 -04:00
|
|
|
localState.currentBranchId = 'main';
|
2019-10-04 11:06:38 -04:00
|
|
|
localState.entries = {
|
|
|
|
oldPath: file('oldPath', 'oldPath', 'blob'),
|
2018-07-31 04:18:24 -04:00
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2019-10-04 11:06:38 -04:00
|
|
|
it('updates existing entry without creating a new one', () => {
|
|
|
|
mutations.RENAME_ENTRY(localState, {
|
|
|
|
path: 'oldPath',
|
|
|
|
name: 'newPath',
|
|
|
|
parentPath: '',
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(localState.entries).toEqual({
|
2019-12-06 19:07:51 -05:00
|
|
|
newPath: expect.objectContaining({
|
2019-10-04 11:06:38 -04:00
|
|
|
path: 'newPath',
|
|
|
|
prevPath: 'oldPath',
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('correctly handles consecutive renames for the same entry', () => {
|
2019-03-04 06:39:55 -05:00
|
|
|
mutations.RENAME_ENTRY(localState, {
|
|
|
|
path: 'oldPath',
|
|
|
|
name: 'newPath',
|
2019-10-04 11:06:38 -04:00
|
|
|
parentPath: '',
|
|
|
|
});
|
|
|
|
|
|
|
|
mutations.RENAME_ENTRY(localState, {
|
|
|
|
path: 'newPath',
|
|
|
|
name: 'newestPath',
|
|
|
|
parentPath: '',
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(localState.entries).toEqual({
|
2019-12-06 19:07:51 -05:00
|
|
|
newestPath: expect.objectContaining({
|
2019-10-04 11:06:38 -04:00
|
|
|
path: 'newestPath',
|
|
|
|
prevPath: 'oldPath',
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('correctly handles the same entry within a consecutively renamed folder', () => {
|
|
|
|
const oldPath = file('root-folder/oldPath', 'root-folder/oldPath', 'blob');
|
|
|
|
localState.entries = {
|
2019-12-06 19:07:51 -05:00
|
|
|
'root-folder': { ...file('root-folder', 'root-folder', 'tree'), tree: [oldPath] },
|
2019-10-04 11:06:38 -04:00
|
|
|
'root-folder/oldPath': oldPath,
|
|
|
|
};
|
|
|
|
Object.assign(localState.entries['root-folder/oldPath'], {
|
|
|
|
parentPath: 'root-folder',
|
|
|
|
});
|
|
|
|
|
|
|
|
mutations.RENAME_ENTRY(localState, {
|
|
|
|
path: 'root-folder/oldPath',
|
|
|
|
name: 'renamed-folder/oldPath',
|
2019-03-04 06:39:55 -05:00
|
|
|
entryPath: null,
|
|
|
|
parentPath: '',
|
|
|
|
});
|
2018-07-31 04:18:24 -04:00
|
|
|
|
2019-10-04 11:06:38 -04:00
|
|
|
mutations.RENAME_ENTRY(localState, {
|
|
|
|
path: 'renamed-folder/oldPath',
|
|
|
|
name: 'simply-renamed/oldPath',
|
|
|
|
entryPath: null,
|
|
|
|
parentPath: '',
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(localState.entries).toEqual({
|
2019-12-06 19:07:51 -05:00
|
|
|
'root-folder': expect.objectContaining({
|
2019-10-04 11:06:38 -04:00
|
|
|
path: 'root-folder',
|
|
|
|
}),
|
2019-12-06 19:07:51 -05:00
|
|
|
'simply-renamed/oldPath': expect.objectContaining({
|
2019-10-04 11:06:38 -04:00
|
|
|
path: 'simply-renamed/oldPath',
|
|
|
|
prevPath: 'root-folder/oldPath',
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renames entry, preserving old parameters', () => {
|
|
|
|
const oldPathData = localState.entries.oldPath;
|
|
|
|
|
|
|
|
mutations.RENAME_ENTRY(localState, {
|
|
|
|
path: 'oldPath',
|
|
|
|
name: 'newPath',
|
|
|
|
parentPath: '',
|
|
|
|
});
|
|
|
|
|
2018-07-31 04:18:24 -04:00
|
|
|
expect(localState.entries.newPath).toEqual({
|
2019-10-04 11:06:38 -04:00
|
|
|
...oldPathData,
|
2018-07-31 04:18:24 -04:00
|
|
|
id: 'newPath',
|
|
|
|
path: 'newPath',
|
2019-10-04 11:06:38 -04:00
|
|
|
name: 'newPath',
|
2019-12-06 19:07:51 -05:00
|
|
|
key: expect.stringMatching('newPath'),
|
2019-10-04 11:06:38 -04:00
|
|
|
prevId: 'oldPath',
|
|
|
|
prevName: 'oldPath',
|
2018-07-31 04:18:24 -04:00
|
|
|
prevPath: 'oldPath',
|
2019-10-04 11:06:38 -04:00
|
|
|
prevKey: oldPathData.key,
|
|
|
|
prevParentPath: oldPathData.parentPath,
|
2018-07-31 04:18:24 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-04 11:06:38 -04:00
|
|
|
it('does not store previous attributes on temp files', () => {
|
|
|
|
Object.assign(localState.entries.oldPath, {
|
|
|
|
tempFile: true,
|
|
|
|
});
|
|
|
|
mutations.RENAME_ENTRY(localState, {
|
|
|
|
path: 'oldPath',
|
|
|
|
name: 'newPath',
|
|
|
|
entryPath: null,
|
|
|
|
parentPath: '',
|
|
|
|
});
|
2018-07-31 04:18:24 -04:00
|
|
|
|
2019-10-04 11:06:38 -04:00
|
|
|
expect(localState.entries.newPath).not.toEqual(
|
2019-12-06 19:07:51 -05:00
|
|
|
expect.objectContaining({
|
|
|
|
prevId: expect.anything(),
|
|
|
|
prevName: expect.anything(),
|
|
|
|
prevPath: expect.anything(),
|
|
|
|
prevKey: expect.anything(),
|
|
|
|
prevParentPath: expect.anything(),
|
2019-10-04 11:06:38 -04:00
|
|
|
}),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('properly handles files with spaces in name', () => {
|
|
|
|
const path = 'my fancy path';
|
|
|
|
const newPath = 'new path';
|
2020-09-14 08:09:34 -04:00
|
|
|
const oldEntry = file(path, path, 'blob');
|
2018-07-31 04:18:24 -04:00
|
|
|
|
2019-10-04 11:06:38 -04:00
|
|
|
localState.entries[path] = oldEntry;
|
2018-07-31 04:18:24 -04:00
|
|
|
|
2019-10-04 11:06:38 -04:00
|
|
|
mutations.RENAME_ENTRY(localState, {
|
|
|
|
path,
|
|
|
|
name: newPath,
|
|
|
|
entryPath: null,
|
|
|
|
parentPath: '',
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(localState.entries[newPath]).toEqual({
|
|
|
|
...oldEntry,
|
|
|
|
id: newPath,
|
|
|
|
path: newPath,
|
|
|
|
name: newPath,
|
2019-12-06 19:07:51 -05:00
|
|
|
key: expect.stringMatching(newPath),
|
2019-10-04 11:06:38 -04:00
|
|
|
prevId: path,
|
|
|
|
prevName: path,
|
|
|
|
prevPath: path,
|
|
|
|
prevKey: oldEntry.key,
|
|
|
|
prevParentPath: oldEntry.parentPath,
|
|
|
|
});
|
2018-07-31 04:18:24 -04:00
|
|
|
});
|
|
|
|
|
2019-10-04 11:06:38 -04:00
|
|
|
it('adds to parent tree', () => {
|
|
|
|
const parentEntry = {
|
|
|
|
...file('parentPath', 'parentPath', 'tree'),
|
|
|
|
tree: [localState.entries.oldPath],
|
2018-07-31 04:18:24 -04:00
|
|
|
};
|
2019-10-04 11:06:38 -04:00
|
|
|
localState.entries.parentPath = parentEntry;
|
2018-07-31 04:18:24 -04:00
|
|
|
|
2019-03-04 06:39:55 -05:00
|
|
|
mutations.RENAME_ENTRY(localState, {
|
|
|
|
path: 'oldPath',
|
|
|
|
name: 'newPath',
|
|
|
|
entryPath: null,
|
|
|
|
parentPath: 'parentPath',
|
|
|
|
});
|
2018-07-31 04:18:24 -04:00
|
|
|
|
2019-10-04 11:06:38 -04:00
|
|
|
expect(parentEntry.tree.length).toBe(1);
|
|
|
|
expect(parentEntry.tree[0].name).toBe('newPath');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sorts tree after renaming an entry', () => {
|
|
|
|
const alpha = file('alpha', 'alpha', 'blob');
|
|
|
|
const beta = file('beta', 'beta', 'blob');
|
|
|
|
const gamma = file('gamma', 'gamma', 'blob');
|
2019-12-06 19:07:51 -05:00
|
|
|
localState.entries = {
|
|
|
|
alpha,
|
|
|
|
beta,
|
|
|
|
gamma,
|
|
|
|
};
|
2019-10-04 11:06:38 -04:00
|
|
|
|
2021-06-14 20:10:11 -04:00
|
|
|
localState.trees['gitlab-ce/main'].tree = [alpha, beta, gamma];
|
2019-10-04 11:06:38 -04:00
|
|
|
|
|
|
|
mutations.RENAME_ENTRY(localState, {
|
|
|
|
path: 'alpha',
|
|
|
|
name: 'theta',
|
|
|
|
entryPath: null,
|
|
|
|
parentPath: '',
|
|
|
|
});
|
|
|
|
|
2021-06-14 20:10:11 -04:00
|
|
|
expect(localState.trees['gitlab-ce/main'].tree).toEqual([
|
2019-12-06 19:07:51 -05:00
|
|
|
expect.objectContaining({
|
|
|
|
name: 'beta',
|
|
|
|
}),
|
|
|
|
expect.objectContaining({
|
|
|
|
name: 'gamma',
|
|
|
|
}),
|
|
|
|
expect.objectContaining({
|
2019-10-04 11:06:38 -04:00
|
|
|
path: 'theta',
|
|
|
|
name: 'theta',
|
|
|
|
}),
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('updates openFiles with the renamed one if the original one is open', () => {
|
|
|
|
Object.assign(localState.entries.oldPath, {
|
|
|
|
opened: true,
|
|
|
|
type: 'blob',
|
|
|
|
});
|
|
|
|
Object.assign(localState, {
|
|
|
|
openFiles: [localState.entries.oldPath],
|
|
|
|
});
|
|
|
|
|
2019-12-06 19:07:51 -05:00
|
|
|
mutations.RENAME_ENTRY(localState, {
|
|
|
|
path: 'oldPath',
|
|
|
|
name: 'newPath',
|
|
|
|
});
|
2019-10-04 11:06:38 -04:00
|
|
|
|
|
|
|
expect(localState.openFiles.length).toBe(1);
|
|
|
|
expect(localState.openFiles[0].path).toBe('newPath');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not add renamed entry to changedFiles', () => {
|
2019-12-06 19:07:51 -05:00
|
|
|
mutations.RENAME_ENTRY(localState, {
|
|
|
|
path: 'oldPath',
|
|
|
|
name: 'newPath',
|
|
|
|
});
|
2019-10-04 11:06:38 -04:00
|
|
|
|
|
|
|
expect(localState.changedFiles.length).toBe(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('updates existing changedFiles entry with the renamed one', () => {
|
2019-12-06 19:07:51 -05:00
|
|
|
const origFile = { ...file('oldPath', 'oldPath', 'blob'), content: 'Foo' };
|
2019-10-04 11:06:38 -04:00
|
|
|
|
|
|
|
Object.assign(localState, {
|
|
|
|
changedFiles: [origFile],
|
|
|
|
});
|
|
|
|
Object.assign(localState.entries, {
|
|
|
|
oldPath: origFile,
|
|
|
|
});
|
|
|
|
|
2019-12-06 19:07:51 -05:00
|
|
|
mutations.RENAME_ENTRY(localState, {
|
|
|
|
path: 'oldPath',
|
|
|
|
name: 'newPath',
|
|
|
|
});
|
2019-10-04 11:06:38 -04:00
|
|
|
|
|
|
|
expect(localState.changedFiles).toEqual([
|
2019-12-06 19:07:51 -05:00
|
|
|
expect.objectContaining({
|
2019-10-04 11:06:38 -04:00
|
|
|
path: 'newPath',
|
|
|
|
content: 'Foo',
|
|
|
|
}),
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('correctly saves original values if an entry is renamed multiple times', () => {
|
|
|
|
const original = { ...localState.entries.oldPath };
|
2020-09-14 08:09:34 -04:00
|
|
|
const paramsToCheck = ['prevId', 'prevPath', 'prevName'];
|
2019-10-04 11:06:38 -04:00
|
|
|
const expectedObj = paramsToCheck.reduce(
|
|
|
|
(o, param) => ({ ...o, [param]: original[param.replace('prev', '').toLowerCase()] }),
|
|
|
|
{},
|
|
|
|
);
|
|
|
|
|
2019-12-06 19:07:51 -05:00
|
|
|
mutations.RENAME_ENTRY(localState, {
|
|
|
|
path: 'oldPath',
|
|
|
|
name: 'newPath',
|
|
|
|
});
|
2019-10-04 11:06:38 -04:00
|
|
|
|
2019-12-06 19:07:51 -05:00
|
|
|
expect(localState.entries.newPath).toEqual(expect.objectContaining(expectedObj));
|
2019-10-04 11:06:38 -04:00
|
|
|
|
2019-12-06 19:07:51 -05:00
|
|
|
mutations.RENAME_ENTRY(localState, {
|
|
|
|
path: 'newPath',
|
|
|
|
name: 'newer',
|
|
|
|
});
|
2019-10-04 11:06:38 -04:00
|
|
|
|
2019-12-06 19:07:51 -05:00
|
|
|
expect(localState.entries.newer).toEqual(expect.objectContaining(expectedObj));
|
2019-10-04 11:06:38 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('renaming back to original', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
const renamedEntry = {
|
|
|
|
...file('renamed', 'renamed', 'blob'),
|
|
|
|
prevId: 'lorem/orig',
|
|
|
|
prevPath: 'lorem/orig',
|
|
|
|
prevName: 'orig',
|
|
|
|
prevKey: 'lorem/orig',
|
|
|
|
prevParentPath: 'lorem',
|
|
|
|
};
|
|
|
|
|
|
|
|
localState.entries = {
|
|
|
|
renamed: renamedEntry,
|
|
|
|
};
|
|
|
|
|
2019-12-06 19:07:51 -05:00
|
|
|
mutations.RENAME_ENTRY(localState, {
|
|
|
|
path: 'renamed',
|
|
|
|
name: 'orig',
|
|
|
|
parentPath: 'lorem',
|
|
|
|
});
|
2019-10-04 11:06:38 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renames entry and clears prev properties', () => {
|
|
|
|
expect(localState.entries).toEqual({
|
2019-12-06 19:07:51 -05:00
|
|
|
'lorem/orig': expect.objectContaining({
|
2019-10-04 11:06:38 -04:00
|
|
|
id: 'lorem/orig',
|
|
|
|
path: 'lorem/orig',
|
|
|
|
name: 'orig',
|
|
|
|
prevId: undefined,
|
|
|
|
prevPath: undefined,
|
|
|
|
prevName: undefined,
|
|
|
|
prevKey: undefined,
|
|
|
|
prevParentPath: undefined,
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('key updates', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
const rootFolder = file('rootFolder', 'rootFolder', 'tree');
|
|
|
|
localState.entries = {
|
|
|
|
rootFolder,
|
|
|
|
oldPath: file('oldPath', 'oldPath', 'blob'),
|
|
|
|
'oldPath.txt': file('oldPath.txt', 'oldPath.txt', 'blob'),
|
|
|
|
'rootFolder/oldPath.md': file('oldPath.md', 'oldPath.md', 'blob', rootFolder),
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets properly constucted key while preserving the original one', () => {
|
|
|
|
const key = 'oldPath.txt-blob-oldPath.txt';
|
|
|
|
localState.entries['oldPath.txt'].key = key;
|
2019-12-06 19:07:51 -05:00
|
|
|
mutations.RENAME_ENTRY(localState, {
|
|
|
|
path: 'oldPath.txt',
|
|
|
|
name: 'newPath.md',
|
|
|
|
});
|
2019-10-04 11:06:38 -04:00
|
|
|
|
|
|
|
expect(localState.entries['newPath.md'].key).toBe('newPath.md-blob-newPath.md');
|
|
|
|
expect(localState.entries['newPath.md'].prevKey).toBe(key);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('correctly updates key for an entry without an extension', () => {
|
|
|
|
localState.entries.oldPath.key = 'oldPath-blob-oldPath';
|
2019-12-06 19:07:51 -05:00
|
|
|
mutations.RENAME_ENTRY(localState, {
|
|
|
|
path: 'oldPath',
|
|
|
|
name: 'newPath.md',
|
|
|
|
});
|
2019-10-04 11:06:38 -04:00
|
|
|
|
|
|
|
expect(localState.entries['newPath.md'].key).toBe('newPath.md-blob-newPath.md');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('correctly updates key when new name does not have an extension', () => {
|
|
|
|
localState.entries['oldPath.txt'].key = 'oldPath.txt-blob-oldPath.txt';
|
2019-12-06 19:07:51 -05:00
|
|
|
mutations.RENAME_ENTRY(localState, {
|
|
|
|
path: 'oldPath.txt',
|
|
|
|
name: 'newPath',
|
|
|
|
});
|
2019-10-04 11:06:38 -04:00
|
|
|
|
|
|
|
expect(localState.entries.newPath.key).toBe('newPath-blob-newPath');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('correctly updates key when renaming an entry in a folder', () => {
|
|
|
|
localState.entries['rootFolder/oldPath.md'].key =
|
|
|
|
'rootFolder/oldPath.md-blob-rootFolder/oldPath.md';
|
|
|
|
mutations.RENAME_ENTRY(localState, {
|
|
|
|
path: 'rootFolder/oldPath.md',
|
|
|
|
name: 'newPath.md',
|
|
|
|
entryPath: null,
|
|
|
|
parentPath: 'rootFolder',
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(localState.entries['rootFolder/newPath.md'].key).toBe(
|
|
|
|
'rootFolder/newPath.md-blob-rootFolder/newPath.md',
|
|
|
|
);
|
|
|
|
});
|
2018-07-31 04:18:24 -04:00
|
|
|
});
|
|
|
|
});
|
2018-03-20 10:12:48 -04:00
|
|
|
});
|