Commit b96371eb authored by Phil Hughes's avatar Phil Hughes

Fix JS error when discussion has no diff_file

This can be caused by opening a merge request to a note
that is no in a diff, but just in the overview tab

Closes https://gitlab.com/gitlab-org/gitlab/-/issues/230900
parent e30e95e9
...@@ -748,9 +748,11 @@ export const setCurrentDiffFileIdFromNote = ({ commit, rootGetters }, noteId) => ...@@ -748,9 +748,11 @@ export const setCurrentDiffFileIdFromNote = ({ commit, rootGetters }, noteId) =>
if (!note) return; if (!note) return;
const fileHash = rootGetters.getDiscussion(note.discussion_id).diff_file.file_hash; const fileHash = rootGetters.getDiscussion(note.discussion_id).diff_file?.file_hash;
if (fileHash) {
commit(types.UPDATE_CURRENT_DIFF_FILE_ID, fileHash); commit(types.UPDATE_CURRENT_DIFF_FILE_ID, fileHash);
}
}; };
export const navigateToDiffFileIndex = ({ commit, state }, index) => { export const navigateToDiffFileIndex = ({ commit, state }, index) => {
......
...@@ -1603,6 +1603,18 @@ describe('DiffsStoreActions', () => { ...@@ -1603,6 +1603,18 @@ describe('DiffsStoreActions', () => {
expect(commit).toHaveBeenCalledWith(types.UPDATE_CURRENT_DIFF_FILE_ID, '123'); expect(commit).toHaveBeenCalledWith(types.UPDATE_CURRENT_DIFF_FILE_ID, '123');
}); });
it('does not commit UPDATE_CURRENT_DIFF_FILE_ID when discussion has no diff_file', () => {
const commit = jest.fn();
const rootGetters = {
getDiscussion: () => ({ id: '1' }),
notesById: { '1': { discussion_id: '2' } },
};
setCurrentDiffFileIdFromNote({ commit, rootGetters }, '1');
expect(commit).not.toHaveBeenCalled();
});
}); });
describe('navigateToDiffFileIndex', () => { describe('navigateToDiffFileIndex', () => {
......
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