debian-mirror-gitlab/spec/features/merge_request/user_posts_notes_spec.rb

226 lines
6.7 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2019-12-04 20:38:33 +05:30
require 'spec_helper'
2017-08-17 22:00:37 +05:30
2020-06-23 00:09:42 +05:30
RSpec.describe 'Merge request > User posts notes', :js do
2017-09-10 17:25:29 +05:30
include NoteInteractionHelpers
2020-04-08 14:13:33 +05:30
let_it_be(:project) { create(:project, :repository) }
2018-03-17 18:26:18 +05:30
let(:user) { project.creator }
2017-08-17 22:00:37 +05:30
let(:merge_request) do
create(:merge_request, source_project: project, target_project: project)
end
2020-10-24 23:57:45 +05:30
2017-08-17 22:00:37 +05:30
let!(:note) do
create(:note_on_merge_request, :with_attachment, noteable: merge_request,
project: project)
end
before do
2018-11-18 11:00:15 +05:30
project.add_maintainer(user)
2018-03-17 18:26:18 +05:30
sign_in(user)
2017-09-10 17:25:29 +05:30
visit project_merge_request_path(project, merge_request)
2017-08-17 22:00:37 +05:30
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)
2018-11-08 19:23:39 +05:30
expect(find('.js-main-target-form')).to have_selector('button', text: 'Comment')
2017-08-17 22:00:37 +05:30
page.within('.js-main-target-form') do
2018-11-08 19:23:39 +05:30
expect(page).not_to have_button('Cancel')
2017-08-17 22:00:37 +05:30
end
end
describe 'with text' do
2019-12-04 20:38:33 +05:30
let(:text) { 'This is awesome' }
2017-08-17 22:00:37 +05:30
before do
page.within('.js-main-target-form') do
2019-12-04 20:38:33 +05:30
fill_in 'note[note]', with: text
2017-08-17 22:00:37 +05:30
end
end
2019-12-04 20:38:33 +05:30
it 'has enable submit button, preview button and saves content to local storage' do
2017-08-17 22:00:37 +05:30
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
2019-12-04 20:38:33 +05:30
expect(page.evaluate_script("localStorage['autosave/Note/MergeRequest/#{merge_request.id}']")).to eq(text)
2017-08-17 22:00:37 +05:30
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!')
2018-11-08 19:23:39 +05:30
expect(page).to have_css('.js-vue-md-preview', visible: :hidden)
2017-08-17 22:00:37 +05:30
end
2018-11-08 19:23:39 +05:30
wait_for_requests
2017-08-17 22:00:37 +05:30
page.within('.js-main-target-form') do
is_expected.to have_css('.js-note-text', visible: true)
end
end
2019-03-02 22:35:43 +05:30
2019-07-07 11:18:12 +05:30
describe 'reply button' do
2019-03-02 22:35:43 +05:30
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)
2020-11-24 15:15:51 +05:30
expect(reply_button).to have_selector('[data-testid="comment-icon"]')
2019-03-02 22:35:43 +05:30
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
2017-08-17 22:00:37 +05:30
end
2020-10-24 23:57:45 +05:30
describe 'replying to a comment' do
it 'makes the discussion resolvable' do
2020-01-01 13:55:28 +05:30
find('.js-reply-button').click
page.within('.discussion-reply-holder') do
fill_in 'note[note]', with: 'A reply'
2020-06-23 00:09:42 +05:30
click_button 'Add comment now'
2020-10-24 23:57:45 +05:30
expect(page).to have_button('Resolve thread')
end
end
context 'when comment is deleted' do
it 'shows an error message' do
find('.js-reply-button').click
page.within('.discussion-reply-holder') do
fill_in 'note[note]', with: 'A reply'
note.delete
click_button 'Add comment now'
expect(page).to have_content('Your comment could not be submitted because discussion to reply to cannot be found')
end
2020-01-01 13:55:28 +05:30
end
end
end
2018-03-17 18:26:18 +05:30
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
2018-11-08 19:23:39 +05:30
wait_for_requests
2018-03-17 18:26:18 +05:30
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
2017-08-17 22:00:37 +05:30
describe 'when editing a note' do
describe 'editing the note' do
before do
find('.note').hover
2017-09-10 17:25:29 +05:30
2017-08-17 22:00:37 +05:30
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'
2020-05-24 23:13:21 +05:30
accept_confirm do
find('.btn-cancel').click
end
2017-08-17 22:00:37 +05:30
end
2018-11-08 19:23:39 +05:30
expect(find('.js-note-text').text).to eq ''
2017-08-17 22:00:37 +05:30
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'
2018-12-05 23:21:45 +05:30
find('.btn-success').click
2017-08-17 22:00:37 +05:30
end
find('.note').hover
2018-11-08 19:23:39 +05:30
wait_for_requests
2017-09-10 17:25:29 +05:30
2017-08-17 22:00:37 +05:30
find('.js-note-edit').click
page.within('.current-note-edit-form') do
2020-03-13 15:44:24 +05:30
expect(find('#note_note').value).to include('This is the new content')
2019-09-04 21:01:54 +05:30
first('.js-md').click
2020-03-13 15:44:24 +05:30
expect(find('#note_note').value).to include('This is the new content****')
2017-08-17 22:00:37 +05:30
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'
2018-12-05 23:21:45 +05:30
find('.btn-success').click
2017-08-17 22:00:37 +05:30
end
page.within("#note_#{note.id}") do
is_expected.to have_css('.note_edited_ago')
2017-09-10 17:25:29 +05:30
expect(find('.note_edited_ago').text)
2018-11-08 19:23:39 +05:30
.to match(/just now/)
2017-08-17 22:00:37 +05:30
end
end
end
2018-03-27 19:54:05 +05:30
describe 'deleting attachment on legacy diff note' do
2017-08-17 22:00:37 +05:30
before do
find('.note').hover
2017-09-10 17:25:29 +05:30
2017-08-17 22:00:37 +05:30
find('.js-note-edit').click
end
2019-12-04 20:38:33 +05:30
# TODO: https://gitlab.com/gitlab-org/gitlab-foss/issues/48034
2018-11-08 19:23:39 +05:30
xit 'shows the delete link' do
2017-08-17 22:00:37 +05:30
page.within('.note-attachment') do
is_expected.to have_css('.js-note-attachment-delete')
end
end
2019-12-04 20:38:33 +05:30
# TODO: https://gitlab.com/gitlab-org/gitlab-foss/issues/48034
2018-11-08 19:23:39 +05:30
xit 'removes the attachment div and resets the edit form' do
2018-03-17 18:26:18 +05:30
accept_confirm { find('.js-note-attachment-delete').click }
2017-08-17 22:00:37 +05:30
is_expected.not_to have_css('.note-attachment')
is_expected.not_to have_css('.current-note-edit-form')
2017-09-10 17:25:29 +05:30
wait_for_requests
2017-08-17 22:00:37 +05:30
end
end
end
end