diff options
author | Phil Hughes <me@iamphill.com> | 2018-11-20 15:11:33 +0000 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2018-11-20 15:11:33 +0000 |
commit | b24316b2fe757324b037aea7e06ce52d8dfa53d8 (patch) | |
tree | 073efadfd8f6476d10943d30cb6873a42795e943 | |
parent | ac8895b7413080a0f1a1bfe92227d3871e0ba1c7 (diff) | |
download | gitlab-ce-b24316b2fe757324b037aea7e06ce52d8dfa53d8.tar.gz |
Added a test for open merge request files
-rw-r--r-- | app/assets/javascripts/ide/stores/actions/file.js | 2 | ||||
-rw-r--r-- | spec/javascripts/ide/stores/actions/merge_request_spec.js | 30 |
2 files changed, 28 insertions, 4 deletions
diff --git a/app/assets/javascripts/ide/stores/actions/file.js b/app/assets/javascripts/ide/stores/actions/file.js index 2cdbb312b9e..a297740bd5f 100644 --- a/app/assets/javascripts/ide/stores/actions/file.js +++ b/app/assets/javascripts/ide/stores/actions/file.js @@ -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 }); diff --git a/spec/javascripts/ide/stores/actions/merge_request_spec.js b/spec/javascripts/ide/stores/actions/merge_request_spec.js index 950c447f924..d8e9260e932 100644 --- a/spec/javascripts/ide/stores/actions/merge_request_spec.js +++ b/spec/javascripts/ide/stores/actions/merge_request_spec.js @@ -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); |