user_posts_notes_spec.rb 5.64 KB
Newer Older
1
require 'rails_helper'
2

3
describe 'Merge request > User posts notes', :js do
4 5
  include NoteInteractionHelpers

6
  let(:project) { create(:project, :repository) }
7
  let(:user) { project.creator }
8 9 10 11 12 13 14 15 16
  let(:merge_request) do
    create(:merge_request, source_project: project, target_project: project)
  end
  let!(:note) do
    create(:note_on_merge_request, :with_attachment, noteable: merge_request,
                                                     project: project)
  end

  before do
17
    project.add_maintainer(user)
18
    sign_in(user)
19
    visit project_merge_request_path(project, merge_request)
20 21 22 23 24 25 26
  end

  subject { page }

  describe 'the note form' do
    it 'is valid' do
      is_expected.to have_css('.js-main-target-form', visible: true, count: 1)
Felipe Artur's avatar
Felipe Artur committed
27
      expect(find('.js-main-target-form')).to have_selector('button', text: 'Comment')
28
      page.within('.js-main-target-form') do
Felipe Artur's avatar
Felipe Artur committed
29
        expect(page).not_to have_button('Cancel')
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
      end
    end

    describe 'with text' do
      before do
        page.within('.js-main-target-form') do
          fill_in 'note[note]', with: 'This is awesome'
        end
      end

      it 'has enable submit button and preview button' do
        page.within('.js-main-target-form') do
          expect(page).not_to have_css('.js-comment-button[disabled]')
          expect(page).to have_css('.js-md-preview-button', visible: true)
        end
      end
    end
  end

  describe 'when posting a note' do
    before do
      page.within('.js-main-target-form') do
        fill_in 'note[note]', with: 'This is awesome!'
        find('.js-md-preview-button').click
        click_button 'Comment'
      end
    end

    it 'is added and form reset' do
      is_expected.to have_content('This is awesome!')
      page.within('.js-main-target-form') do
        expect(page).to have_no_field('note[note]', with: 'This is awesome!')
Felipe Artur's avatar
Felipe Artur committed
62
        expect(page).to have_css('.js-vue-md-preview', visible: :hidden)
63
      end
Felipe Artur's avatar
Felipe Artur committed
64
      wait_for_requests
65 66 67 68
      page.within('.js-main-target-form') do
        is_expected.to have_css('.js-note-text', visible: true)
      end
    end
69

70
    describe 'reply button' do
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
      before do
        visit project_merge_request_path(project, merge_request)
      end

      it 'shows a reply button' do
        reply_button = find('.js-reply-button', match: :first)

        expect(reply_button).to have_selector('.ic-comment')
      end

      it 'shows reply placeholder when clicking reply button' do
        reply_button = find('.js-reply-button', match: :first)

        reply_button.click

        expect(page).to have_selector('.discussion-reply-holder')
      end
    end
89 90
  end

91 92 93 94 95 96 97 98
  describe 'when previewing a note' do
    it 'shows the toolbar buttons when editing a note' do
      page.within('.js-main-target-form') do
        expect(page).to have_css('.md-header-toolbar.active')
      end
    end

    it 'hides the toolbar buttons when previewing a note' do
Felipe Artur's avatar
Felipe Artur committed
99
      wait_for_requests
100 101 102 103 104 105 106
      find('.js-md-preview-button').click
      page.within('.js-main-target-form') do
        expect(page).not_to have_css('.md-header-toolbar.active')
      end
    end
  end

107 108 109 110
  describe 'when editing a note' do
    describe 'editing the note' do
      before do
        find('.note').hover
111

112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
        find('.js-note-edit').click
      end

      it 'shows the note edit form and hide the note body' do
        page.within("#note_#{note.id}") do
          expect(find('.current-note-edit-form', visible: true)).to be_visible
          expect(find('.note-edit-form', visible: true)).to be_visible
          expect(find(:css, '.note-body > .note-text', visible: false)).not_to be_visible
        end
      end

      it 'resets 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
        end
Felipe Artur's avatar
Felipe Artur committed
128
        expect(find('.js-note-text').text).to eq ''
129 130 131 132 133
      end

      it 'allows using markdown buttons after saving a note and then trying to edit it again' do
        page.within('.current-note-edit-form') do
          fill_in 'note[note]', with: 'This is the new content'
134
          find('.btn-success').click
135 136 137
        end

        find('.note').hover
Felipe Artur's avatar
Felipe Artur committed
138
        wait_for_requests
139

140 141 142 143
        find('.js-note-edit').click

        page.within('.current-note-edit-form') do
          expect(find('#note_note').value).to eq('This is the new content')
144
          first('.js-md').click
145 146 147 148 149 150 151
          expect(find('#note_note').value).to eq('This is the new content****')
        end
      end

      it 'appends the edited at time to the note' do
        page.within('.current-note-edit-form') do
          fill_in 'note[note]', with: 'Some new content'
152
          find('.btn-success').click
153 154 155 156
        end

        page.within("#note_#{note.id}") do
          is_expected.to have_css('.note_edited_ago')
157
          expect(find('.note_edited_ago').text)
158
            .to match(/just now/)
159 160 161 162
        end
      end
    end

163
    describe 'deleting attachment on legacy diff note' do
164 165
      before do
        find('.note').hover
166

167 168 169
        find('.js-note-edit').click
      end

Felipe Artur's avatar
Felipe Artur committed
170 171
      # TODO: https://gitlab.com/gitlab-org/gitlab-ce/issues/48034
      xit 'shows the delete link' do
172 173 174 175 176
        page.within('.note-attachment') do
          is_expected.to have_css('.js-note-attachment-delete')
        end
      end

Felipe Artur's avatar
Felipe Artur committed
177 178
      # TODO: https://gitlab.com/gitlab-org/gitlab-ce/issues/48034
      xit 'removes the attachment div and resets the edit form' do
179
        accept_confirm { find('.js-note-attachment-delete').click }
180 181
        is_expected.not_to have_css('.note-attachment')
        is_expected.not_to have_css('.current-note-edit-form')
182
        wait_for_requests
183 184 185 186
      end
    end
  end
end