From 7d654c0e1810f2023a1deaeddd542c5c92d20f42 Mon Sep 17 00:00:00 2001 From: Luke Bennett Date: Fri, 5 Aug 2016 13:02:08 +0100 Subject: Added addtional 'renderable' validator to check 'data-note-type' attr exists --- app/assets/javascripts/files_comment_button.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/files_comment_button.js b/app/assets/javascripts/files_comment_button.js index b2e49b71fec..817d38ea86e 100644 --- a/app/assets/javascripts/files_comment_button.js +++ b/app/assets/javascripts/files_comment_button.js @@ -39,12 +39,13 @@ FilesCommentButton.prototype.render = function(e) { var $currentTarget, buttonParentElement, lineContentElement, textFileElement; $currentTarget = $(e.currentTarget); + buttonParentElement = this.getButtonParent($currentTarget); - if (!this.shouldRender(e, buttonParentElement)) { - return; - } - textFileElement = this.getTextFileElement($currentTarget); + if (!this.validateButtonParent(buttonParentElement)) return; lineContentElement = this.getLineContent($currentTarget); + if (!this.validateLineContent(lineContentElement)) return; + + textFileElement = this.getTextFileElement($currentTarget); buttonParentElement.append(this.buildButton({ noteableType: textFileElement.attr('data-noteable-type'), noteableID: textFileElement.attr('data-noteable-id'), @@ -119,10 +120,14 @@ return newButtonParent.is(this.getButtonParent($(e.currentTarget))); }; - FilesCommentButton.prototype.shouldRender = function(e, buttonParentElement) { + FilesCommentButton.prototype.validateButtonParent = function(buttonParentElement) { return !buttonParentElement.hasClass(EMPTY_CELL_CLASS) && !buttonParentElement.hasClass(UNFOLDABLE_LINE_CLASS) && $(COMMENT_BUTTON_CLASS, buttonParentElement).length === 0; }; + FilesCommentButton.prototype.validateLineContent = function(lineContentElement) { + return lineContentElement.attr('data-note-type') && lineContentElement.attr('data-note-type') !== ''; + }; + return FilesCommentButton; })(); -- cgit v1.2.1 From 66a6dfbc5326418ce5b5e2c72bc8aca11890c601 Mon Sep 17 00:00:00 2001 From: Luke Bennett Date: Fri, 5 Aug 2016 14:02:10 +0100 Subject: Added 'with an unfolded line should not allow commenting' scenario (line 125) --- spec/features/merge_requests/diff_notes_spec.rb | 153 ++++++++++++++++++++++++ 1 file changed, 153 insertions(+) diff --git a/spec/features/merge_requests/diff_notes_spec.rb b/spec/features/merge_requests/diff_notes_spec.rb index b8f82d06e19..f5bc0543661 100644 --- a/spec/features/merge_requests/diff_notes_spec.rb +++ b/spec/features/merge_requests/diff_notes_spec.rb @@ -17,6 +17,7 @@ feature 'Diff notes', js: true, feature: true do context 'when hovering over the parallel view diff file' do before(:each) do +<<<<<<< 7d654c0e1810f2023a1deaeddd542c5c92d20f42 visit diffs_namespace_project_merge_request_path(@project.namespace, @project, @merge_request, view: 'parallel') end @@ -27,51 +28,111 @@ feature 'Diff notes', js: true, feature: true do it 'should not allow commenting on the right side' do should_not_allow_commenting(find('[id="6eb14e00385d2fb284765eb1cd8d420d33d63fc9_23_22"]').find(:xpath, '..'), 'right') +======= + visit diffs_namespace_project_merge_request_path(@project.namespace, @project, @merge_request) + click_link 'Side-by-side' + end + + context 'with an old line on the left and no line on the right' do + let(:line_holder) { find('[id="6eb14e00385d2fb284765eb1cd8d420d33d63fc9_23_22"]').find(:xpath, '..') } + + it 'should allow commenting on the left side' do + should_allow_commenting line_holder, 'left' + end + + it 'should not allow commenting on the right side' do + should_not_allow_commenting line_holder, 'right' +>>>>>>> Added 'with an unfolded line should not allow commenting' scenario (line 125) end end context 'with no line on the left and a new line on the right' do +<<<<<<< 7d654c0e1810f2023a1deaeddd542c5c92d20f42 it 'should not allow commenting on the left side' do should_not_allow_commenting(find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_15"]').find(:xpath, '..'), 'left') end it 'should allow commenting on the right side' do should_allow_commenting(find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_15"]').find(:xpath, '..'), 'right') +======= + let(:line_holder) { find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_15"]').find(:xpath, '..') } + + it 'should not allow commenting on the left side' do + should_not_allow_commenting line_holder, 'left' + end + + it 'should allow commenting on the right side' do + should_allow_commenting line_holder, 'right' +>>>>>>> Added 'with an unfolded line should not allow commenting' scenario (line 125) end end context 'with an old line on the left and a new line on the right' do +<<<<<<< 7d654c0e1810f2023a1deaeddd542c5c92d20f42 it 'should allow commenting on the left side' do should_allow_commenting(find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_9_9"]').find(:xpath, '..'), 'left') end it 'should allow commenting on the right side' do should_allow_commenting(find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_9_9"]').find(:xpath, '..'), 'right') +======= + let(:line_holder) { find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_9_9"]').find(:xpath, '..') } + + it 'should allow commenting on the left side' do + should_allow_commenting line_holder, 'left' + end + + it 'should allow commenting on the right side' do + should_allow_commenting line_holder, 'right' +>>>>>>> Added 'with an unfolded line should not allow commenting' scenario (line 125) end end context 'with an unchanged line on the left and an unchanged line on the right' do +<<<<<<< 7d654c0e1810f2023a1deaeddd542c5c92d20f42 it 'should allow commenting on the left side' do should_allow_commenting(find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_7_7"]', match: :first).find(:xpath, '..'), 'left') end it 'should allow commenting on the right side' do should_allow_commenting(find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_7_7"]', match: :first).find(:xpath, '..'), 'right') +======= + let(:line_holder) { first('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_7_7"]').find(:xpath, '..') } + + it 'should allow commenting on the left side' do + should_allow_commenting line_holder, 'left' + end + + it 'should allow commenting on the right side' do + should_allow_commenting line_holder, 'right' +>>>>>>> Added 'with an unfolded line should not allow commenting' scenario (line 125) end end context 'with a match line' do +<<<<<<< 7d654c0e1810f2023a1deaeddd542c5c92d20f42 it 'should not allow commenting on the left side' do should_not_allow_commenting(find('.match', match: :first).find(:xpath, '..'), 'left') end it 'should not allow commenting on the right side' do should_not_allow_commenting(find('.match', match: :first).find(:xpath, '..'), 'right') +======= + let(:line_holder) { first('.match').find(:xpath, '..') } + + it 'should not allow commenting on the left side' do + should_not_allow_commenting line_holder, 'left' + end + + it 'should not allow commenting on the right side' do + should_not_allow_commenting line_holder, 'right' +>>>>>>> Added 'with an unfolded line should not allow commenting' scenario (line 125) end end end context 'when hovering over the inline view diff file' do +<<<<<<< 7d654c0e1810f2023a1deaeddd542c5c92d20f42 before do visit diffs_namespace_project_merge_request_path(@project.namespace, @project, @merge_request, view: 'inline') end @@ -79,29 +140,80 @@ feature 'Diff notes', js: true, feature: true do context 'with a new line' do it 'should allow commenting' do should_allow_commenting(find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_10_9"]')) +======= + let(:comment_button_class) { '.add-diff-note' } + + before(:each) do + visit diffs_namespace_project_merge_request_path(@project.namespace, @project, @merge_request) + click_link 'Inline' + end + + context 'with a new line' do + let(:line_holder) { find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_10_9"]') } + + it 'should allow commenting' do + should_allow_commenting line_holder +>>>>>>> Added 'with an unfolded line should not allow commenting' scenario (line 125) end end context 'with an old line' do +<<<<<<< 7d654c0e1810f2023a1deaeddd542c5c92d20f42 it 'should allow commenting' do should_allow_commenting(find('[id="6eb14e00385d2fb284765eb1cd8d420d33d63fc9_22_22"]')) +======= + let(:line_holder) { find('[id="6eb14e00385d2fb284765eb1cd8d420d33d63fc9_22_22"]') } + + it 'should allow commenting' do + should_allow_commenting line_holder +>>>>>>> Added 'with an unfolded line should not allow commenting' scenario (line 125) end end context 'with an unchanged line' do +<<<<<<< 7d654c0e1810f2023a1deaeddd542c5c92d20f42 it 'should allow commenting' do should_allow_commenting(find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_7_7"]')) +======= + let(:line_holder) { find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_7_7"]') } + + it 'should allow commenting' do + should_allow_commenting line_holder +>>>>>>> Added 'with an unfolded line should not allow commenting' scenario (line 125) end end context 'with a match line' do +<<<<<<< 7d654c0e1810f2023a1deaeddd542c5c92d20f42 it 'should not allow commenting' do should_not_allow_commenting(find('.match', match: :first)) +======= + let(:line_holder) { first('.match') } + + it 'should not allow commenting' do + should_not_allow_commenting line_holder + end + end + + context 'with an unfolded line' do + before(:each) do + first('.js-unfold').click + wait_for_ajax + end + + # The first `.js-unfold` unfolds upwards, therefore the first + # `.line_holder` will be an unfolded line. + let(:line_holder) { first('.line_holder[id="1"]') } + + it 'should not allow commenting' do + should_not_allow_commenting line_holder +>>>>>>> Added 'with an unfolded line should not allow commenting' scenario (line 125) end end end def should_allow_commenting(line_holder, diff_side = nil) +<<<<<<< 7d654c0e1810f2023a1deaeddd542c5c92d20f42 line = get_line_components(line_holder, diff_side) line[:content].hover expect(line[:num]).to have_css comment_button_class @@ -113,33 +225,61 @@ feature 'Diff notes', js: true, feature: true do def should_not_allow_commenting(line_holder, diff_side = nil) line = get_line_components(line_holder, diff_side) +======= + line = get_line_components line_holder, diff_side + line[:content].hover + expect(line[:num]).to have_css comment_button_class + + comment_on_line line_holder, line + wait_for_ajax + + assert_comment_persistence line_holder + end + + def should_not_allow_commenting(line_holder, diff_side = nil) + line = get_line_components line_holder, diff_side +>>>>>>> Added 'with an unfolded line should not allow commenting' scenario (line 125) line[:content].hover expect(line[:num]).not_to have_css comment_button_class end def get_line_components(line_holder, diff_side = nil) if diff_side.nil? +<<<<<<< 7d654c0e1810f2023a1deaeddd542c5c92d20f42 get_inline_line_components(line_holder) else get_parallel_line_components(line_holder, diff_side) +======= + get_inline_line_components line_holder + else + get_parallel_line_components line_holder, diff_side +>>>>>>> Added 'with an unfolded line should not allow commenting' scenario (line 125) end end def get_inline_line_components(line_holder) +<<<<<<< 7d654c0e1810f2023a1deaeddd542c5c92d20f42 { content: line_holder.find('.line_content', match: :first), num: line_holder.find('.diff-line-num', match: :first) } +======= + { content: line_holder.first('.line_content'), num: line_holder.first('.diff-line-num') } +>>>>>>> Added 'with an unfolded line should not allow commenting' scenario (line 125) end def get_parallel_line_components(line_holder, diff_side = nil) side_index = diff_side == 'left' ? 0 : 1 +<<<<<<< 7d654c0e1810f2023a1deaeddd542c5c92d20f42 # Wait for `.line_content` line_holder.find('.line_content', match: :first) # Wait for `.diff-line-num` line_holder.find('.diff-line-num', match: :first) +======= +>>>>>>> Added 'with an unfolded line should not allow commenting' scenario (line 125) { content: line_holder.all('.line_content')[side_index], num: line_holder.all('.diff-line-num')[side_index] } end def comment_on_line(line_holder, line) line[:num].find(comment_button_class).trigger 'click' +<<<<<<< 7d654c0e1810f2023a1deaeddd542c5c92d20f42 line_holder.find(:xpath, notes_holder_input_xpath) notes_holder_input = line_holder.find(:xpath, notes_holder_input_xpath) @@ -148,13 +288,26 @@ feature 'Diff notes', js: true, feature: true do notes_holder_input.fill_in 'note[note]', with: test_note_comment click_button 'Comment' wait_for_ajax +======= + expect(line_holder).to have_xpath notes_holder_input_xpath + + notes_holder_input = line_holder.find(:xpath, notes_holder_input_xpath) + expect(notes_holder_input[:class].include? notes_holder_input_class).to be true + + notes_holder_input.fill_in 'note[note]', with: test_note_comment + click_button 'Comment' +>>>>>>> Added 'with an unfolded line should not allow commenting' scenario (line 125) end def assert_comment_persistence(line_holder) expect(line_holder).to have_xpath notes_holder_input_xpath notes_holder_saved = line_holder.find(:xpath, notes_holder_input_xpath) +<<<<<<< 7d654c0e1810f2023a1deaeddd542c5c92d20f42 expect(notes_holder_saved[:class]).not_to include(notes_holder_input_class) +======= + expect(notes_holder_saved[:class].include? notes_holder_input_class).to be false +>>>>>>> Added 'with an unfolded line should not allow commenting' scenario (line 125) expect(notes_holder_saved).to have_content test_note_comment end end -- cgit v1.2.1 From ed94b9b4c755c863bb90914c72cf20318fefe58a Mon Sep 17 00:00:00 2001 From: Luke Bennett Date: Mon, 22 Aug 2016 14:21:18 +0100 Subject: Updated to optimized specs from !5864 --- spec/features/merge_requests/diff_notes_spec.rb | 138 ------------------------ 1 file changed, 138 deletions(-) diff --git a/spec/features/merge_requests/diff_notes_spec.rb b/spec/features/merge_requests/diff_notes_spec.rb index f5bc0543661..482c280c188 100644 --- a/spec/features/merge_requests/diff_notes_spec.rb +++ b/spec/features/merge_requests/diff_notes_spec.rb @@ -17,7 +17,6 @@ feature 'Diff notes', js: true, feature: true do context 'when hovering over the parallel view diff file' do before(:each) do -<<<<<<< 7d654c0e1810f2023a1deaeddd542c5c92d20f42 visit diffs_namespace_project_merge_request_path(@project.namespace, @project, @merge_request, view: 'parallel') end @@ -28,111 +27,51 @@ feature 'Diff notes', js: true, feature: true do it 'should not allow commenting on the right side' do should_not_allow_commenting(find('[id="6eb14e00385d2fb284765eb1cd8d420d33d63fc9_23_22"]').find(:xpath, '..'), 'right') -======= - visit diffs_namespace_project_merge_request_path(@project.namespace, @project, @merge_request) - click_link 'Side-by-side' - end - - context 'with an old line on the left and no line on the right' do - let(:line_holder) { find('[id="6eb14e00385d2fb284765eb1cd8d420d33d63fc9_23_22"]').find(:xpath, '..') } - - it 'should allow commenting on the left side' do - should_allow_commenting line_holder, 'left' - end - - it 'should not allow commenting on the right side' do - should_not_allow_commenting line_holder, 'right' ->>>>>>> Added 'with an unfolded line should not allow commenting' scenario (line 125) end end context 'with no line on the left and a new line on the right' do -<<<<<<< 7d654c0e1810f2023a1deaeddd542c5c92d20f42 it 'should not allow commenting on the left side' do should_not_allow_commenting(find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_15"]').find(:xpath, '..'), 'left') end it 'should allow commenting on the right side' do should_allow_commenting(find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_15"]').find(:xpath, '..'), 'right') -======= - let(:line_holder) { find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_15"]').find(:xpath, '..') } - - it 'should not allow commenting on the left side' do - should_not_allow_commenting line_holder, 'left' - end - - it 'should allow commenting on the right side' do - should_allow_commenting line_holder, 'right' ->>>>>>> Added 'with an unfolded line should not allow commenting' scenario (line 125) end end context 'with an old line on the left and a new line on the right' do -<<<<<<< 7d654c0e1810f2023a1deaeddd542c5c92d20f42 it 'should allow commenting on the left side' do should_allow_commenting(find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_9_9"]').find(:xpath, '..'), 'left') end it 'should allow commenting on the right side' do should_allow_commenting(find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_9_9"]').find(:xpath, '..'), 'right') -======= - let(:line_holder) { find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_9_9"]').find(:xpath, '..') } - - it 'should allow commenting on the left side' do - should_allow_commenting line_holder, 'left' - end - - it 'should allow commenting on the right side' do - should_allow_commenting line_holder, 'right' ->>>>>>> Added 'with an unfolded line should not allow commenting' scenario (line 125) end end context 'with an unchanged line on the left and an unchanged line on the right' do -<<<<<<< 7d654c0e1810f2023a1deaeddd542c5c92d20f42 it 'should allow commenting on the left side' do should_allow_commenting(find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_7_7"]', match: :first).find(:xpath, '..'), 'left') end it 'should allow commenting on the right side' do should_allow_commenting(find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_7_7"]', match: :first).find(:xpath, '..'), 'right') -======= - let(:line_holder) { first('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_7_7"]').find(:xpath, '..') } - - it 'should allow commenting on the left side' do - should_allow_commenting line_holder, 'left' - end - - it 'should allow commenting on the right side' do - should_allow_commenting line_holder, 'right' ->>>>>>> Added 'with an unfolded line should not allow commenting' scenario (line 125) end end context 'with a match line' do -<<<<<<< 7d654c0e1810f2023a1deaeddd542c5c92d20f42 it 'should not allow commenting on the left side' do should_not_allow_commenting(find('.match', match: :first).find(:xpath, '..'), 'left') end it 'should not allow commenting on the right side' do should_not_allow_commenting(find('.match', match: :first).find(:xpath, '..'), 'right') -======= - let(:line_holder) { first('.match').find(:xpath, '..') } - - it 'should not allow commenting on the left side' do - should_not_allow_commenting line_holder, 'left' - end - - it 'should not allow commenting on the right side' do - should_not_allow_commenting line_holder, 'right' ->>>>>>> Added 'with an unfolded line should not allow commenting' scenario (line 125) end end end context 'when hovering over the inline view diff file' do -<<<<<<< 7d654c0e1810f2023a1deaeddd542c5c92d20f42 before do visit diffs_namespace_project_merge_request_path(@project.namespace, @project, @merge_request, view: 'inline') end @@ -140,58 +79,24 @@ feature 'Diff notes', js: true, feature: true do context 'with a new line' do it 'should allow commenting' do should_allow_commenting(find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_10_9"]')) -======= - let(:comment_button_class) { '.add-diff-note' } - - before(:each) do - visit diffs_namespace_project_merge_request_path(@project.namespace, @project, @merge_request) - click_link 'Inline' - end - - context 'with a new line' do - let(:line_holder) { find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_10_9"]') } - - it 'should allow commenting' do - should_allow_commenting line_holder ->>>>>>> Added 'with an unfolded line should not allow commenting' scenario (line 125) end end context 'with an old line' do -<<<<<<< 7d654c0e1810f2023a1deaeddd542c5c92d20f42 it 'should allow commenting' do should_allow_commenting(find('[id="6eb14e00385d2fb284765eb1cd8d420d33d63fc9_22_22"]')) -======= - let(:line_holder) { find('[id="6eb14e00385d2fb284765eb1cd8d420d33d63fc9_22_22"]') } - - it 'should allow commenting' do - should_allow_commenting line_holder ->>>>>>> Added 'with an unfolded line should not allow commenting' scenario (line 125) end end context 'with an unchanged line' do -<<<<<<< 7d654c0e1810f2023a1deaeddd542c5c92d20f42 it 'should allow commenting' do should_allow_commenting(find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_7_7"]')) -======= - let(:line_holder) { find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_7_7"]') } - - it 'should allow commenting' do - should_allow_commenting line_holder ->>>>>>> Added 'with an unfolded line should not allow commenting' scenario (line 125) end end context 'with a match line' do -<<<<<<< 7d654c0e1810f2023a1deaeddd542c5c92d20f42 it 'should not allow commenting' do should_not_allow_commenting(find('.match', match: :first)) -======= - let(:line_holder) { first('.match') } - - it 'should not allow commenting' do - should_not_allow_commenting line_holder end end @@ -207,13 +112,11 @@ feature 'Diff notes', js: true, feature: true do it 'should not allow commenting' do should_not_allow_commenting line_holder ->>>>>>> Added 'with an unfolded line should not allow commenting' scenario (line 125) end end end def should_allow_commenting(line_holder, diff_side = nil) -<<<<<<< 7d654c0e1810f2023a1deaeddd542c5c92d20f42 line = get_line_components(line_holder, diff_side) line[:content].hover expect(line[:num]).to have_css comment_button_class @@ -225,61 +128,33 @@ feature 'Diff notes', js: true, feature: true do def should_not_allow_commenting(line_holder, diff_side = nil) line = get_line_components(line_holder, diff_side) -======= - line = get_line_components line_holder, diff_side - line[:content].hover - expect(line[:num]).to have_css comment_button_class - - comment_on_line line_holder, line - wait_for_ajax - - assert_comment_persistence line_holder - end - - def should_not_allow_commenting(line_holder, diff_side = nil) - line = get_line_components line_holder, diff_side ->>>>>>> Added 'with an unfolded line should not allow commenting' scenario (line 125) line[:content].hover expect(line[:num]).not_to have_css comment_button_class end def get_line_components(line_holder, diff_side = nil) if diff_side.nil? -<<<<<<< 7d654c0e1810f2023a1deaeddd542c5c92d20f42 get_inline_line_components(line_holder) else get_parallel_line_components(line_holder, diff_side) -======= - get_inline_line_components line_holder - else - get_parallel_line_components line_holder, diff_side ->>>>>>> Added 'with an unfolded line should not allow commenting' scenario (line 125) end end def get_inline_line_components(line_holder) -<<<<<<< 7d654c0e1810f2023a1deaeddd542c5c92d20f42 { content: line_holder.find('.line_content', match: :first), num: line_holder.find('.diff-line-num', match: :first) } -======= - { content: line_holder.first('.line_content'), num: line_holder.first('.diff-line-num') } ->>>>>>> Added 'with an unfolded line should not allow commenting' scenario (line 125) end def get_parallel_line_components(line_holder, diff_side = nil) side_index = diff_side == 'left' ? 0 : 1 -<<<<<<< 7d654c0e1810f2023a1deaeddd542c5c92d20f42 # Wait for `.line_content` line_holder.find('.line_content', match: :first) # Wait for `.diff-line-num` line_holder.find('.diff-line-num', match: :first) -======= ->>>>>>> Added 'with an unfolded line should not allow commenting' scenario (line 125) { content: line_holder.all('.line_content')[side_index], num: line_holder.all('.diff-line-num')[side_index] } end def comment_on_line(line_holder, line) line[:num].find(comment_button_class).trigger 'click' -<<<<<<< 7d654c0e1810f2023a1deaeddd542c5c92d20f42 line_holder.find(:xpath, notes_holder_input_xpath) notes_holder_input = line_holder.find(:xpath, notes_holder_input_xpath) @@ -288,26 +163,13 @@ feature 'Diff notes', js: true, feature: true do notes_holder_input.fill_in 'note[note]', with: test_note_comment click_button 'Comment' wait_for_ajax -======= - expect(line_holder).to have_xpath notes_holder_input_xpath - - notes_holder_input = line_holder.find(:xpath, notes_holder_input_xpath) - expect(notes_holder_input[:class].include? notes_holder_input_class).to be true - - notes_holder_input.fill_in 'note[note]', with: test_note_comment - click_button 'Comment' ->>>>>>> Added 'with an unfolded line should not allow commenting' scenario (line 125) end def assert_comment_persistence(line_holder) expect(line_holder).to have_xpath notes_holder_input_xpath notes_holder_saved = line_holder.find(:xpath, notes_holder_input_xpath) -<<<<<<< 7d654c0e1810f2023a1deaeddd542c5c92d20f42 expect(notes_holder_saved[:class]).not_to include(notes_holder_input_class) -======= - expect(notes_holder_saved[:class].include? notes_holder_input_class).to be false ->>>>>>> Added 'with an unfolded line should not allow commenting' scenario (line 125) expect(notes_holder_saved).to have_content test_note_comment end end -- cgit v1.2.1 From 2473dade6ad4844c1f936bda3338bdc8a45fbdc0 Mon Sep 17 00:00:00 2001 From: Luke Bennett Date: Tue, 23 Aug 2016 18:00:15 +0100 Subject: Better first match on this MR also --- spec/features/merge_requests/diff_notes_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/merge_requests/diff_notes_spec.rb b/spec/features/merge_requests/diff_notes_spec.rb index 482c280c188..a371d89f7a5 100644 --- a/spec/features/merge_requests/diff_notes_spec.rb +++ b/spec/features/merge_requests/diff_notes_spec.rb @@ -102,7 +102,7 @@ feature 'Diff notes', js: true, feature: true do context 'with an unfolded line' do before(:each) do - first('.js-unfold').click + find('.js-unfold', match: :first).click wait_for_ajax end -- cgit v1.2.1 From a60c1fc4f8e315d82fddf157b5f4790ed8409d1e Mon Sep 17 00:00:00 2001 From: Luke Bennett Date: Tue, 23 Aug 2016 20:08:18 +0100 Subject: Added unfold test to parallel and added 'diff discussion' context --- app/assets/javascripts/files_comment_button.js | 2 +- spec/features/merge_requests/diff_notes_spec.rb | 35 +++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/files_comment_button.js b/app/assets/javascripts/files_comment_button.js index 817d38ea86e..3fb3b1a8b51 100644 --- a/app/assets/javascripts/files_comment_button.js +++ b/app/assets/javascripts/files_comment_button.js @@ -125,7 +125,7 @@ }; FilesCommentButton.prototype.validateLineContent = function(lineContentElement) { - return lineContentElement.attr('data-note-type') && lineContentElement.attr('data-note-type') !== ''; + return lineContentElement.attr('data-discussion-id') && lineContentElement.attr('data-discussion-id') !== ''; }; return FilesCommentButton; diff --git a/spec/features/merge_requests/diff_notes_spec.rb b/spec/features/merge_requests/diff_notes_spec.rb index a371d89f7a5..a818679a874 100644 --- a/spec/features/merge_requests/diff_notes_spec.rb +++ b/spec/features/merge_requests/diff_notes_spec.rb @@ -15,7 +15,7 @@ feature 'Diff notes', js: true, feature: true do let(:notes_holder_input_xpath) { './following-sibling::*[contains(concat(" ", @class, " "), " notes_holder ")]' } let(:test_note_comment) { 'this is a test note!' } - context 'when hovering over the parallel view diff file' do + context 'when hovering over a parallel view diff file' do before(:each) do visit diffs_namespace_project_merge_request_path(@project.namespace, @project, @merge_request, view: 'parallel') end @@ -69,9 +69,28 @@ feature 'Diff notes', js: true, feature: true do should_not_allow_commenting(find('.match', match: :first).find(:xpath, '..'), 'right') end end + + context 'with an unfolded line' do + before(:each) do + find('.js-unfold', match: :first).click + wait_for_ajax + end + + # The first `.js-unfold` unfolds upwards, therefore the first + # `.line_holder` will be an unfolded line. + let(:line_holder) { first('.line_holder[id="1"]') } + + it 'should not allow commenting on the left side' do + should_not_allow_commenting(line_holder, 'left') + end + + it 'should not allow commenting on the right side' do + should_not_allow_commenting(line_holder, 'right') + end + end end - context 'when hovering over the inline view diff file' do + context 'when hovering over an inline view diff file' do before do visit diffs_namespace_project_merge_request_path(@project.namespace, @project, @merge_request, view: 'inline') end @@ -114,6 +133,18 @@ feature 'Diff notes', js: true, feature: true do should_not_allow_commenting line_holder end end + + context 'when hovering over a diff discussion' do + before do + visit diffs_namespace_project_merge_request_path(@project.namespace, @project, @merge_request, view: 'inline') + should_allow_commenting(find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_7_7"]')) + visit namespace_project_merge_request_path(@project.namespace, @project, @merge_request) + end + + it 'should not allow commenting' do + should_not_allow_commenting(find('.line_holder', match: :first)) + end + end end def should_allow_commenting(line_holder, diff_side = nil) -- cgit v1.2.1 From 6692bca49d0c652eb50f5fcefb77f0afcce3588d Mon Sep 17 00:00:00 2001 From: Luke Bennett Date: Tue, 23 Aug 2016 21:48:42 +0100 Subject: Added CHANGELOG --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index 97bd6316b55..5fad4684e86 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ Please view this file on the master branch, on stable branches it's out of date. v 8.12.0 (unreleased) - Optimistic locking for Issues and Merge Requests (title and description overriding prevention) + - Added tests for diff notes v 8.11.0 - Use test coverage value from the latest successful pipeline in badge. !5862 -- cgit v1.2.1