From d3a8fb6e791aa4c6639eb15349d18f02e0408030 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Wed, 5 Dec 2018 14:12:51 +0000 Subject: [PATCH] Fixed expanding diff commit files Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/50662 --- app/assets/javascripts/diffs/store/actions.js | 18 ++++--- .../unreleased/diff-expand-commit-file.yml | 5 ++ spec/javascripts/diffs/store/actions_spec.js | 51 ++++++++++++++----- 3 files changed, 54 insertions(+), 20 deletions(-) create mode 100644 changelogs/unreleased/diff-expand-commit-file.yml diff --git a/app/assets/javascripts/diffs/store/actions.js b/app/assets/javascripts/diffs/store/actions.js index c87e178c8cf..c0456c18e44 100644 --- a/app/assets/javascripts/diffs/store/actions.js +++ b/app/assets/javascripts/diffs/store/actions.js @@ -147,13 +147,19 @@ export const scrollToLineIfNeededParallel = (_, line) => { } }; -export const loadCollapsedDiff = ({ commit }, file) => - axios.get(file.load_collapsed_diff_url).then(res => { - commit(types.ADD_COLLAPSED_DIFFS, { - file, - data: res.data, +export const loadCollapsedDiff = ({ commit, getters }, file) => + axios + .get(file.load_collapsed_diff_url, { + params: { + commit_id: getters.commitId, + }, + }) + .then(res => { + commit(types.ADD_COLLAPSED_DIFFS, { + file, + data: res.data, + }); }); - }); export const expandAllFiles = ({ commit }) => { commit(types.EXPAND_ALL_FILES); diff --git a/changelogs/unreleased/diff-expand-commit-file.yml b/changelogs/unreleased/diff-expand-commit-file.yml new file mode 100644 index 00000000000..8ca784d75c1 --- /dev/null +++ b/changelogs/unreleased/diff-expand-commit-file.yml @@ -0,0 +1,5 @@ +--- +title: Fixed diff files expanding not loading commit content +merge_request: +author: +type: fixed diff --git a/spec/javascripts/diffs/store/actions_spec.js b/spec/javascripts/diffs/store/actions_spec.js index 5656ce16db0..4b339a0553f 100644 --- a/spec/javascripts/diffs/store/actions_spec.js +++ b/spec/javascripts/diffs/store/actions_spec.js @@ -382,24 +382,47 @@ describe('DiffsStoreActions', () => { const file = { hash: 123, load_collapsed_diff_url: '/load/collapsed/diff/url' }; const data = { hash: 123, parallelDiffLines: [{ lineCode: 1 }] }; const mock = new MockAdapter(axios); + const commit = jasmine.createSpy('commit'); mock.onGet(file.loadCollapsedDiffUrl).reply(200, data); - testAction( - loadCollapsedDiff, - file, - {}, - [ - { - type: types.ADD_COLLAPSED_DIFFS, - payload: { file, data }, - }, - ], - [], - () => { + loadCollapsedDiff({ commit, getters: { commitId: null } }, file) + .then(() => { + expect(commit).toHaveBeenCalledWith(types.ADD_COLLAPSED_DIFFS, { file, data }); + mock.restore(); done(); - }, - ); + }) + .catch(done.fail); + }); + + it('should fetch data without commit ID', () => { + const file = { load_collapsed_diff_url: '/load/collapsed/diff/url' }; + const getters = { + commitId: null, + }; + + spyOn(axios, 'get').and.returnValue(Promise.resolve({ data: {} })); + + loadCollapsedDiff({ commit() {}, getters }, file); + + expect(axios.get).toHaveBeenCalledWith(file.load_collapsed_diff_url, { + params: { commit_id: null }, + }); + }); + + it('should fetch data with commit ID', () => { + const file = { load_collapsed_diff_url: '/load/collapsed/diff/url' }; + const getters = { + commitId: '123', + }; + + spyOn(axios, 'get').and.returnValue(Promise.resolve({ data: {} })); + + loadCollapsedDiff({ commit() {}, getters }, file); + + expect(axios.get).toHaveBeenCalledWith(file.load_collapsed_diff_url, { + params: { commit_id: '123' }, + }); }); });