diff_notes_avatars_spec.rb 5.48 KB
Newer Older
1 2
require 'spec_helper'

3
feature 'Diff note avatars', js: true do
4 5
  include NoteInteractionHelpers

6
  let(:user)          { create(:user) }
7
  let(:project)       { create(:project, :public, :repository) }
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
  let(:merge_request) { create(:merge_request_with_diffs, source_project: project, author: user, title: "Bug NS-04") }
  let(:path)          { "files/ruby/popen.rb" }
  let(:position) do
    Gitlab::Diff::Position.new(
      old_path: path,
      new_path: path,
      old_line: nil,
      new_line: 9,
      diff_refs: merge_request.diff_refs
    )
  end
  let!(:note) { create(:diff_note_on_merge_request, project: project, noteable: merge_request, position: position) }

  before do
    project.team << [user, :master]
23
    sign_in user
24 25
  end

Phil Hughes's avatar
Phil Hughes committed
26 27
  context 'discussion tab' do
    before do
28
      visit project_merge_request_path(project, merge_request)
Phil Hughes's avatar
Phil Hughes committed
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
    end

    it 'does not show avatars on discussion tab' do
      expect(page).not_to have_selector('.js-avatar-container')
      expect(page).not_to have_selector('.diff-comment-avatar-holders')
    end

    it 'does not render avatars after commening on discussion tab' do
      click_button 'Reply...'

      page.within('.js-discussion-note-form') do
        find('.note-textarea').native.send_keys('Test comment')

        click_button 'Comment'
      end

      expect(page).to have_content('Test comment')
      expect(page).not_to have_selector('.js-avatar-container')
      expect(page).not_to have_selector('.diff-comment-avatar-holders')
    end
  end

  context 'commit view' do
    before do
53
      visit project_commit_path(project, merge_request.commits.first.id)
Phil Hughes's avatar
Phil Hughes committed
54 55 56 57 58 59 60 61 62 63 64
    end

    it 'does not render avatar after commenting' do
      first('.diff-line-num').trigger('mouseover')
      find('.js-add-diff-note-button').click

      page.within('.js-discussion-note-form') do
        find('.note-textarea').native.send_keys('test comment')

        click_button 'Comment'

65
        wait_for_requests
Phil Hughes's avatar
Phil Hughes committed
66 67
      end

68
      visit project_merge_request_path(project, merge_request)
Phil Hughes's avatar
Phil Hughes committed
69 70 71 72 73 74 75

      expect(page).to have_content('test comment')
      expect(page).not_to have_selector('.js-avatar-container')
      expect(page).not_to have_selector('.diff-comment-avatar-holders')
    end
  end

76 77 78
  %w(inline parallel).each do |view|
    context "#{view} view" do
      before do
79
        visit diffs_project_merge_request_path(project, merge_request, view: view)
80

81
        wait_for_requests
82 83 84 85 86 87 88 89 90 91 92 93 94 95
      end

      it 'shows note avatar' do
        page.within find("[id='#{position.line_code(project.repository)}']") do
          find('.diff-notes-collapse').click

          expect(page).to have_selector('img.js-diff-comment-avatar', count: 1)
        end
      end

      it 'shows comment on note avatar' do
        page.within find("[id='#{position.line_code(project.repository)}']") do
          find('.diff-notes-collapse').click

96
          expect(first('img.js-diff-comment-avatar')["data-original-title"]).to eq("#{note.author.name}: #{note.note.truncate(17)}")
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
        end
      end

      it 'toggles comments when clicking avatar' do
        page.within find("[id='#{position.line_code(project.repository)}']") do
          find('.diff-notes-collapse').click
        end

        expect(page).to have_selector('.notes_holder', visible: false)

        page.within find("[id='#{position.line_code(project.repository)}']") do
          first('img.js-diff-comment-avatar').click
        end

        expect(page).to have_selector('.notes_holder')
      end

      it 'removes avatar when note is deleted' do
115 116
        open_more_actions_dropdown(note)

117 118 119 120
        page.within find(".note-row-#{note.id}") do
          find('.js-note-delete').click
        end

121
        wait_for_requests
122 123 124 125 126 127 128 129 130 131 132 133 134 135

        page.within find("[id='#{position.line_code(project.repository)}']") do
          expect(page).not_to have_selector('img.js-diff-comment-avatar')
        end
      end

      it 'adds avatar when commenting' do
        click_button 'Reply...'

        page.within '.js-discussion-note-form' do
          find('.js-note-text').native.send_keys('Test')

          click_button 'Comment'

136
          wait_for_requests
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
        end

        page.within find("[id='#{position.line_code(project.repository)}']") do
          find('.diff-notes-collapse').click

          expect(page).to have_selector('img.js-diff-comment-avatar', count: 2)
        end
      end

      it 'adds multiple comments' do
        3.times do
          click_button 'Reply...'

          page.within '.js-discussion-note-form' do
            find('.js-note-text').native.send_keys('Test')

            find('.js-comment-button').trigger 'click'

155
            wait_for_requests
156 157 158 159 160 161 162 163 164 165 166 167
          end
        end

        page.within find("[id='#{position.line_code(project.repository)}']") do
          find('.diff-notes-collapse').click

          expect(page).to have_selector('img.js-diff-comment-avatar', count: 3)
          expect(find('.diff-comments-more-count')).to have_content '+1'
        end
      end

      context 'multiple comments' do
Douwe Maan's avatar
Douwe Maan committed
168
        before do
Douwe Maan's avatar
Douwe Maan committed
169 170
          create_list(:diff_note_on_merge_request, 3, project: project, noteable: merge_request, in_reply_to: note)

171
          visit diffs_project_merge_request_path(project, merge_request, view: view)
172

173
          wait_for_requests
174 175 176 177 178 179 180 181 182 183 184 185 186
        end

        it 'shows extra comment count' do
          page.within find("[id='#{position.line_code(project.repository)}']") do
            find('.diff-notes-collapse').click

            expect(find('.diff-comments-more-count')).to have_content '+1'
          end
        end
      end
    end
  end
end