Commit 50dfdf02 authored by Luke "Jared" Bennett's avatar Luke "Jared" Bennett Committed by Paco Guzman

fix up tests

Added more exceptions

Added handling inline view type
parent 914bb05d
......@@ -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)
......@@ -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)
......
......@@ -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
......@@ -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
......
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