notes_on_merge_requests_spec.rb 7.02 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

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
7
  describe 'On a merge request', js: true, feature: true do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
8 9
    let!(:merge_request) { create(:merge_request) }
    let!(:project) { merge_request.source_project }
Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
10 11 12
    let!(:note) do
      create(:note_on_merge_request, :with_attachment, project: project)
    end
13

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
14 15
    before do
      login_as :admin
Vinnie Okada's avatar
Vinnie Okada committed
16
      visit namespace_project_merge_request_path(project.namespace, project, merge_request)
17 18
    end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
19
    subject { page }
20

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
21
    describe 'the note form' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
22
      it 'should be valid' do
Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
23 24
        is_expected.to have_css('.js-main-target-form', visible: true, count: 1)
        expect(find('.js-main-target-form input[type=submit]').value).
25
          to eq('Comment')
26
        page.within('.js-main-target-form') do
27 28
          expect(page).not_to have_link('Cancel')
        end
29
      end
30

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
31
      describe 'with text' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
32
        before do
33
          page.within('.js-main-target-form') do
Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
34
            fill_in 'note[note]', with: 'This is awesome'
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
35 36 37 38
          end
        end

        it 'should have enable submit button and preview button' do
39
          page.within('.js-main-target-form') do
Vinnie Okada's avatar
Vinnie Okada committed
40
            expect(page).not_to have_css('.js-comment-button[disabled]')
Vinnie Okada's avatar
Vinnie Okada committed
41
            expect(page).to have_css('.js-md-preview-button', visible: true)
42
          end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
43
        end
44 45 46
      end
    end

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
47
    describe 'when posting a note' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
48
      before do
49
        page.within('.js-main-target-form') do
Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
50
          fill_in 'note[note]', with: 'This is awsome!'
51
          find('.js-md-preview-button').click
52
          click_button 'Comment'
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
53 54
        end
      end
Jack Weeden's avatar
Jack Weeden committed
55

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
56
      it 'should be added and form reset' do
Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
57
        is_expected.to have_content('This is awsome!')
58
        page.within('.js-main-target-form') do
Vinnie Okada's avatar
Vinnie Okada committed
59
          expect(page).to have_no_field('note[note]', with: 'This is awesome!')
Vinnie Okada's avatar
Vinnie Okada committed
60
          expect(page).to have_css('.js-md-preview', visible: :hidden)
61
        end
62
        page.within('.js-main-target-form') do
Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
63 64
          is_expected.to have_css('.js-note-text', visible: true)
        end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
65
      end
Jack Weeden's avatar
Jack Weeden committed
66 67
    end

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
68
    describe 'when editing a note', js: true do
69 70 71 72 73 74
      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
75
      describe 'editing the note' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
76 77 78
        before do
          find('.note').hover
          find(".js-note-edit").click
Jack Weeden's avatar
Jack Weeden committed
79 80
        end

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
81
        it 'should show the note edit form and hide the note body' do
82
          page.within("#note_#{note.id}") do
Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
83 84
            expect(find('.current-note-edit-form', visible: true)).to be_visible
            expect(find('.note-edit-form', visible: true)).to be_visible
85
            expect(find(:css, '.note-body > .note-text', visible: false)).not_to be_visible
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
86
          end
Jack Weeden's avatar
Jack Weeden committed
87 88
        end

89
        # TODO: fix after 7.7 release
90 91 92 93 94 95 96
        # 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
97

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
98
        it 'appends the edited at time to the note' do
99
          page.within('.current-note-edit-form') do
Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
100 101
            fill_in 'note[note]', with: 'Some new content'
            find('.btn-save').click
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
102 103
          end

104
          page.within("#note_#{note.id}") do
Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
105 106 107
            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
108
          end
Jack Weeden's avatar
Jack Weeden committed
109 110 111
        end
      end

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
112
      describe 'deleting an attachment' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
113 114
        before do
          find('.note').hover
Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
115
          find('.js-note-edit').click
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
116
        end
Jack Weeden's avatar
Jack Weeden committed
117

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
118
        it 'shows the delete link' do
119
          page.within('.note-attachment') do
Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
120
            is_expected.to have_css('.js-note-attachment-delete')
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
121
          end
Jack Weeden's avatar
Jack Weeden committed
122 123
        end

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
124 125 126
        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')
127 128
          is_expected.not_to have_css('.current-note-edit-form')
          wait_for_ajax
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
129
        end
Jack Weeden's avatar
Jack Weeden committed
130 131 132
      end
    end
  end
133

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
134
  describe 'On a merge request diff', js: true, feature: true do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
135 136
    let(:merge_request) { create(:merge_request) }
    let(:project) { merge_request.source_project }
137 138

    before do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
139
      login_as :admin
Vinnie Okada's avatar
Vinnie Okada committed
140
      visit diffs_namespace_project_merge_request_path(project.namespace, project, merge_request)
141 142
    end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
143
    subject { page }
144

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
145
    describe 'when adding a note' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
146
      before do
147
        click_diff_line
148 149
      end

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

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
153
        it 'has .new_note css class' do
154
          page.within('.js-temp-notes-holder') do
Phil Hughes's avatar
Phil Hughes committed
155
            expect(subject).to have_css('.new-note')
Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
156 157
          end
        end
158 159
      end

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
160
      describe 'the note form' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
161
        it "shouldn't add a second form for same row" do
162
          click_diff_line
163

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
164 165 166
          is_expected.
            to have_css("tr[id='#{line_code}'] + .js-temp-notes-holder form",
                        count: 1)
167
        end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
168

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

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
174
          is_expected.to have_no_css('.js-temp-notes-holder')
175 176 177 178
        end
      end
    end

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
179
    describe 'with muliple note forms' do
180
      before do
181 182
        click_diff_line
        click_diff_line(line_code_2)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
183 184
      end

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

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
187
      describe 'previewing them separately' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
188 189
        before do
          # add two separate texts and trigger previews on both
190
          page.within("tr[id='#{line_code}'] + .js-temp-notes-holder") do
Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
191
            fill_in 'note[note]', with: 'One comment on line 7'
192
            find('.js-md-preview-button').click
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
193
          end
194
          page.within("tr[id='#{line_code_2}'] + .js-temp-notes-holder") do
Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
195
            fill_in 'note[note]', with: 'Another comment on line 10'
196
            find('.js-md-preview-button').click
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
197
          end
198 199 200
        end
      end

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
201
      describe 'posting a note' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
202
        before do
203
          page.within("tr[id='#{line_code_2}'] + .js-temp-notes-holder") do
Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
204
            fill_in 'note[note]', with: 'Another comment on line 10'
205
            click_button('Comment')
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
206 207 208 209
          end
        end

        it 'should be added as discussion' do
Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
210 211 212
          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)
213
          is_expected.to have_button('Reply')
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
214
        end
215
      end
216 217
    end
  end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
218 219 220 221 222 223 224 225

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

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

227
  def click_diff_line(data = line_code)
Phil Hughes's avatar
Phil Hughes committed
228
    execute_script("$('button[data-line-code=\"#{data}\"]').click()")
229
  end
230
end