notes_on_merge_requests_spec.rb 7.92 KB
Newer Older
1 2
require 'spec_helper'

3
describe 'Comments', feature: true do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
4
  include RepoHelpers
5
  include WaitForAjax
6

7 8 9 10 11 12 13 14 15 16 17 18 19 20
  describe 'On merge requests page', feature: true do
    it 'excludes award_emoji from comment count' do
      merge_request = create(:merge_request)
      project = merge_request.source_project
      create(:upvote_note, noteable: merge_request, project: project)

      login_as :admin
      visit namespace_project_merge_requests_path(project.namespace, project)

      expect(merge_request.mr_and_commit_notes.count).to eq 1
      expect(page.all('.merge-request-no-comments').first.text).to eq "0"
    end
  end

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
21
  describe 'On a merge request', js: true, feature: true do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
22 23
    let!(:merge_request) { create(:merge_request) }
    let!(:project) { merge_request.source_project }
Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
24 25 26
    let!(:note) do
      create(:note_on_merge_request, :with_attachment, project: project)
    end
27

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
28 29
    before do
      login_as :admin
Vinnie Okada's avatar
Vinnie Okada committed
30
      visit namespace_project_merge_request_path(project.namespace, project, merge_request)
31 32
    end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
33
    subject { page }
34

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
35
    describe 'the note form' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
36
      it 'should be valid' do
Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
37 38
        is_expected.to have_css('.js-main-target-form', visible: true, count: 1)
        expect(find('.js-main-target-form input[type=submit]').value).
39
          to eq('Comment')
40
        page.within('.js-main-target-form') do
41 42
          expect(page).not_to have_link('Cancel')
        end
43
      end
44

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
45
      describe 'with text' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
46
        before do
47
          page.within('.js-main-target-form') do
Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
48
            fill_in 'note[note]', with: 'This is awesome'
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
49 50 51 52
          end
        end

        it 'should have enable submit button and preview button' do
53
          page.within('.js-main-target-form') do
Vinnie Okada's avatar
Vinnie Okada committed
54
            expect(page).not_to have_css('.js-comment-button[disabled]')
Vinnie Okada's avatar
Vinnie Okada committed
55
            expect(page).to have_css('.js-md-preview-button', visible: true)
56
          end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
57
        end
58 59 60
      end
    end

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
61
    describe 'when posting a note' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
62
      before do
63
        page.within('.js-main-target-form') do
Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
64
          fill_in 'note[note]', with: 'This is awsome!'
65
          find('.js-md-preview-button').click
66
          click_button 'Comment'
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
67 68
        end
      end
Jack Weeden's avatar
Jack Weeden committed
69

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
70
      it 'should be added and form reset' do
Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
71
        is_expected.to have_content('This is awsome!')
72
        page.within('.js-main-target-form') do
Vinnie Okada's avatar
Vinnie Okada committed
73
          expect(page).to have_no_field('note[note]', with: 'This is awesome!')
Vinnie Okada's avatar
Vinnie Okada committed
74
          expect(page).to have_css('.js-md-preview', visible: :hidden)
75
        end
76
        page.within('.js-main-target-form') do
Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
77 78
          is_expected.to have_css('.js-note-text', visible: true)
        end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
79
      end
Jack Weeden's avatar
Jack Weeden committed
80 81
    end

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
82
    describe 'when editing a note', js: true do
83 84 85 86 87 88
      it 'should contain the hidden edit form' do
        page.within("#note_#{note.id}") do
          is_expected.to have_css('.note-edit-form', visible: false)
        end
      end

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
89
      describe 'editing the note' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
90 91 92
        before do
          find('.note').hover
          find(".js-note-edit").click
Jack Weeden's avatar
Jack Weeden committed
93 94
        end

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
95
        it 'should show the note edit form and hide the note body' do
96
          page.within("#note_#{note.id}") do
Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
97 98
            expect(find('.current-note-edit-form', visible: true)).to be_visible
            expect(find('.note-edit-form', visible: true)).to be_visible
99
            expect(find(:css, '.note-body > .note-text', visible: false)).not_to be_visible
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
100
          end
Jack Weeden's avatar
Jack Weeden committed
101 102
        end

103
        # TODO: fix after 7.7 release
104 105 106 107 108 109 110
        # it "should reset the edit note form textarea with the original content of the note if cancelled" do
        #   within(".current-note-edit-form") do
        #     fill_in "note[note]", with: "Some new content"
        #     find(".btn-cancel").click
        #     expect(find(".js-note-text", visible: false).text).to eq note.note
        #   end
        # end
Jack Weeden's avatar
Jack Weeden committed
111

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
112
        it 'appends the edited at time to the note' do
113
          page.within('.current-note-edit-form') do
Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
114 115
            fill_in 'note[note]', with: 'Some new content'
            find('.btn-save').click
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
116 117
          end

118
          page.within("#note_#{note.id}") do
Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
119 120 121
            is_expected.to have_css('.note_edited_ago')
            expect(find('.note_edited_ago').text).
              to match(/less than a minute ago/)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
122
          end
Jack Weeden's avatar
Jack Weeden committed
123 124 125
        end
      end

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
126
      describe 'deleting an attachment' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
127 128
        before do
          find('.note').hover
Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
129
          find('.js-note-edit').click
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
130
        end
Jack Weeden's avatar
Jack Weeden committed
131

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
132
        it 'shows the delete link' do
133
          page.within('.note-attachment') do
Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
134
            is_expected.to have_css('.js-note-attachment-delete')
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
135
          end
Jack Weeden's avatar
Jack Weeden committed
136 137
        end

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
138 139 140
        it 'removes the attachment div and resets the edit form' do
          find('.js-note-attachment-delete').click
          is_expected.not_to have_css('.note-attachment')
141 142
          is_expected.not_to have_css('.current-note-edit-form')
          wait_for_ajax
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
143
        end
Jack Weeden's avatar
Jack Weeden committed
144 145
      end
    end
146 147 148 149 150 151 152 153 154 155 156

    describe 'comment info' do
      it 'excludes award_emoji from comment count' do
        create(:upvote_note, noteable: merge_request, project: project)

        visit namespace_project_merge_request_path(project.namespace, project, merge_request)

        expect(merge_request.mr_and_commit_notes.count).to eq 2
        expect(find('.notes-tab span.badge').text).to eq "1"
      end
    end
Jack Weeden's avatar
Jack Weeden committed
157
  end
158

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
159
  describe 'On a merge request diff', js: true, feature: true do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
160 161
    let(:merge_request) { create(:merge_request) }
    let(:project) { merge_request.source_project }
162 163

    before do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
164
      login_as :admin
Vinnie Okada's avatar
Vinnie Okada committed
165
      visit diffs_namespace_project_merge_request_path(project.namespace, project, merge_request)
166 167
    end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
168
    subject { page }
169

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
170
    describe 'when adding a note' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
171
      before do
172
        click_diff_line
173 174
      end

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
175 176
      describe 'the notes holder' do
        it { is_expected.to have_css('.js-temp-notes-holder') }
177

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
178
        it 'has .new_note css class' do
179
          page.within('.js-temp-notes-holder') do
Phil Hughes's avatar
Phil Hughes committed
180
            expect(subject).to have_css('.new-note')
Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
181 182
          end
        end
183 184
      end

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
185
      describe 'the note form' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
186
        it "shouldn't add a second form for same row" do
187
          click_diff_line
188

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
189 190 191
          is_expected.
            to have_css("tr[id='#{line_code}'] + .js-temp-notes-holder form",
                        count: 1)
192
        end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
193

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
194
        it 'should be removed when canceled' do
Rémy Coutable's avatar
Rémy Coutable committed
195
          page.within(".diff-file form[id$='#{line_code}']") do
Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
196
            find('.js-close-discussion-note-form').trigger('click')
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
197 198
          end

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
199
          is_expected.to have_no_css('.js-temp-notes-holder')
200 201 202 203
        end
      end
    end

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
204
    describe 'with muliple note forms' do
205
      before do
206 207
        click_diff_line
        click_diff_line(line_code_2)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
208 209
      end

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
210
      it { is_expected.to have_css('.js-temp-notes-holder', count: 2) }
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
211

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
212
      describe 'previewing them separately' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
213 214
        before do
          # add two separate texts and trigger previews on both
215
          page.within("tr[id='#{line_code}'] + .js-temp-notes-holder") do
Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
216
            fill_in 'note[note]', with: 'One comment on line 7'
217
            find('.js-md-preview-button').click
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
218
          end
219
          page.within("tr[id='#{line_code_2}'] + .js-temp-notes-holder") do
Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
220
            fill_in 'note[note]', with: 'Another comment on line 10'
221
            find('.js-md-preview-button').click
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
222
          end
223 224 225
        end
      end

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
226
      describe 'posting a note' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
227
        before do
228
          page.within("tr[id='#{line_code_2}'] + .js-temp-notes-holder") do
Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
229
            fill_in 'note[note]', with: 'Another comment on line 10'
230
            click_button('Comment')
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
231 232 233 234
          end
        end

        it 'should be added as discussion' do
Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
235 236 237
          is_expected.to have_content('Another comment on line 10')
          is_expected.to have_css('.notes_holder')
          is_expected.to have_css('.notes_holder .note', count: 1)
Annabel Dunstone's avatar
Annabel Dunstone committed
238
          is_expected.to have_button('Reply...')
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
239
        end
240
      end
241 242
    end
  end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
243 244 245 246 247 248 249 250

  def line_code
    sample_compare.changes.first[:line_code]
  end

  def line_code_2
    sample_compare.changes.last[:line_code]
  end
251

252
  def click_diff_line(data = line_code)
Phil Hughes's avatar
Phil Hughes committed
253
    execute_script("$('button[data-line-code=\"#{data}\"]').click()")
254
  end
255
end