diff --git a/app/assets/javascripts/notes/components/diff_with_note.vue b/app/assets/javascripts/notes/components/diff_with_note.vue
index 9a854b05ee2851bff8fefc36fd79be49559ea23e..1df5ee04b37ab97da07e3b695a93aa7644ebc8bb 100644
--- a/app/assets/javascripts/notes/components/diff_with_note.vue
+++ b/app/assets/javascripts/notes/components/diff_with_note.vue
@@ -3,6 +3,7 @@ import { GlButton, GlSkeletonLoader } from '@gitlab/ui';
// eslint-disable-next-line no-restricted-imports
import { mapActions } from 'vuex';
import { mapState } from 'pinia';
+import { mergeUrlParams } from '~/lib/utils/url_utility';
import SafeHtml from '~/vue_shared/directives/safe_html';
import DiffFileHeader from '~/diffs/components/diff_file_header.vue';
import ImageDiffOverlay from '~/diffs/components/image_diff_overlay.vue';
@@ -78,6 +79,12 @@ export default {
return this.positionType === FILE_DIFF_POSITION_TYPE;
},
+ linkedFileDiscussionPath() {
+ const { discussion_path: discussionPath } = this.discussion;
+ const file = this.discussion.diff_file?.file_hash;
+
+ return discussionPath && file ? mergeUrlParams({ file }, discussionPath) : discussionPath;
+ },
showHeader() {
if (this.discussion.diff_file) return true;
@@ -131,7 +138,7 @@ export default {
{
describe('when discussion does not have a diff_file', () => {
beforeEach(() => {
- const imageDiscussion = JSON.parse(JSON.stringify(imageDiscussionFixture[0]));
+ const imageDiscussion = cloneDeep(imageDiscussionFixture[0]);
delete imageDiscussion.diff_file;
createComponent({ discussion: imageDiscussion, diffFile: {} });
@@ -184,4 +185,48 @@ describe('diff_with_note', () => {
expect(findDiffViewer().props('newSha')).toBe(mockCommitId);
});
});
+
+ describe('diff header', () => {
+ let fileDiscussion;
+
+ beforeEach(() => {
+ fileDiscussion = JSON.parse(JSON.stringify(discussionFixture[0]));
+ fileDiscussion.position.position_type = 'file';
+ fileDiscussion.original_position.position_type = 'file';
+ });
+
+ describe('when the discussion has a diff_file', () => {
+ beforeEach(() => {
+ wrapper = shallowMount(DiffWithNote, {
+ propsData: { discussion: fileDiscussion, diffFile: {} },
+ store,
+ });
+ });
+
+ it('links directly to the file to take advantage of the prioritized Linked File feature', () => {
+ const header = findDiffFileHeader();
+
+ expect(header.attributes('discussionpath')).toContain(
+ `file=${fileDiscussion.diff_file.file_hash}`,
+ );
+ });
+ });
+
+ describe('when the discussion does not have a diff_file', () => {
+ beforeEach(() => {
+ delete fileDiscussion.diff_file;
+
+ wrapper = shallowMount(DiffWithNote, {
+ propsData: { discussion: fileDiscussion, diffFile: {} },
+ store,
+ });
+ });
+
+ it('does not include the `file` search parameter in the file link', () => {
+ const header = findDiffFileHeader();
+
+ expect(header.attributes('discussionpath')).not.toContain('file=');
+ });
+ });
+ });
});