summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/assets/javascripts/files_comment_button.js.coffee24
-rw-r--r--app/helpers/diff_helper.rb2
-rw-r--r--features/steps/shared/diff_note.rb17
-rw-r--r--spec/helpers/diff_helper_spec.rb2
4 files changed, 27 insertions, 18 deletions
diff --git a/app/assets/javascripts/files_comment_button.js.coffee b/app/assets/javascripts/files_comment_button.js.coffee
index d2613847f69..681592f246a 100644
--- a/app/assets/javascripts/files_comment_button.js.coffee
+++ b/app/assets/javascripts/files_comment_button.js.coffee
@@ -8,11 +8,16 @@ class @FilesCommentButton
@LINE_HOLDER_CLASS = '.line_holder'
@LINE_NUMBER_CLASS = 'diff-line-num'
@LINE_CONTENT_CLASS = 'line_content'
+ @UNFOLDABLE_LINE_CLASS = 'js-unfold'
+ @EMPTY_CELL_CLASS = 'empty-cell'
+ @OLD_LINE_CLASS = 'old_line'
@LINE_COLUMN_CLASSES = ".#{@LINE_NUMBER_CLASS}, .line_content"
@TEXT_FILE_SELECTOR = '.text-file'
@DEBOUNCE_TIMEOUT_DURATION = 150
+ @VIEW_TYPE = $('input#view[type=hidden]').val()
+
$(document)
.on 'mouseover', @LINE_COLUMN_CLASSES, @debounceRender
.on 'mouseleave', @LINE_COLUMN_CLASSES, @destroy
@@ -38,13 +43,13 @@ class @FilesCommentButton
id:
noteable: textFileElement.attr 'data-noteable-id'
commit: textFileElement.attr 'data-commit-id'
- discussion: lineContentElement.attr('data-discussion-id') || lineHolderElement.attr('data-discussion-id')
+ discussion: lineContentElement.attr('data-discussion-id') or lineHolderElement.attr('data-discussion-id')
type:
noteable: textFileElement.attr 'data-noteable-type'
note: textFileElement.attr 'data-note-type'
line: lineContentElement.attr 'data-line-type'
code:
- line: lineContentElement.attr('data-line-code') || lineHolderElement.attr('id')
+ line: lineContentElement.attr('data-line-code') or lineHolderElement.attr('id')
return
destroy: (e) =>
@@ -70,14 +75,17 @@ class @FilesCommentButton
$(hoveredElement.parent())
getLineNum: (hoveredElement) ->
- return hoveredElement if hoveredElement.hasClass @LINE_NUMBER_CLASS
-
- $(hoveredElement).prev('.' + @LINE_NUMBER_CLASS)
+ if @VIEW_TYPE is 'inline' and hoveredElement.hasClass @OLD_LINE_CLASS
+ $(hoveredElement).next ".#{@LINE_NUMBER_CLASS}"
+ else if hoveredElement.hasClass @LINE_NUMBER_CLASS
+ hoveredElement
+ else
+ $(hoveredElement).prev ".#{@LINE_NUMBER_CLASS}"
getLineContent: (hoveredElement) ->
return hoveredElement if hoveredElement.hasClass @LINE_CONTENT_CLASS
- $(hoveredElement).next('.' + @LINE_CONTENT_CLASS)
+ $(hoveredElement).next ".#{@LINE_CONTENT_CLASS}"
isMovingToSameType: (e) ->
newLineNum = @getLineNum($(e.toElement))
@@ -85,4 +93,6 @@ class @FilesCommentButton
(newLineNum).is @getLineNum($(e.currentTarget))
shouldRender: (e, buttonParentElement) ->
- (!buttonParentElement.hasClass('empty-cell') and $(@COMMENT_BUTTON_CLASS, buttonParentElement).length is 0)
+ (!buttonParentElement.hasClass(@EMPTY_CELL_CLASS) and \
+ !buttonParentElement.hasClass(@UNFOLDABLE_LINE_CLASS) and \
+ $(@COMMENT_BUTTON_CLASS, buttonParentElement).length is 0)
diff --git a/app/helpers/diff_helper.rb b/app/helpers/diff_helper.rb
index e22dce59d0f..a282a67020f 100644
--- a/app/helpers/diff_helper.rb
+++ b/app/helpers/diff_helper.rb
@@ -39,7 +39,7 @@ module DiffHelper
end
def unfold_bottom_class(bottom)
- bottom ? 'js-unfold-bottom' : ''
+ bottom ? 'js-unfold js-unfold-bottom' : ''
end
def unfold_class(unfold)
diff --git a/features/steps/shared/diff_note.rb b/features/steps/shared/diff_note.rb
index 8dc461bdd95..146cbcfad5e 100644
--- a/features/steps/shared/diff_note.rb
+++ b/features/steps/shared/diff_note.rb
@@ -25,8 +25,7 @@ module SharedDiffNote
page.within("form[id$='#{sample_commit.line_code}-true']") do
fill_in "note[note]", with: "Typo, please fix"
- find(".js-comment-button").trigger("click")
- sleep 0.05
+ find(".js-comment-button").click
end
end
end
@@ -35,7 +34,7 @@ module SharedDiffNote
click_parallel_diff_line(sample_commit.del_line_code, 'old')
page.within("#{diff_file_selector} form[id$='#{sample_commit.del_line_code}-true']") do
fill_in "note[note]", with: "Old comment"
- find(".js-comment-button").trigger("click")
+ find(".js-comment-button").click
end
end
@@ -43,7 +42,7 @@ module SharedDiffNote
click_parallel_diff_line(sample_commit.line_code, 'new')
page.within("#{diff_file_selector} form[id$='#{sample_commit.line_code}-true']") do
fill_in "note[note]", with: "New comment"
- find(".js-comment-button").trigger("click")
+ find(".js-comment-button").click
end
end
@@ -211,7 +210,7 @@ module SharedDiffNote
end
step 'I click side-by-side diff button' do
- find('#parallel-diff-btn').trigger('click')
+ find('#parallel-diff-btn').click
end
step 'I see side-by-side diff button' do
@@ -223,12 +222,12 @@ module SharedDiffNote
end
def click_diff_line(code)
- find(".line_holder[id='#{code}'] td:nth-of-type(1)").hover
- find(".line_holder[id='#{code}'] button").trigger('click')
+ find(".line_holder[id='#{code}'] td:nth-of-type(1)").trigger 'mouseover'
+ find(".line_holder[id='#{code}'] button").trigger 'click'
end
def click_parallel_diff_line(code, line_type)
- find(".line_content.parallel.#{line_type}[data-line-code='#{code}']").trigger('mouseover')
- find(".line_holder.parallel button[data-line-code='#{code}']").trigger('click')
+ find(".line_content.parallel.#{line_type}[data-line-code='#{code}']").trigger 'mouseover'
+ find(".line_holder.parallel button[data-line-code='#{code}']").trigger 'click'
end
end
diff --git a/spec/helpers/diff_helper_spec.rb b/spec/helpers/diff_helper_spec.rb
index 52764f41e0d..a71dd53e6ed 100644
--- a/spec/helpers/diff_helper_spec.rb
+++ b/spec/helpers/diff_helper_spec.rb
@@ -59,7 +59,7 @@ describe DiffHelper do
end
it 'should return js class when bottom lines should be unfolded' do
- expect(unfold_bottom_class(true)).to eq('js-unfold-bottom')
+ expect(unfold_bottom_class(true)).to include('js-unfold-bottom')
end
end