Commit 38d56a8b authored by Tim Zallmann's avatar Tim Zallmann

Added Tests for all new functionality

parent f0e1ee5f
...@@ -35,14 +35,14 @@ describe('Api', () => { ...@@ -35,14 +35,14 @@ describe('Api', () => {
}); });
describe('group', () => { describe('group', () => {
it('fetches a group', (done) => { it('fetches a group', done => {
const groupId = '123456'; const groupId = '123456';
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/groups/${groupId}`; const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/groups/${groupId}`;
mock.onGet(expectedUrl).reply(200, { mock.onGet(expectedUrl).reply(200, {
name: 'test', name: 'test',
}); });
Api.group(groupId, (response) => { Api.group(groupId, response => {
expect(response.name).toBe('test'); expect(response.name).toBe('test');
done(); done();
}); });
...@@ -50,15 +50,17 @@ describe('Api', () => { ...@@ -50,15 +50,17 @@ describe('Api', () => {
}); });
describe('groups', () => { describe('groups', () => {
it('fetches groups', (done) => { it('fetches groups', done => {
const query = 'dummy query'; const query = 'dummy query';
const options = { unused: 'option' }; const options = { unused: 'option' };
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/groups.json`; const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/groups.json`;
mock.onGet(expectedUrl).reply(200, [{ mock.onGet(expectedUrl).reply(200, [
{
name: 'test', name: 'test',
}]); },
]);
Api.groups(query, options, (response) => { Api.groups(query, options, response => {
expect(response.length).toBe(1); expect(response.length).toBe(1);
expect(response[0].name).toBe('test'); expect(response[0].name).toBe('test');
done(); done();
...@@ -67,14 +69,16 @@ describe('Api', () => { ...@@ -67,14 +69,16 @@ describe('Api', () => {
}); });
describe('namespaces', () => { describe('namespaces', () => {
it('fetches namespaces', (done) => { it('fetches namespaces', done => {
const query = 'dummy query'; const query = 'dummy query';
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/namespaces.json`; const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/namespaces.json`;
mock.onGet(expectedUrl).reply(200, [{ mock.onGet(expectedUrl).reply(200, [
{
name: 'test', name: 'test',
}]); },
]);
Api.namespaces(query, (response) => { Api.namespaces(query, response => {
expect(response.length).toBe(1); expect(response.length).toBe(1);
expect(response[0].name).toBe('test'); expect(response[0].name).toBe('test');
done(); done();
...@@ -83,31 +87,35 @@ describe('Api', () => { ...@@ -83,31 +87,35 @@ describe('Api', () => {
}); });
describe('projects', () => { describe('projects', () => {
it('fetches projects with membership when logged in', (done) => { it('fetches projects with membership when logged in', done => {
const query = 'dummy query'; const query = 'dummy query';
const options = { unused: 'option' }; const options = { unused: 'option' };
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects.json`; const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects.json`;
window.gon.current_user_id = 1; window.gon.current_user_id = 1;
mock.onGet(expectedUrl).reply(200, [{ mock.onGet(expectedUrl).reply(200, [
{
name: 'test', name: 'test',
}]); },
]);
Api.projects(query, options, (response) => { Api.projects(query, options, response => {
expect(response.length).toBe(1); expect(response.length).toBe(1);
expect(response[0].name).toBe('test'); expect(response[0].name).toBe('test');
done(); done();
}); });
}); });
it('fetches projects without membership when not logged in', (done) => { it('fetches projects without membership when not logged in', done => {
const query = 'dummy query'; const query = 'dummy query';
const options = { unused: 'option' }; const options = { unused: 'option' };
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects.json`; const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects.json`;
mock.onGet(expectedUrl).reply(200, [{ mock.onGet(expectedUrl).reply(200, [
{
name: 'test', name: 'test',
}]); },
]);
Api.projects(query, options, (response) => { Api.projects(query, options, response => {
expect(response.length).toBe(1); expect(response.length).toBe(1);
expect(response[0].name).toBe('test'); expect(response[0].name).toBe('test');
done(); done();
...@@ -115,8 +123,65 @@ describe('Api', () => { ...@@ -115,8 +123,65 @@ describe('Api', () => {
}); });
}); });
describe('mergerequest', () => {
it('fetches a merge request', done => {
const projectPath = 'abc';
const mergeRequestId = '123456';
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectPath}/merge_requests/${mergeRequestId}`;
mock.onGet(expectedUrl).reply(200, {
title: 'test',
});
Api.mergeRequest(projectPath, mergeRequestId)
.then(({ data }) => {
expect(data.title).toBe('test');
})
.then(done)
.catch(done.fail);
});
});
describe('mergerequest changes', () => {
it('fetches the changes of a merge request', done => {
const projectPath = 'abc';
const mergeRequestId = '123456';
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectPath}/merge_requests/${mergeRequestId}/changes`;
mock.onGet(expectedUrl).reply(200, {
title: 'test',
});
Api.mergeRequestChanges(projectPath, mergeRequestId)
.then(({ data }) => {
expect(data.title).toBe('test');
})
.then(done)
.catch(done.fail);
});
});
describe('mergerequest versions', () => {
it('fetches the versions of a merge request', done => {
const projectPath = 'abc';
const mergeRequestId = '123456';
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectPath}/merge_requests/${mergeRequestId}/versions`;
mock.onGet(expectedUrl).reply(200, [
{
id: 123,
},
]);
Api.mergeRequestVersions(projectPath, mergeRequestId)
.then(({ data }) => {
expect(data.length).toBe(1);
expect(data[0].id).toBe(123);
})
.then(done)
.catch(done.fail);
});
});
describe('newLabel', () => { describe('newLabel', () => {
it('creates a new label', (done) => { it('creates a new label', done => {
const namespace = 'some namespace'; const namespace = 'some namespace';
const project = 'some project'; const project = 'some project';
const labelData = { some: 'data' }; const labelData = { some: 'data' };
...@@ -124,36 +189,42 @@ describe('Api', () => { ...@@ -124,36 +189,42 @@ describe('Api', () => {
const expectedData = { const expectedData = {
label: labelData, label: labelData,
}; };
mock.onPost(expectedUrl).reply((config) => { mock.onPost(expectedUrl).reply(config => {
expect(config.data).toBe(JSON.stringify(expectedData)); expect(config.data).toBe(JSON.stringify(expectedData));
return [200, { return [
200,
{
name: 'test', name: 'test',
}]; },
];
}); });
Api.newLabel(namespace, project, labelData, (response) => { Api.newLabel(namespace, project, labelData, response => {
expect(response.name).toBe('test'); expect(response.name).toBe('test');
done(); done();
}); });
}); });
it('creates a group label', (done) => { it('creates a group label', done => {
const namespace = 'group/subgroup'; const namespace = 'group/subgroup';
const labelData = { some: 'data' }; const labelData = { some: 'data' };
const expectedUrl = `${dummyUrlRoot}/groups/${namespace}/-/labels`; const expectedUrl = `${dummyUrlRoot}/groups/${namespace}/-/labels`;
const expectedData = { const expectedData = {
label: labelData, label: labelData,
}; };
mock.onPost(expectedUrl).reply((config) => { mock.onPost(expectedUrl).reply(config => {
expect(config.data).toBe(JSON.stringify(expectedData)); expect(config.data).toBe(JSON.stringify(expectedData));
return [200, { return [
200,
{
name: 'test', name: 'test',
}]; },
];
}); });
Api.newLabel(namespace, undefined, labelData, (response) => { Api.newLabel(namespace, undefined, labelData, response => {
expect(response.name).toBe('test'); expect(response.name).toBe('test');
done(); done();
}); });
...@@ -161,15 +232,17 @@ describe('Api', () => { ...@@ -161,15 +232,17 @@ describe('Api', () => {
}); });
describe('groupProjects', () => { describe('groupProjects', () => {
it('fetches group projects', (done) => { it('fetches group projects', done => {
const groupId = '123456'; const groupId = '123456';
const query = 'dummy query'; const query = 'dummy query';
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/groups/${groupId}/projects.json`; const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/groups/${groupId}/projects.json`;
mock.onGet(expectedUrl).reply(200, [{ mock.onGet(expectedUrl).reply(200, [
{
name: 'test', name: 'test',
}]); },
]);
Api.groupProjects(groupId, query, (response) => { Api.groupProjects(groupId, query, response => {
expect(response.length).toBe(1); expect(response.length).toBe(1);
expect(response[0].name).toBe('test'); expect(response[0].name).toBe('test');
done(); done();
...@@ -178,13 +251,13 @@ describe('Api', () => { ...@@ -178,13 +251,13 @@ describe('Api', () => {
}); });
describe('licenseText', () => { describe('licenseText', () => {
it('fetches a license text', (done) => { it('fetches a license text', done => {
const licenseKey = "driver's license"; const licenseKey = "driver's license";
const data = { unused: 'option' }; const data = { unused: 'option' };
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/templates/licenses/${licenseKey}`; const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/templates/licenses/${licenseKey}`;
mock.onGet(expectedUrl).reply(200, 'test'); mock.onGet(expectedUrl).reply(200, 'test');
Api.licenseText(licenseKey, data, (response) => { Api.licenseText(licenseKey, data, response => {
expect(response).toBe('test'); expect(response).toBe('test');
done(); done();
}); });
...@@ -192,12 +265,12 @@ describe('Api', () => { ...@@ -192,12 +265,12 @@ describe('Api', () => {
}); });
describe('gitignoreText', () => { describe('gitignoreText', () => {
it('fetches a gitignore text', (done) => { it('fetches a gitignore text', done => {
const gitignoreKey = 'ignore git'; const gitignoreKey = 'ignore git';
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/templates/gitignores/${gitignoreKey}`; const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/templates/gitignores/${gitignoreKey}`;
mock.onGet(expectedUrl).reply(200, 'test'); mock.onGet(expectedUrl).reply(200, 'test');
Api.gitignoreText(gitignoreKey, (response) => { Api.gitignoreText(gitignoreKey, response => {
expect(response).toBe('test'); expect(response).toBe('test');
done(); done();
}); });
...@@ -205,12 +278,12 @@ describe('Api', () => { ...@@ -205,12 +278,12 @@ describe('Api', () => {
}); });
describe('gitlabCiYml', () => { describe('gitlabCiYml', () => {
it('fetches a .gitlab-ci.yml', (done) => { it('fetches a .gitlab-ci.yml', done => {
const gitlabCiYmlKey = 'Y CI ML'; const gitlabCiYmlKey = 'Y CI ML';
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/templates/gitlab_ci_ymls/${gitlabCiYmlKey}`; const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/templates/gitlab_ci_ymls/${gitlabCiYmlKey}`;
mock.onGet(expectedUrl).reply(200, 'test'); mock.onGet(expectedUrl).reply(200, 'test');
Api.gitlabCiYml(gitlabCiYmlKey, (response) => { Api.gitlabCiYml(gitlabCiYmlKey, response => {
expect(response).toBe('test'); expect(response).toBe('test');
done(); done();
}); });
...@@ -218,12 +291,12 @@ describe('Api', () => { ...@@ -218,12 +291,12 @@ describe('Api', () => {
}); });
describe('dockerfileYml', () => { describe('dockerfileYml', () => {
it('fetches a Dockerfile', (done) => { it('fetches a Dockerfile', done => {
const dockerfileYmlKey = 'a giant whale'; const dockerfileYmlKey = 'a giant whale';
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/templates/dockerfiles/${dockerfileYmlKey}`; const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/templates/dockerfiles/${dockerfileYmlKey}`;
mock.onGet(expectedUrl).reply(200, 'test'); mock.onGet(expectedUrl).reply(200, 'test');
Api.dockerfileYml(dockerfileYmlKey, (response) => { Api.dockerfileYml(dockerfileYmlKey, response => {
expect(response).toBe('test'); expect(response).toBe('test');
done(); done();
}); });
...@@ -231,12 +304,14 @@ describe('Api', () => { ...@@ -231,12 +304,14 @@ describe('Api', () => {
}); });
describe('issueTemplate', () => { describe('issueTemplate', () => {
it('fetches an issue template', (done) => { it('fetches an issue template', done => {
const namespace = 'some namespace'; const namespace = 'some namespace';
const project = 'some project'; const project = 'some project';
const templateKey = ' template #%?.key '; const templateKey = ' template #%?.key ';
const templateType = 'template type'; const templateType = 'template type';
const expectedUrl = `${dummyUrlRoot}/${namespace}/${project}/templates/${templateType}/${encodeURIComponent(templateKey)}`; const expectedUrl = `${dummyUrlRoot}/${namespace}/${project}/templates/${templateType}/${encodeURIComponent(
templateKey,
)}`;
mock.onGet(expectedUrl).reply(200, 'test'); mock.onGet(expectedUrl).reply(200, 'test');
Api.issueTemplate(namespace, project, templateKey, templateType, (error, response) => { Api.issueTemplate(namespace, project, templateKey, templateType, (error, response) => {
...@@ -247,13 +322,15 @@ describe('Api', () => { ...@@ -247,13 +322,15 @@ describe('Api', () => {
}); });
describe('users', () => { describe('users', () => {
it('fetches users', (done) => { it('fetches users', done => {
const query = 'dummy query'; const query = 'dummy query';
const options = { unused: 'option' }; const options = { unused: 'option' };
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/users.json`; const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/users.json`;
mock.onGet(expectedUrl).reply(200, [{ mock.onGet(expectedUrl).reply(200, [
{
name: 'test', name: 'test',
}]); },
]);
Api.users(query, options) Api.users(query, options)
.then(({ data }) => { .then(({ data }) => {
......
...@@ -89,6 +89,20 @@ describe('RepoEditor', () => { ...@@ -89,6 +89,20 @@ describe('RepoEditor', () => {
done(); done();
}); });
}); });
it('calls createDiffInstance when viewer is a merge request diff', done => {
vm.$store.state.viewer = 'mrdiff';
spyOn(vm.editor, 'createDiffInstance');
vm.createEditorInstance();
vm.$nextTick(() => {
expect(vm.editor.createDiffInstance).toHaveBeenCalled();
done();
});
});
}); });
describe('setupEditor', () => { describe('setupEditor', () => {
...@@ -134,4 +148,48 @@ describe('RepoEditor', () => { ...@@ -134,4 +148,48 @@ describe('RepoEditor', () => {
}); });
}); });
}); });
describe('setup editor for merge request viewing', () => {
beforeEach(done => {
vm.$destroy();
resetStore(vm.$store);
Editor.editorInstance.modelManager.dispose();
const f = file();
const RepoEditor = Vue.extend(repoEditor);
vm = createComponentWithStore(RepoEditor, store, {
file: f,
});
f.active = true;
f.tempFile = true;
f.html = 'testing';
f.mrChange = { diff: 'ABC' };
f.baseRaw = 'testing';
f.content = 'test';
vm.$store.state.openFiles.push(f);
vm.$store.state.entries[f.path] = f;
vm.$store.state.viewer = 'mrdiff';
vm.monaco = true;
vm.$mount();
monacoLoader(['vs/editor/editor.main'], () => {
setTimeout(done, 0);
});
});
it('attaches merge request model to editor when merge request diff', () => {
spyOn(vm.editor, 'attachMergeRequestModel').and.callThrough();
vm.setupEditor();
expect(vm.editor.attachMergeRequestModel).toHaveBeenCalledWith(vm.model);
});
});
}); });
...@@ -57,6 +57,7 @@ describe('RepoTabs', () => { ...@@ -57,6 +57,7 @@ describe('RepoTabs', () => {
files: [], files: [],
viewer: 'editor', viewer: 'editor',
hasChanges: false, hasChanges: false,
hasMergeRequest: false,
}, },
'#test-app', '#test-app',
); );
......
...@@ -11,7 +11,10 @@ describe('Multi-file editor library model', () => { ...@@ -11,7 +11,10 @@ describe('Multi-file editor library model', () => {
spyOn(eventHub, '$on').and.callThrough(); spyOn(eventHub, '$on').and.callThrough();
monacoLoader(['vs/editor/editor.main'], () => { monacoLoader(['vs/editor/editor.main'], () => {
model = new Model(monaco, file('path')); const f = file('path');
f.mrChange = { diff: 'ABC' };
f.baseRaw = 'test';
model = new Model(monaco, f);
done(); done();
}); });
...@@ -21,9 +24,10 @@ describe('Multi-file editor library model', () => { ...@@ -21,9 +24,10 @@ describe('Multi-file editor library model', () => {
model.dispose(); model.dispose();
}); });
it('creates original model & new model', () => { it('creates original model & base model & new model', () => {
expect(model.originalModel).not.toBeNull(); expect(model.originalModel).not.toBeNull();
expect(model.model).not.toBeNull(); expect(model.model).not.toBeNull();
expect(model.baseModel).not.toBeNull();
}); });
it('adds eventHub listener', () => { it('adds eventHub listener', () => {
...@@ -51,6 +55,12 @@ describe('Multi-file editor library model', () => { ...@@ -51,6 +55,12 @@ describe('Multi-file editor library model', () => {
}); });
}); });
describe('getBaseModel', () => {
it('returns base model', () => {
expect(model.getBaseModel()).toBe(model.baseModel);
});
});
describe('setValue', () => { describe('setValue', () => {
it('updates models value', () => { it('updates models value', () => {
model.setValue('testing 123'); model.setValue('testing 123');
......
...@@ -143,6 +143,31 @@ describe('Multi-file editor library', () => { ...@@ -143,6 +143,31 @@ describe('Multi-file editor library', () => {
}); });
}); });
describe('attachMergeRequestModel', () => {
let model;
beforeEach(() => {
instance.createDiffInstance(document.createElement('div'));
const f = file();
f.mrChanges = { diff: 'ABC' };
f.baseRaw = 'testing';
model = instance.createModel(f);
});
it('sets original & modified', () => {
spyOn(instance.instance, 'setModel');
instance.attachMergeRequestModel(model);
expect(instance.instance.setModel).toHaveBeenCalledWith({
original: model.getBaseModel(),
modified: model.getModel(),
});
});
});
describe('clearEditor', () => { describe('clearEditor', () => {
it('resets the editor model', () => { it('resets the editor model', () => {
instance.createInstance(document.createElement('div')); instance.createInstance(document.createElement('div'));
......
...@@ -5,7 +5,7 @@ import router from '~/ide/ide_router'; ...@@ -5,7 +5,7 @@ import router from '~/ide/ide_router';
import eventHub from '~/ide/eventhub'; import eventHub from '~/ide/eventhub';
import { file, resetStore } from '../../helpers'; import { file, resetStore } from '../../helpers';
describe('Multi-file store file actions', () => { describe('IDE store file actions', () => {
beforeEach(() => { beforeEach(() => {
spyOn(router, 'push'); spyOn(router, 'push');
}); });
...@@ -189,7 +189,7 @@ describe('Multi-file store file actions', () => { ...@@ -189,7 +189,7 @@ describe('Multi-file store file actions', () => {
it('calls the service', done => { it('calls the service', done => {
store store
.dispatch('getFileData', localFile) .dispatch('getFileData', { path: localFile.path })
.then(() => { .then(() => {
expect(service.getFileData).toHaveBeenCalledWith('getFileDataURL'); expect(service.getFileData).toHaveBeenCalledWith('getFileDataURL');
...@@ -200,7 +200,7 @@ describe('Multi-file store file actions', () => { ...@@ -200,7 +200,7 @@ describe('Multi-file store file actions', () => {
it('sets the file data', done => { it('sets the file data', done => {
store store
.dispatch('getFileData', localFile) .dispatch('getFileData', { path: localFile.path })
.then(() => { .then(() => {
expect(localFile.blamePath).toBe('blame_path'); expect(localFile.blamePath).toBe('blame_path');
...@@ -211,7 +211,7 @@ describe('Multi-file store file actions', () => { ...@@ -211,7 +211,7 @@ describe('Multi-file store file actions', () => {
it('sets document title', done => { it('sets document title', done => {
store store
.dispatch('getFileData', localFile) .dispatch('getFileData', { path: localFile.path })
.then(() => { .then(() => {
expect(document.title).toBe('testing getFileData'); expect(document.title).toBe('testing getFileData');
...@@ -222,7 +222,7 @@ describe('Multi-file store file actions', () => { ...@@ -222,7 +222,7 @@ describe('Multi-file store file actions', () => {
it('sets the file as active', done => { it('sets the file as active', done => {
store store
.dispatch('getFileData', localFile) .dispatch('getFileData', { path: localFile.path })
.then(() => { .then(() => {
expect(localFile.active).toBeTruthy(); expect(localFile.active).toBeTruthy();
...@@ -231,9 +231,20 @@ describe('Multi-file store file actions', () => { ...@@ -231,9 +231,20 @@ describe('Multi-file store file actions', () => {
.catch(done.fail); .catch(done.fail);
}); });
it('sets the file not as active if we pass makeFileActive false', done => {
store
.dispatch('getFileData', { path: localFile.path, makeFileActive: false })
.then(() => {
expect(localFile.active).toBeFalsy();
done();
})
.catch(done.fail);
});
it('adds the file to open files', done => { it('adds the file to open files', done => {
store store
.dispatch('getFileData', localFile) .dispatch('getFileData', { path: localFile.path })
.then(() => { .then(() => {
expect(store.state.openFiles.length).toBe(1); expect(store.state.openFiles.length).toBe(1);
expect(store.state.openFiles[0].name).toBe(localFile.name); expect(store.state.openFiles[0].name).toBe(localFile.name);
...@@ -256,7 +267,7 @@ describe('Multi-file store file actions', () => { ...@@ -256,7 +267,7 @@ describe('Multi-file store file actions', () => {
it('calls getRawFileData service method', done => { it('calls getRawFileData service method', done => {
store store
.dispatch('getRawFileData', tmpFile) .dispatch('getRawFileData', { path: tmpFile.path })
.then(() => { .then(() => {
expect(service.getRawFileData).toHaveBeenCalledWith(tmpFile); expect(service.getRawFileData).toHaveBeenCalledWith(tmpFile);
...@@ -267,7 +278,7 @@ describe('Multi-file store file actions', () => { ...@@ -267,7 +278,7 @@ describe('Multi-file store file actions', () => {
it('updates file raw data', done => { it('updates file raw data', done => {
store store
.dispatch('getRawFileData', tmpFile) .dispatch('getRawFileData', { path: tmpFile.path })
.then(() => { .then(() => {
expect(tmpFile.raw).toBe('raw'); expect(tmpFile.raw).toBe('raw');
...@@ -275,6 +286,22 @@ describe('Multi-file store file actions', () => { ...@@ -275,6 +286,22 @@ describe('Multi-file store file actions', () => {
}) })
.catch(done.fail); .catch(done.fail);
}); });
it('calls also getBaseRawFileData service method', done => {
spyOn(service, 'getBaseRawFileData').and.returnValue(Promise.resolve('baseraw'));
tmpFile.mrChange = { new_file: false };
store
.dispatch('getRawFileData', { path: tmpFile.path, baseSha: 'SHA' })
.then(() => {
expect(service.getBaseRawFileData).toHaveBeenCalledWith(tmpFile, 'SHA');
expect(tmpFile.baseRaw).toBe('baseraw');
done();
})
.catch(done.fail);
});
}); });
describe('changeFileContent', () => { describe('changeFileContent', () => {
......
import store from '~/ide/stores';
import service from '~/ide/services';
import { resetStore } from '../../helpers';
describe('IDE store merge request actions', () => {
beforeEach(() => {
store.state.projects.abcproject = {
mergeRequests: {},
};
});
afterEach(() => {
resetStore(store);
});
describe('getMergeRequestData', () => {
beforeEach(() => {
spyOn(service, 'getProjectMergeRequestData').and.returnValue(
Promise.resolve({ data: { title: 'mergerequest' } }),
);
});
it('calls getProjectMergeRequestData service method', done => {
store
.dispatch('getMergeRequestData', { projectId: 'abcproject', mergeRequestId: 1 })
.then(() => {
expect(service.getProjectMergeRequestData).toHaveBeenCalledWith('abcproject', 1);
done();
})
.catch(done.fail);
});
it('sets the Merge Request Object', done => {
store
.dispatch('getMergeRequestData', { projectId: 'abcproject', mergeRequestId: 1 })
.then(() => {
expect(store.state.projects.abcproject.mergeRequests['1'].title).toBe('mergerequest');
expect(store.state.currentMergeRequestId).toBe(1);
done();
})
.catch(done.fail);
});
});
describe('getMergeRequestChanges', () => {
beforeEach(() => {
spyOn(service, 'getProjectMergeRequestChanges').and.returnValue(
Promise.resolve({ data: { title: 'mergerequest' } }),
);
store.state.projects.abcproject.mergeRequests['1'] = { changes: [] };
});
it('calls getProjectMergeRequestChanges service method', done => {
store
.dispatch('getMergeRequestChanges', { projectId: 'abcproject', mergeRequestId: 1 })
.then(() => {
expect(service.getProjectMergeRequestChanges).toHaveBeenCalledWith('abcproject', 1);
done();
})
.catch(done.fail);
});
it('sets the Merge Request Changes Object', done => {
store
.dispatch('getMergeRequestChanges', { projectId: 'abcproject', mergeRequestId: 1 })
.then(() => {
expect(store.state.projects.abcproject.mergeRequests['1'].changes.title).toBe(
'mergerequest',
);
done();
})
.catch(done.fail);
});
});
describe('getMergeRequestVersions', () => {
beforeEach(() => {
spyOn(service, 'getProjectMergeRequestVersions').and.returnValue(
Promise.resolve({ data: [{ id: 789 }] }),
);
store.state.projects.abcproject.mergeRequests['1'] = { versions: [] };
});
it('calls getProjectMergeRequestVersions service method', done => {
store
.dispatch('getMergeRequestVersions', { projectId: 'abcproject', mergeRequestId: 1 })
.then(() => {
expect(service.getProjectMergeRequestVersions).toHaveBeenCalledWith('abcproject', 1);
done();
})
.catch(done.fail);
});
it('sets the Merge Request Versions Object', done => {
store
.dispatch('getMergeRequestVersions', { projectId: 'abcproject', mergeRequestId: 1 })
.then(() => {
expect(store.state.projects.abcproject.mergeRequests['1'].versions.length).toBe(1);
done();
})
.catch(done.fail);
});
});
});
...@@ -68,9 +68,7 @@ describe('Multi-file store tree actions', () => { ...@@ -68,9 +68,7 @@ describe('Multi-file store tree actions', () => {
expect(projectTree.tree[0].tree[1].name).toBe('fileinfolder.js'); expect(projectTree.tree[0].tree[1].name).toBe('fileinfolder.js');
expect(projectTree.tree[1].type).toBe('blob'); expect(projectTree.tree[1].type).toBe('blob');
expect(projectTree.tree[0].tree[0].tree[0].type).toBe('blob'); expect(projectTree.tree[0].tree[0].tree[0].type).toBe('blob');
expect(projectTree.tree[0].tree[0].tree[0].name).toBe( expect(projectTree.tree[0].tree[0].tree[0].name).toBe('fileinsubfolder.js');
'fileinsubfolder.js',
);
done(); done();
}) })
...@@ -132,9 +130,7 @@ describe('Multi-file store tree actions', () => { ...@@ -132,9 +130,7 @@ describe('Multi-file store tree actions', () => {
store store
.dispatch('getLastCommitData', projectTree) .dispatch('getLastCommitData', projectTree)
.then(() => { .then(() => {
expect(service.getTreeLastCommit).toHaveBeenCalledWith( expect(service.getTreeLastCommit).toHaveBeenCalledWith('lastcommitpath');
'lastcommitpath',
);
done(); done();
}) })
...@@ -160,9 +156,7 @@ describe('Multi-file store tree actions', () => { ...@@ -160,9 +156,7 @@ describe('Multi-file store tree actions', () => {
.dispatch('getLastCommitData', projectTree) .dispatch('getLastCommitData', projectTree)
.then(Vue.nextTick) .then(Vue.nextTick)
.then(() => { .then(() => {
expect(projectTree.tree[0].lastCommit.message).not.toBe( expect(projectTree.tree[0].lastCommit.message).not.toBe('commit message');
'commit message',
);
done(); done();
}) })
......
...@@ -2,7 +2,7 @@ import * as getters from '~/ide/stores/getters'; ...@@ -2,7 +2,7 @@ import * as getters from '~/ide/stores/getters';
import state from '~/ide/stores/state'; import state from '~/ide/stores/state';
import { file } from '../helpers'; import { file } from '../helpers';
describe('Multi-file store getters', () => { describe('IDE store getters', () => {
let localState; let localState;
beforeEach(() => { beforeEach(() => {
...@@ -52,4 +52,24 @@ describe('Multi-file store getters', () => { ...@@ -52,4 +52,24 @@ describe('Multi-file store getters', () => {
expect(modifiedFiles[0].name).toBe('added'); expect(modifiedFiles[0].name).toBe('added');
}); });
}); });
describe('currentMergeRequest', () => {
it('returns Current Merge Request', () => {
localState.currentProjectId = 'abcproject';
localState.currentMergeRequestId = 1;
localState.projects.abcproject = {
mergeRequests: {
1: { mergeId: 1 },
},
};
expect(getters.currentMergeRequest(localState).mergeId).toBe(1);
});
it('returns null if no active Merge Request was found', () => {
localState.currentProjectId = 'otherproject';
expect(getters.currentMergeRequest(localState)).toBeNull();
});
});
}); });
...@@ -2,7 +2,7 @@ import mutations from '~/ide/stores/mutations/file'; ...@@ -2,7 +2,7 @@ import mutations from '~/ide/stores/mutations/file';
import state from '~/ide/stores/state'; import state from '~/ide/stores/state';
import { file } from '../../helpers'; import { file } from '../../helpers';
describe('Multi-file store file mutations', () => { describe('IDE store file mutations', () => {
let localState; let localState;
let localFile; let localFile;
...@@ -62,6 +62,8 @@ describe('Multi-file store file mutations', () => { ...@@ -62,6 +62,8 @@ describe('Multi-file store file mutations', () => {
expect(localFile.rawPath).toBe('raw'); expect(localFile.rawPath).toBe('raw');
expect(localFile.binary).toBeTruthy(); expect(localFile.binary).toBeTruthy();
expect(localFile.renderError).toBe('render_error'); expect(localFile.renderError).toBe('render_error');
expect(localFile.raw).toBeNull();
expect(localFile.baseRaw).toBeNull();
}); });
}); });
...@@ -76,6 +78,17 @@ describe('Multi-file store file mutations', () => { ...@@ -76,6 +78,17 @@ describe('Multi-file store file mutations', () => {
}); });
}); });
describe('SET_FILE_BASE_RAW_DATA', () => {
it('sets raw data from base branch', () => {
mutations.SET_FILE_BASE_RAW_DATA(localState, {
file: localFile,
baseRaw: 'testing',
});
expect(localFile.baseRaw).toBe('testing');
});
});
describe('UPDATE_FILE_CONTENT', () => { describe('UPDATE_FILE_CONTENT', () => {
beforeEach(() => { beforeEach(() => {
localFile.raw = 'test'; localFile.raw = 'test';
...@@ -112,6 +125,17 @@ describe('Multi-file store file mutations', () => { ...@@ -112,6 +125,17 @@ describe('Multi-file store file mutations', () => {
}); });
}); });
describe('SET_FILE_MR_CHANGE', () => {
it('sets file mr change', () => {
mutations.SET_FILE_MR_CHANGE(localState, {
file: localFile,
mrChange: { diff: 'ABC' },
});
expect(localFile.mrChange.diff).toBe('ABC');
});
});
describe('DISCARD_FILE_CHANGES', () => { describe('DISCARD_FILE_CHANGES', () => {
beforeEach(() => { beforeEach(() => {
localFile.content = 'test'; localFile.content = 'test';
......
import mutations from '~/ide/stores/mutations/merge_request';
import state from '~/ide/stores/state';
describe('IDE store merge request mutations', () => {
let localState;
beforeEach(() => {
localState = state();
localState.projects = { abcproject: { mergeRequests: {} } };
mutations.SET_MERGE_REQUEST(localState, {
projectPath: 'abcproject',
mergeRequestId: 1,
mergeRequest: {
title: 'mr',
},
});
});
describe('SET_CURRENT_MERGE_REQUEST', () => {
it('sets current merge request', () => {
mutations.SET_CURRENT_MERGE_REQUEST(localState, 2);
expect(localState.currentMergeRequestId).toBe(2);
});
});
describe('SET_MERGE_REQUEST', () => {
it('setsmerge request data', () => {
const newMr = localState.projects.abcproject.mergeRequests[1];
expect(newMr.title).toBe('mr');
expect(newMr.active).toBeTruthy();
});
});
describe('SET_MERGE_REQUEST_CHANGES', () => {
it('sets merge request changes', () => {
mutations.SET_MERGE_REQUEST_CHANGES(localState, {
projectPath: 'abcproject',
mergeRequestId: 1,
changes: {
diff: 'abc',
},
});
const newMr = localState.projects.abcproject.mergeRequests[1];
expect(newMr.changes.diff).toBe('abc');
});
});
describe('SET_MERGE_REQUEST_VERSIONS', () => {
it('sets merge request versions', () => {
mutations.SET_MERGE_REQUEST_VERSIONS(localState, {
projectPath: 'abcproject',
mergeRequestId: 1,
versions: [{ id: 123 }],
});
const newMr = localState.projects.abcproject.mergeRequests[1];
expect(newMr.versions.length).toBe(1);
expect(newMr.versions[0].id).toBe(123);
});
});
});
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