summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Bennett <lukeeeebennettplus@gmail.com>2016-08-05 13:56:26 +0100
committerLuke Bennett <lukeeeebennettplus@gmail.com>2016-08-05 13:56:26 +0100
commit0013e59fef7fa21e1f24796ad5c97973bf04e0e3 (patch)
treef9068ae0184c7aeb322d9ee930ca071dc21af8b5
parentf9806bdef291113d6112769093020af3dcb1000c (diff)
downloadgitlab-ce-0013e59fef7fa21e1f24796ad5c97973bf04e0e3.tar.gz
Moved notes scenarios to 'diff_notes_spec.rb'
-rw-r--r--features/project/merge_requests.feature10
-rw-r--r--spec/features/merge_requests/diff_notes_spec.rb179
-rw-r--r--spec/features/merge_requests/diffs_spec.rb170
3 files changed, 179 insertions, 180 deletions
diff --git a/features/project/merge_requests.feature b/features/project/merge_requests.feature
index 21768c15c17..5c1a0099a58 100644
--- a/features/project/merge_requests.feature
+++ b/features/project/merge_requests.feature
@@ -107,16 +107,6 @@ Feature: Project Merge Requests
Then The list should be sorted by "Least popular"
@javascript
- Scenario: I comment on a merge request diff
- Given project "Shop" have "Bug NS-05" open merge request with diffs inside
- And I visit merge request page "Bug NS-05"
- And I click on the Changes tab
- And I leave a comment like "Line is wrong" on diff
- And I switch to the merge request's comments tab
- Then I should see a discussion has started on diff
- And I should see a badge of "1" next to the discussion link
-
- @javascript
Scenario: I see a new comment on merge request diff from another user in the discussion tab
Given project "Shop" have "Bug NS-05" open merge request with diffs inside
And I visit merge request page "Bug NS-05"
diff --git a/spec/features/merge_requests/diff_notes_spec.rb b/spec/features/merge_requests/diff_notes_spec.rb
new file mode 100644
index 00000000000..8b01601b004
--- /dev/null
+++ b/spec/features/merge_requests/diff_notes_spec.rb
@@ -0,0 +1,179 @@
+require 'spec_helper'
+
+feature 'Diff notes', js: true, feature: true do
+ include WaitForAjax
+
+ before do
+ login_as :admin
+ @merge_request = create(:merge_request)
+ @project = @merge_request.source_project
+ end
+
+ context 'merge request diffs' do
+ let(:comment_button_class) { '.add-diff-note' }
+ let(:notes_holder_input_class) { 'js-temp-notes-holder' }
+ 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
+ before(:each) do
+ 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'
+ end
+ end
+
+ context 'with no line on the left and a new line on the right' do
+ 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'
+ end
+ end
+
+ context 'with an old line on the left and a new line on the right' do
+ 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'
+ end
+ end
+
+ context 'with an unchanged line on the left and an unchanged line on the right' do
+ 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'
+ end
+ end
+
+ context 'with a match line' do
+ 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'
+ end
+ end
+ end
+
+ context 'when hovering over the inline view diff file' do
+ 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
+ end
+ end
+
+ context 'with an old line' do
+ let(:line_holder) { find('[id="6eb14e00385d2fb284765eb1cd8d420d33d63fc9_22_22"]') }
+
+ it 'should allow commenting' do
+ should_allow_commenting line_holder
+ end
+ end
+
+ context 'with an unchanged line' do
+ let(:line_holder) { find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_7_7"]') }
+
+ it 'should allow commenting' do
+ should_allow_commenting line_holder
+ end
+ end
+
+ context 'with a match line' do
+ let(:line_holder) { first('.match') }
+
+ it 'should not allow commenting' do
+ should_not_allow_commenting line_holder
+ end
+ end
+ end
+
+ def should_allow_commenting(line_holder, diff_side = nil)
+ 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
+ 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?
+ get_inline_line_components line_holder
+ else
+ get_parallel_line_components line_holder, diff_side
+ end
+ end
+
+ def get_inline_line_components(line_holder)
+ { content: line_holder.first('.line_content'), num: line_holder.first('.diff-line-num') }
+ end
+
+ def get_parallel_line_components(line_holder, diff_side = nil)
+ side_index = diff_side == 'left' ? 0 : 1
+ { 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'
+ 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'
+ 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)
+ expect(notes_holder_saved[:class].include? notes_holder_input_class).to be false
+ expect(notes_holder_saved).to have_content test_note_comment
+ end
+ end
+end
diff --git a/spec/features/merge_requests/diffs_spec.rb b/spec/features/merge_requests/diffs_spec.rb
index d93fc5e84ee..c9a0059645d 100644
--- a/spec/features/merge_requests/diffs_spec.rb
+++ b/spec/features/merge_requests/diffs_spec.rb
@@ -1,8 +1,6 @@
require 'spec_helper'
feature 'Diffs URL', js: true, feature: true do
- include WaitForAjax
-
before do
login_as :admin
@merge_request = create(:merge_request)
@@ -24,172 +22,4 @@ feature 'Diffs URL', js: true, feature: true do
expect(page).to have_css('.diffs.tab-pane.active')
end
end
-
- context 'diff notes' do
- let(:comment_button_class) { '.add-diff-note' }
- let(:notes_holder_input_class) { 'js-temp-notes-holder' }
- 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
- before(:each) do
- 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'
- end
- end
-
- context 'with no line on the left and a new line on the right' do
- 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'
- end
- end
-
- context 'with an old line on the left and a new line on the right' do
- 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'
- end
- end
-
- context 'with an unchanged line on the left and an unchanged line on the right' do
- 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'
- end
- end
-
- context 'with a match line' do
- 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'
- end
- end
- end
-
- context 'when hovering over the inline view diff file' do
- 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
- end
- end
-
- context 'with an old line' do
- let(:line_holder) { find('[id="6eb14e00385d2fb284765eb1cd8d420d33d63fc9_22_22"]') }
-
- it 'should allow commenting' do
- should_allow_commenting line_holder
- end
- end
-
- context 'with an unchanged line' do
- let(:line_holder) { find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_7_7"]') }
-
- it 'should allow commenting' do
- should_allow_commenting line_holder
- end
- end
-
- context 'with a match line' do
- let(:line_holder) { first('.match') }
-
- it 'should not allow commenting' do
- should_not_allow_commenting line_holder
- end
- end
- end
-
- def should_allow_commenting(line_holder, diff_side = nil)
- 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
- 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?
- get_inline_line_components line_holder
- else
- get_parallel_line_components line_holder, diff_side
- end
- end
-
- def get_inline_line_components(line_holder)
- { content: line_holder.first('.line_content'), num: line_holder.first('.diff-line-num') }
- end
-
- def get_parallel_line_components(line_holder, diff_side = nil)
- side_index = diff_side == 'left' ? 0 : 1
- { 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'
- 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'
- 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)
- expect(notes_holder_saved[:class].include? notes_holder_input_class).to be false
- expect(notes_holder_saved).to have_content test_note_comment
- end
- end
end