Commit 9712a6dd authored by Phil Hughes's avatar Phil Hughes

specs

parent fd3ef2eb
...@@ -25,19 +25,19 @@ export default { ...@@ -25,19 +25,19 @@ export default {
}, },
}, },
modalTitle() { modalTitle() {
if (this.entryModal.type === 'rename') return __('Rename');
if (this.entryModal.type === 'tree') { if (this.entryModal.type === 'tree') {
return __('Create new directory'); return __('Create new directory');
} else if (this.entryModal.type === 'rename') {
return this.entryModal.entry.type === 'tree' ? __('Rename folder') : __('Rename file');
} }
return __('Create new file'); return __('Create new file');
}, },
buttonLabel() { buttonLabel() {
if (this.entryModal.type === 'rename') return __('Update');
if (this.entryModal.type === 'tree') { if (this.entryModal.type === 'tree') {
return __('Create directory'); return __('Create directory');
} else if (this.entryModal.type === 'rename') {
return this.entryModal.entry.type === 'tree' ? __('Rename folder') : __('Rename file');
} }
return __('Create file'); return __('Create file');
......
...@@ -153,10 +153,10 @@ export default { ...@@ -153,10 +153,10 @@ export default {
const regex = new RegExp(`${prevPath}$`); const regex = new RegExp(`${prevPath}$`);
Object.assign(state.entries[file.path], { Object.assign(state.entries[file.path], {
rawPath: file.rawPath.replace(regex, file.name), rawPath: file.rawPath.replace(regex, file.path),
permalink: file.permalink.replace(regex, file.name), permalink: file.permalink.replace(regex, file.path),
commitsPath: file.commitsPath.replace(regex, file.name), commitsPath: file.commitsPath.replace(regex, file.path),
blamePath: file.blamePath.replace(regex, file.name), blamePath: file.blamePath.replace(regex, file.path),
}); });
} }
}, },
......
...@@ -4354,6 +4354,12 @@ msgstr "" ...@@ -4354,6 +4354,12 @@ msgstr ""
msgid "Rename" msgid "Rename"
msgstr "" msgstr ""
msgid "Rename file"
msgstr ""
msgid "Rename folder"
msgstr ""
msgid "Reply to this email directly or %{view_it_on_gitlab}." msgid "Reply to this email directly or %{view_it_on_gitlab}."
msgstr "" msgstr ""
......
...@@ -8,6 +8,7 @@ import actions, { ...@@ -8,6 +8,7 @@ import actions, {
updateTempFlagForEntry, updateTempFlagForEntry,
setErrorMessage, setErrorMessage,
deleteEntry, deleteEntry,
renameEntry,
} from '~/ide/stores/actions'; } from '~/ide/stores/actions';
import store from '~/ide/stores'; import store from '~/ide/stores';
import * as types from '~/ide/stores/mutation_types'; import * as types from '~/ide/stores/mutation_types';
...@@ -473,4 +474,57 @@ describe('Multi-file store actions', () => { ...@@ -473,4 +474,57 @@ describe('Multi-file store actions', () => {
); );
}); });
}); });
describe('renameEntry', () => {
it('renames entry', done => {
store.state.entries.test = {
tree: [],
};
testAction(
renameEntry,
{ path: 'test', name: 'new-name' },
store.state,
[
{
type: types.RENAME_ENTRY,
payload: { path: 'test', name: 'new-name', entryPath: null },
},
],
[{ type: 'deleteEntry', payload: 'test' }],
done,
);
});
it('renames all entries in tree', done => {
store.state.entries.test = {
tree: [
{
path: 'tree-1',
},
{
path: 'tree-2',
},
],
};
testAction(
renameEntry,
{ path: 'test', name: 'new-name' },
store.state,
[
{
type: types.RENAME_ENTRY,
payload: { path: 'test', name: 'new-name', entryPath: null },
},
],
[
{ type: 'renameEntry', payload: { path: 'test', name: 'new-name', entryPath: 'tree-1' } },
{ type: 'renameEntry', payload: { path: 'test', name: 'new-name', entryPath: 'tree-2' } },
{ type: 'deleteEntry', payload: 'test' },
],
done,
);
});
});
}); });
...@@ -213,4 +213,101 @@ describe('Multi-file store mutations', () => { ...@@ -213,4 +213,101 @@ describe('Multi-file store mutations', () => {
expect(localState.changedFiles).toEqual([localState.entries.filePath]); expect(localState.changedFiles).toEqual([localState.entries.filePath]);
}); });
}); });
describe('UPDATE_FILE_AFTER_COMMIT', () => {
it('updates URLs if prevPath is set', () => {
const f = {
...file(),
path: 'test',
prevPath: 'testing-123',
rawPath: `${gl.TEST_HOST}/testing-123`,
permalink: `${gl.TEST_HOST}/testing-123`,
commitsPath: `${gl.TEST_HOST}/testing-123`,
blamePath: `${gl.TEST_HOST}/testing-123`,
};
localState.entries.test = f;
localState.changedFiles.push(f);
mutations.UPDATE_FILE_AFTER_COMMIT(localState, { file: f, lastCommit: { commit: {} } });
expect(f.rawPath).toBe(`${gl.TEST_HOST}/test`);
expect(f.permalink).toBe(`${gl.TEST_HOST}/test`);
expect(f.commitsPath).toBe(`${gl.TEST_HOST}/test`);
expect(f.blamePath).toBe(`${gl.TEST_HOST}/test`);
});
});
describe('OPEN_NEW_ENTRY_MODAL', () => {
it('sets entryModal', () => {
localState.entries.testPath = {
...file(),
};
mutations.OPEN_NEW_ENTRY_MODAL(localState, { type: 'test', path: 'testPath' });
expect(localState.entryModal).toEqual({
type: 'test',
path: 'testPath',
entry: localState.entries.testPath,
});
});
});
describe('RENAME_ENTRY', () => {
beforeEach(() => {
localState.trees = {
'gitlab-ce/master': { tree: [] },
};
localState.currentProjectId = 'gitlab-ce';
localState.currentBranchId = 'master';
localState.entries.oldPath = {
...file(),
type: 'blob',
path: 'oldPath',
url: `${gl.TEST_HOST}/oldPath`,
};
});
it('creates new renamed entry', () => {
mutations.RENAME_ENTRY(localState, { path: 'oldPath', name: 'newPath' });
expect(localState.entries.newPath).toEqual({
...localState.entries.oldPath,
id: 'newPath',
name: 'newPath',
key: 'newPath-blob-name',
path: 'newPath',
tempFile: true,
prevPath: 'oldPath',
tree: [],
parentPath: '',
url: `${gl.TEST_HOST}/newPath`,
moved: jasmine.anything(),
});
});
it('adds new entry to changedFiles', () => {
mutations.RENAME_ENTRY(localState, { path: 'oldPath', name: 'newPath' });
expect(localState.changedFiles.length).toBe(1);
expect(localState.changedFiles[0].path).toBe('newPath');
});
it('sets oldEntry as moved', () => {
mutations.RENAME_ENTRY(localState, { path: 'oldPath', name: 'newPath' });
expect(localState.entries.oldPath.moved).toBe(true);
});
it('adds to parents tree', () => {
localState.entries.oldPath.parentPath = 'parentPath';
localState.entries.parentPath = {
...file(),
};
mutations.RENAME_ENTRY(localState, { path: 'oldPath', name: 'newPath' });
expect(localState.entries.parentPath.tree.length).toBe(1);
});
});
}); });
...@@ -232,6 +232,17 @@ describe('Multi-file store utils', () => { ...@@ -232,6 +232,17 @@ describe('Multi-file store utils', () => {
}, },
], ],
}, },
{
path: 'c',
prevPath: 'x',
type: 'tree',
tree: [
{
path: 'c/index.js',
type: 'blob',
},
],
},
]; ];
const flattendFiles = utils.getCommitFiles(files); const flattendFiles = utils.getCommitFiles(files);
...@@ -252,6 +263,11 @@ describe('Multi-file store utils', () => { ...@@ -252,6 +263,11 @@ describe('Multi-file store utils', () => {
type: 'blob', type: 'blob',
deleted: true, deleted: true,
}, },
{
path: 'c/index.js',
type: 'blob',
deleted: true,
},
]); ]);
}); });
}); });
......
...@@ -29,7 +29,7 @@ describe('GlModal', () => { ...@@ -29,7 +29,7 @@ describe('GlModal', () => {
describe('without id', () => { describe('without id', () => {
beforeEach(() => { beforeEach(() => {
vm = mountComponent(modalComponent, { }); vm = mountComponent(modalComponent, {});
}); });
it('does not add an id attribute to the modal', () => { it('does not add an id attribute to the modal', () => {
...@@ -83,7 +83,7 @@ describe('GlModal', () => { ...@@ -83,7 +83,7 @@ describe('GlModal', () => {
}); });
}); });
it('works with data-toggle="modal"', (done) => { it('works with data-toggle="modal"', done => {
setFixtures(` setFixtures(`
<button id="modal-button" data-toggle="modal" data-target="#my-modal"></button> <button id="modal-button" data-toggle="modal" data-target="#my-modal"></button>
<div id="modal-container"></div> <div id="modal-container"></div>
...@@ -91,9 +91,13 @@ describe('GlModal', () => { ...@@ -91,9 +91,13 @@ describe('GlModal', () => {
const modalContainer = document.getElementById('modal-container'); const modalContainer = document.getElementById('modal-container');
const modalButton = document.getElementById('modal-button'); const modalButton = document.getElementById('modal-button');
vm = mountComponent(modalComponent, { vm = mountComponent(
id: 'my-modal', modalComponent,
}, modalContainer); {
id: 'my-modal',
},
modalContainer,
);
$(vm.$el).on('shown.bs.modal', () => done()); $(vm.$el).on('shown.bs.modal', () => done());
modalButton.click(); modalButton.click();
...@@ -103,7 +107,7 @@ describe('GlModal', () => { ...@@ -103,7 +107,7 @@ describe('GlModal', () => {
const dummyEvent = 'not really an event'; const dummyEvent = 'not really an event';
beforeEach(() => { beforeEach(() => {
vm = mountComponent(modalComponent, { }); vm = mountComponent(modalComponent, {});
spyOn(vm, '$emit'); spyOn(vm, '$emit');
}); });
...@@ -122,11 +126,27 @@ describe('GlModal', () => { ...@@ -122,11 +126,27 @@ describe('GlModal', () => {
expect(vm.$emit).toHaveBeenCalledWith('submit', dummyEvent); expect(vm.$emit).toHaveBeenCalledWith('submit', dummyEvent);
}); });
}); });
describe('opened', () => {
it('emits a open event', () => {
vm.opened();
expect(vm.$emit).toHaveBeenCalledWith('open');
});
});
describe('closed', () => {
it('emits a closed event', () => {
vm.closed();
expect(vm.$emit).toHaveBeenCalledWith('closed');
});
});
}); });
describe('slots', () => { describe('slots', () => {
const slotContent = 'this should go into the slot'; const slotContent = 'this should go into the slot';
const modalWithSlot = (slotName) => { const modalWithSlot = slotName => {
let template; let template;
if (slotName) { if (slotName) {
template = ` template = `
......
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