2019-07-25 05:24:42 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-08-29 07:56:52 +00:00
|
|
|
require 'spec_helper'
|
2017-04-12 15:02:53 +00:00
|
|
|
|
2020-06-16 18:09:01 +00:00
|
|
|
RSpec.describe 'Merge request > User posts notes', :js do
|
2017-06-07 18:33:50 +00:00
|
|
|
include NoteInteractionHelpers
|
|
|
|
|
2020-02-26 18:09:24 +00:00
|
|
|
let_it_be(:project) { create(:project, :repository) }
|
2021-04-22 06:09:47 +00:00
|
|
|
|
2017-08-01 18:03:07 +00:00
|
|
|
let(:user) { project.creator }
|
2017-04-12 15:02:53 +00:00
|
|
|
let(:merge_request) do
|
|
|
|
create(:merge_request, source_project: project, target_project: project)
|
|
|
|
end
|
2020-08-11 03:11:00 +00:00
|
|
|
|
2017-04-12 15:02:53 +00:00
|
|
|
let!(:note) do
|
|
|
|
create(:note_on_merge_request, :with_attachment, noteable: merge_request,
|
|
|
|
project: project)
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
2018-07-11 14:36:08 +00:00
|
|
|
project.add_maintainer(user)
|
2017-08-01 18:03:07 +00:00
|
|
|
sign_in(user)
|
2021-11-11 12:10:41 +00:00
|
|
|
|
2017-07-06 16:20:50 +00:00
|
|
|
visit project_merge_request_path(project, merge_request)
|
2017-04-12 15:02:53 +00:00
|
|
|
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-06-21 12:22:40 +00:00
|
|
|
expect(find('.js-main-target-form')).to have_selector('button', text: 'Comment')
|
2017-04-12 15:02:53 +00:00
|
|
|
page.within('.js-main-target-form') do
|
2018-06-21 12:22:40 +00:00
|
|
|
expect(page).not_to have_button('Cancel')
|
2017-04-12 15:02:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'with text' do
|
2019-09-06 15:49:13 +00:00
|
|
|
let(:text) { 'This is awesome' }
|
|
|
|
|
2017-04-12 15:02:53 +00:00
|
|
|
before do
|
|
|
|
page.within('.js-main-target-form') do
|
2019-09-06 15:49:13 +00:00
|
|
|
fill_in 'note[note]', with: text
|
2017-04-12 15:02:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-06 15:49:13 +00:00
|
|
|
it 'has enable submit button, preview button and saves content to local storage' do
|
2017-04-12 15:02:53 +00:00
|
|
|
page.within('.js-main-target-form') do
|
2021-02-23 09:10:45 +00:00
|
|
|
page.within('[data-testid="comment-button"]') do
|
|
|
|
expect(page).to have_css('.split-content-button')
|
|
|
|
expect(page).not_to have_css('.split-content-button[disabled]')
|
|
|
|
end
|
2017-04-12 15:02:53 +00:00
|
|
|
expect(page).to have_css('.js-md-preview-button', visible: true)
|
|
|
|
end
|
2019-09-06 15:49:13 +00:00
|
|
|
|
|
|
|
expect(page.evaluate_script("localStorage['autosave/Note/MergeRequest/#{merge_request.id}']")).to eq(text)
|
2017-04-12 15:02:53 +00:00
|
|
|
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-06-21 12:22:40 +00:00
|
|
|
expect(page).to have_css('.js-vue-md-preview', visible: :hidden)
|
2017-04-12 15:02:53 +00:00
|
|
|
end
|
2018-06-21 12:22:40 +00:00
|
|
|
wait_for_requests
|
2017-04-12 15:02:53 +00:00
|
|
|
page.within('.js-main-target-form') do
|
|
|
|
is_expected.to have_css('.js-note-text', visible: true)
|
|
|
|
end
|
|
|
|
end
|
2019-02-06 10:31:46 +00:00
|
|
|
|
2019-04-03 02:00:18 +00:00
|
|
|
describe 'reply button' do
|
2019-02-06 10:31:46 +00:00
|
|
|
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-08-20 21:10:18 +00:00
|
|
|
expect(reply_button).to have_selector('[data-testid="comment-icon"]')
|
2019-02-06 10:31:46 +00:00
|
|
|
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-04-12 15:02:53 +00:00
|
|
|
end
|
|
|
|
|
2020-08-18 21:09:57 +00:00
|
|
|
describe 'replying to a comment' do
|
|
|
|
it 'makes the discussion resolvable' do
|
2019-12-13 00:08:05 +00:00
|
|
|
find('.js-reply-button').click
|
|
|
|
|
|
|
|
page.within('.discussion-reply-holder') do
|
|
|
|
fill_in 'note[note]', with: 'A reply'
|
2020-06-01 06:08:21 +00:00
|
|
|
click_button 'Add comment now'
|
2020-08-18 21:09:57 +00:00
|
|
|
|
|
|
|
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'
|
2020-08-19 00:10:34 +00:00
|
|
|
|
|
|
|
note.delete
|
|
|
|
|
2020-08-18 21:09:57 +00:00
|
|
|
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
|
2019-12-13 00:08:05 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-12-20 19:29:44 +00:00
|
|
|
describe 'when previewing a note' do
|
|
|
|
it 'shows the toolbar buttons when editing a note' do
|
|
|
|
page.within('.js-main-target-form') do
|
2022-02-15 21:12:52 +00:00
|
|
|
expect(page).to have_css('.md-header-toolbar')
|
2017-12-20 19:29:44 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'hides the toolbar buttons when previewing a note' do
|
2018-06-21 12:22:40 +00:00
|
|
|
wait_for_requests
|
2017-12-20 19:29:44 +00:00
|
|
|
find('.js-md-preview-button').click
|
|
|
|
page.within('.js-main-target-form') do
|
2022-02-15 21:12:52 +00:00
|
|
|
expect(page).not_to have_css('.md-header-toolbar')
|
2017-12-20 19:29:44 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-04-12 15:02:53 +00:00
|
|
|
describe 'when editing a note' do
|
|
|
|
describe 'editing the note' do
|
|
|
|
before do
|
|
|
|
find('.note').hover
|
2017-06-07 18:33:50 +00:00
|
|
|
|
2017-04-12 15:02:53 +00:00
|
|
|
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
|
2022-05-24 12:09:04 +00:00
|
|
|
expect(find(:css, '.note-body .note-text', visible: false)).not_to be_visible
|
2017-04-12 15:02:53 +00:00
|
|
|
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'
|
2022-02-04 15:15:34 +00:00
|
|
|
find('[data-testid="cancel"]').click
|
|
|
|
end
|
2020-05-05 21:09:42 +00:00
|
|
|
|
2022-02-04 15:15:34 +00:00
|
|
|
page.within('.modal') do
|
2022-04-08 18:08:29 +00:00
|
|
|
click_button('Cancel editing', match: :first)
|
2017-04-12 15:02:53 +00:00
|
|
|
end
|
2022-02-04 15:15:34 +00:00
|
|
|
|
2018-06-21 12:22:40 +00:00
|
|
|
expect(find('.js-note-text').text).to eq ''
|
2017-04-12 15:02:53 +00:00
|
|
|
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'
|
2021-04-09 09:09:10 +00:00
|
|
|
find('.btn-confirm').click
|
2017-04-12 15:02:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
find('.note').hover
|
2018-06-21 12:22:40 +00:00
|
|
|
wait_for_requests
|
2017-06-07 18:33:50 +00:00
|
|
|
|
2017-04-12 15:02:53 +00:00
|
|
|
find('.js-note-edit').click
|
|
|
|
|
|
|
|
page.within('.current-note-edit-form') do
|
2021-03-18 15:09:04 +00:00
|
|
|
expect(find_field('note[note]').value).to include('This is the new content')
|
2019-06-14 13:01:24 +00:00
|
|
|
first('.js-md').click
|
2021-03-18 15:09:04 +00:00
|
|
|
expect(find_field('note[note]').value).to include('This is the new content****')
|
2017-04-12 15:02:53 +00:00
|
|
|
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'
|
2021-04-09 09:09:10 +00:00
|
|
|
find('.btn-confirm').click
|
2017-04-12 15:02:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
page.within("#note_#{note.id}") do
|
|
|
|
is_expected.to have_css('.note_edited_ago')
|
2017-06-21 13:48:12 +00:00
|
|
|
expect(find('.note_edited_ago').text)
|
2018-06-03 14:45:26 +00:00
|
|
|
.to match(/just now/)
|
2017-04-12 15:02:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-28 00:10:43 +00:00
|
|
|
describe 'deleting attachment on legacy diff note' do
|
2017-04-12 15:02:53 +00:00
|
|
|
before do
|
|
|
|
find('.note').hover
|
2017-06-07 18:33:50 +00:00
|
|
|
|
2017-04-12 15:02:53 +00:00
|
|
|
find('.js-note-edit').click
|
|
|
|
end
|
|
|
|
|
2019-09-18 14:02:45 +00:00
|
|
|
# TODO: https://gitlab.com/gitlab-org/gitlab-foss/issues/48034
|
2018-06-21 12:22:40 +00:00
|
|
|
xit 'shows the delete link' do
|
2017-04-12 15:02:53 +00:00
|
|
|
page.within('.note-attachment') do
|
|
|
|
is_expected.to have_css('.js-note-attachment-delete')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-18 14:02:45 +00:00
|
|
|
# TODO: https://gitlab.com/gitlab-org/gitlab-foss/issues/48034
|
2018-06-21 12:22:40 +00:00
|
|
|
xit 'removes the attachment div and resets the edit form' do
|
2017-09-27 12:46:48 +00:00
|
|
|
accept_confirm { find('.js-note-attachment-delete').click }
|
2017-04-12 15:02:53 +00:00
|
|
|
is_expected.not_to have_css('.note-attachment')
|
|
|
|
is_expected.not_to have_css('.current-note-edit-form')
|
2017-05-17 18:25:13 +00:00
|
|
|
wait_for_requests
|
2017-04-12 15:02:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|