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

specs

parent fd3ef2eb
......@@ -25,19 +25,19 @@ export default {
},
},
modalTitle() {
if (this.entryModal.type === 'rename') return __('Rename');
if (this.entryModal.type === 'tree') {
return __('Create new directory');
} else if (this.entryModal.type === 'rename') {
return this.entryModal.entry.type === 'tree' ? __('Rename folder') : __('Rename file');
}
return __('Create new file');
},
buttonLabel() {
if (this.entryModal.type === 'rename') return __('Update');
if (this.entryModal.type === 'tree') {
return __('Create directory');
} else if (this.entryModal.type === 'rename') {
return this.entryModal.entry.type === 'tree' ? __('Rename folder') : __('Rename file');
}
return __('Create file');
......
......@@ -153,10 +153,10 @@ export default {
const regex = new RegExp(`${prevPath}$`);
Object.assign(state.entries[file.path], {
rawPath: file.rawPath.replace(regex, file.name),
permalink: file.permalink.replace(regex, file.name),
commitsPath: file.commitsPath.replace(regex, file.name),
blamePath: file.blamePath.replace(regex, file.name),
rawPath: file.rawPath.replace(regex, file.path),
permalink: file.permalink.replace(regex, file.path),
commitsPath: file.commitsPath.replace(regex, file.path),
blamePath: file.blamePath.replace(regex, file.path),
});
}
},
......
......@@ -4354,6 +4354,12 @@ msgstr ""
msgid "Rename"
msgstr ""
msgid "Rename file"
msgstr ""
msgid "Rename folder"
msgstr ""
msgid "Reply to this email directly or %{view_it_on_gitlab}."
msgstr ""
......
......@@ -8,6 +8,7 @@ import actions, {
updateTempFlagForEntry,
setErrorMessage,
deleteEntry,
renameEntry,
} from '~/ide/stores/actions';
import store from '~/ide/stores';
import * as types from '~/ide/stores/mutation_types';
......@@ -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', () => {
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', () => {
},
],
},
{
path: 'c',
prevPath: 'x',
type: 'tree',
tree: [
{
path: 'c/index.js',
type: 'blob',
},
],
},
];
const flattendFiles = utils.getCommitFiles(files);
......@@ -252,6 +263,11 @@ describe('Multi-file store utils', () => {
type: 'blob',
deleted: true,
},
{
path: 'c/index.js',
type: 'blob',
deleted: true,
},
]);
});
});
......
......@@ -29,7 +29,7 @@ describe('GlModal', () => {
describe('without id', () => {
beforeEach(() => {
vm = mountComponent(modalComponent, { });
vm = mountComponent(modalComponent, {});
});
it('does not add an id attribute to the modal', () => {
......@@ -83,7 +83,7 @@ describe('GlModal', () => {
});
});
it('works with data-toggle="modal"', (done) => {
it('works with data-toggle="modal"', done => {
setFixtures(`
<button id="modal-button" data-toggle="modal" data-target="#my-modal"></button>
<div id="modal-container"></div>
......@@ -91,9 +91,13 @@ describe('GlModal', () => {
const modalContainer = document.getElementById('modal-container');
const modalButton = document.getElementById('modal-button');
vm = mountComponent(modalComponent, {
id: 'my-modal',
}, modalContainer);
vm = mountComponent(
modalComponent,
{
id: 'my-modal',
},
modalContainer,
);
$(vm.$el).on('shown.bs.modal', () => done());
modalButton.click();
......@@ -103,7 +107,7 @@ describe('GlModal', () => {
const dummyEvent = 'not really an event';
beforeEach(() => {
vm = mountComponent(modalComponent, { });
vm = mountComponent(modalComponent, {});
spyOn(vm, '$emit');
});
......@@ -122,11 +126,27 @@ describe('GlModal', () => {
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', () => {
const slotContent = 'this should go into the slot';
const modalWithSlot = (slotName) => {
const modalWithSlot = slotName => {
let template;
if (slotName) {
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