BigW Consortium Gitlab

Commit 38d56a8b by Tim Zallmann

Added Tests for all new functionality

parent f0e1ee5f
...@@ -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