Fixed expanding diff commit files
Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/50662
This commit is contained in:
parent
14db2a4214
commit
d3a8fb6e79
3 changed files with 54 additions and 20 deletions
|
@ -147,8 +147,14 @@ export const scrollToLineIfNeededParallel = (_, line) => {
|
|||
}
|
||||
};
|
||||
|
||||
export const loadCollapsedDiff = ({ commit }, file) =>
|
||||
axios.get(file.load_collapsed_diff_url).then(res => {
|
||||
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,
|
||||
|
|
5
changelogs/unreleased/diff-expand-commit-file.yml
Normal file
5
changelogs/unreleased/diff-expand-commit-file.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Fixed diff files expanding not loading commit content
|
||||
merge_request:
|
||||
author:
|
||||
type: fixed
|
|
@ -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' },
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue