From 90673dbcb82f78c53d071994ca65e3ace7a28f62 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Tue, 18 Sep 2018 16:27:53 +0100 Subject: [PATCH] Changed isDiscussionApplicableToLine to accept an object --- .../javascripts/diffs/store/mutations.js | 6 +++- app/assets/javascripts/diffs/store/utils.js | 2 +- spec/javascripts/diffs/store/utils_spec.js | 36 +++++++++++-------- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/app/assets/javascripts/diffs/store/mutations.js b/app/assets/javascripts/diffs/store/mutations.js index c7fcbe01704..59a2c09e54f 100644 --- a/app/assets/javascripts/diffs/store/mutations.js +++ b/app/assets/javascripts/diffs/store/mutations.js @@ -97,7 +97,11 @@ export default { isDiffDiscussion && hasLineCode && diffPosition && - isDiscussionApplicableToLine(firstDiscussion, diffPosition, state.latestDiff) + isDiscussionApplicableToLine({ + discussion: firstDiscussion, + diffPosition, + latestDiff: state.latestDiff, + }) ) { const targetLine = selectedFile.parallelDiffLines.find( line => diff --git a/app/assets/javascripts/diffs/store/utils.js b/app/assets/javascripts/diffs/store/utils.js index 17732f4eeb6..834a94ea42a 100644 --- a/app/assets/javascripts/diffs/store/utils.js +++ b/app/assets/javascripts/diffs/store/utils.js @@ -254,7 +254,7 @@ export function getDiffPositionByLineCode(diffFiles) { // This method will check whether the discussion is still applicable // to the diff line in question regarding different versions of the MR -export function isDiscussionApplicableToLine(discussion, diffPosition, latestDiff) { +export function isDiscussionApplicableToLine({ discussion, diffPosition, latestDiff }) { const { lineCode, ...diffPositionCopy } = diffPosition; if (discussion.original_position && discussion.position) { diff --git a/spec/javascripts/diffs/store/utils_spec.js b/spec/javascripts/diffs/store/utils_spec.js index cb712463e12..6138b9701f4 100644 --- a/spec/javascripts/diffs/store/utils_spec.js +++ b/spec/javascripts/diffs/store/utils_spec.js @@ -350,13 +350,21 @@ describe('DiffsStoreUtils', () => { it('returns true when the discussion is up to date', () => { expect( - utils.isDiscussionApplicableToLine(discussions.upToDateDiscussion1, diffPosition, true), + utils.isDiscussionApplicableToLine({ + discussion: discussions.upToDateDiscussion1, + diffPosition, + latestDiff: true, + }), ).toBe(true); }); it('returns false when the discussion is not up to date', () => { expect( - utils.isDiscussionApplicableToLine(discussions.outDatedDiscussion1, diffPosition, true), + utils.isDiscussionApplicableToLine({ + discussion: discussions.outDatedDiscussion1, + diffPosition, + latestDiff: true, + }), ).toBe(false); }); @@ -366,14 +374,14 @@ describe('DiffsStoreUtils', () => { delete discussion.position; expect( - utils.isDiscussionApplicableToLine( + utils.isDiscussionApplicableToLine({ discussion, - { + diffPosition: { ...diffPosition, lineCode: 'ABC_1', }, - true, - ), + latestDiff: true, + }), ).toBe(false); }); @@ -383,14 +391,14 @@ describe('DiffsStoreUtils', () => { delete discussion.position; expect( - utils.isDiscussionApplicableToLine( + utils.isDiscussionApplicableToLine({ discussion, - { + diffPosition: { ...diffPosition, lineCode: 'ABC_1', }, - true, - ), + latestDiff: true, + }), ).toBe(true); }); @@ -400,14 +408,14 @@ describe('DiffsStoreUtils', () => { delete discussion.position; expect( - utils.isDiscussionApplicableToLine( + utils.isDiscussionApplicableToLine({ discussion, - { + diffPosition: { ...diffPosition, lineCode: 'ABC_1', }, - false, - ), + latestDiff: false, + }), ).toBe(false); }); });