Commit 32a1dc5e authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'ph/230900/fixGetDicussionJSError' into 'master'

Fix JS error when discussion has no diff_file

Closes #230900

See merge request gitlab-org/gitlab!37569
parents 6e34b265 b96371eb
......@@ -748,9 +748,11 @@ export const setCurrentDiffFileIdFromNote = ({ commit, rootGetters }, noteId) =>
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);
}
};
export const navigateToDiffFileIndex = ({ commit, state }, index) => {
......
......@@ -1603,6 +1603,18 @@ describe('DiffsStoreActions', () => {
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', () => {
......
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