Commit b24316b2 authored by Phil Hughes's avatar Phil Hughes

Added a test for open merge request files

parent ac8895b7
......@@ -74,7 +74,7 @@ export const getFileData = (
const normalizedHeaders = normalizeHeaders(headers);
setPageTitle(decodeURI(normalizedHeaders['PAGE-TITLE']));
commit(types.SET_FILE_DATA, { data, file });
if (data) commit(types.SET_FILE_DATA, { data, file });
if (openFile) commit(types.TOGGLE_FILE_OPEN, path);
if (makeFileActive) dispatch('setFileActive', path);
commit(types.TOGGLE_LOADING, { entry: file });
......
......@@ -262,16 +262,28 @@ describe('IDE store merge request actions', () => {
bar: {},
};
spyOn(store, 'dispatch').and.callFake(type => {
const originalDispatch = store.dispatch;
spyOn(store, 'dispatch').and.callFake((type, payload) => {
switch (type) {
case 'getMergeRequestData':
return Promise.resolve(testMergeRequest);
case 'getMergeRequestChanges':
return Promise.resolve(testMergeRequestChanges);
default:
case 'getFiles':
case 'getMergeRequestVersions':
case 'getBranchData':
case 'setFileMrChange':
return Promise.resolve();
default:
return originalDispatch(type, payload);
}
});
spyOn(service, 'getFileData').and.callFake(() =>
Promise.resolve({
headers: {},
}),
);
});
it('dispatch actions for merge request data', done => {
......@@ -303,7 +315,17 @@ describe('IDE store merge request actions', () => {
});
it('updates activity bar view and gets file data, if changes are found', done => {
testMergeRequestChanges.changes = [{ new_path: 'foo' }, { new_path: 'bar' }];
store.state.entries.foo = {
url: 'test',
};
store.state.entries.bar = {
url: 'test',
};
testMergeRequestChanges.changes = [
{ new_path: 'foo', path: 'foo' },
{ new_path: 'bar', path: 'bar' },
];
openMergeRequest(store, mr)
.then(() => {
......@@ -324,6 +346,8 @@ describe('IDE store merge request actions', () => {
openFile: true,
});
});
expect(store.state.openFiles.length).toBe(testMergeRequestChanges.changes.length);
})
.then(done)
.catch(done.fail);
......
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