Commit d3a8fb6e authored by Phil Hughes's avatar Phil Hughes

Fixed expanding diff commit files

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/50662
parent 14db2a42
...@@ -147,13 +147,19 @@ export const scrollToLineIfNeededParallel = (_, line) => { ...@@ -147,13 +147,19 @@ export const scrollToLineIfNeededParallel = (_, line) => {
} }
}; };
export const loadCollapsedDiff = ({ commit }, file) => export const loadCollapsedDiff = ({ commit, getters }, file) =>
axios.get(file.load_collapsed_diff_url).then(res => { axios
commit(types.ADD_COLLAPSED_DIFFS, { .get(file.load_collapsed_diff_url, {
file, params: {
data: res.data, commit_id: getters.commitId,
},
})
.then(res => {
commit(types.ADD_COLLAPSED_DIFFS, {
file,
data: res.data,
});
}); });
});
export const expandAllFiles = ({ commit }) => { export const expandAllFiles = ({ commit }) => {
commit(types.EXPAND_ALL_FILES); commit(types.EXPAND_ALL_FILES);
......
---
title: Fixed diff files expanding not loading commit content
merge_request:
author:
type: fixed
...@@ -382,24 +382,47 @@ describe('DiffsStoreActions', () => { ...@@ -382,24 +382,47 @@ describe('DiffsStoreActions', () => {
const file = { hash: 123, load_collapsed_diff_url: '/load/collapsed/diff/url' }; const file = { hash: 123, load_collapsed_diff_url: '/load/collapsed/diff/url' };
const data = { hash: 123, parallelDiffLines: [{ lineCode: 1 }] }; const data = { hash: 123, parallelDiffLines: [{ lineCode: 1 }] };
const mock = new MockAdapter(axios); const mock = new MockAdapter(axios);
const commit = jasmine.createSpy('commit');
mock.onGet(file.loadCollapsedDiffUrl).reply(200, data); mock.onGet(file.loadCollapsedDiffUrl).reply(200, data);
testAction( loadCollapsedDiff({ commit, getters: { commitId: null } }, file)
loadCollapsedDiff, .then(() => {
file, expect(commit).toHaveBeenCalledWith(types.ADD_COLLAPSED_DIFFS, { file, data });
{},
[
{
type: types.ADD_COLLAPSED_DIFFS,
payload: { file, data },
},
],
[],
() => {
mock.restore(); mock.restore();
done(); 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' },
});
}); });
}); });
......
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