2013-01-14 18:27:59 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-06-28 16:19:52 -04:00
|
|
|
describe 'Comments', feature: true do
|
2014-08-07 13:46:17 -04:00
|
|
|
include RepoHelpers
|
2015-12-07 17:08:22 -05:00
|
|
|
include WaitForAjax
|
2013-01-14 18:27:59 -05:00
|
|
|
|
2015-02-12 13:53:23 -05:00
|
|
|
describe 'On a merge request', js: true, feature: true do
|
2016-04-26 07:52:18 -04:00
|
|
|
let!(:project) { create(:project) }
|
|
|
|
let!(:merge_request) do
|
|
|
|
create(:merge_request, source_project: project, target_project: project)
|
|
|
|
end
|
|
|
|
|
2015-02-12 13:53:23 -05:00
|
|
|
let!(:note) do
|
2016-04-26 07:52:18 -04:00
|
|
|
create(:note_on_merge_request, :with_attachment, noteable: merge_request,
|
|
|
|
project: project)
|
2015-02-12 13:53:23 -05:00
|
|
|
end
|
2013-01-14 18:27:59 -05:00
|
|
|
|
2014-08-07 13:46:17 -04:00
|
|
|
before do
|
|
|
|
login_as :admin
|
2015-01-24 13:02:58 -05:00
|
|
|
visit namespace_project_merge_request_path(project.namespace, project, merge_request)
|
2013-01-14 18:27:59 -05:00
|
|
|
end
|
|
|
|
|
2014-08-07 13:46:17 -04:00
|
|
|
subject { page }
|
2013-01-14 18:27:59 -05:00
|
|
|
|
2015-02-12 13:53:23 -05:00
|
|
|
describe 'the note form' do
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'is valid' do
|
2015-02-12 13:53:23 -05:00
|
|
|
is_expected.to have_css('.js-main-target-form', visible: true, count: 1)
|
|
|
|
expect(find('.js-main-target-form input[type=submit]').value).
|
2016-03-04 05:44:04 -05:00
|
|
|
to eq('Comment')
|
2015-06-13 18:30:09 -04:00
|
|
|
page.within('.js-main-target-form') do
|
2014-10-17 00:10:50 -04:00
|
|
|
expect(page).not_to have_link('Cancel')
|
|
|
|
end
|
2013-04-10 13:27:43 -04:00
|
|
|
end
|
2013-01-14 18:27:59 -05:00
|
|
|
|
2015-02-12 13:53:23 -05:00
|
|
|
describe 'with text' do
|
2014-08-07 13:46:17 -04:00
|
|
|
before do
|
2015-06-13 18:30:09 -04:00
|
|
|
page.within('.js-main-target-form') do
|
2015-02-12 13:53:23 -05:00
|
|
|
fill_in 'note[note]', with: 'This is awesome'
|
2014-08-07 13:46:17 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'has enable submit button and preview button' do
|
2015-06-13 18:30:09 -04:00
|
|
|
page.within('.js-main-target-form') do
|
2014-10-18 19:24:12 -04:00
|
|
|
expect(page).not_to have_css('.js-comment-button[disabled]')
|
2014-10-20 22:53:17 -04:00
|
|
|
expect(page).to have_css('.js-md-preview-button', visible: true)
|
2014-10-17 00:10:50 -04:00
|
|
|
end
|
2014-08-07 13:46:17 -04:00
|
|
|
end
|
2013-01-14 18:27:59 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-02-12 13:53:23 -05:00
|
|
|
describe 'when posting a note' do
|
2014-08-07 13:46:17 -04:00
|
|
|
before do
|
2015-06-13 18:30:09 -04:00
|
|
|
page.within('.js-main-target-form') do
|
2015-02-12 13:53:23 -05:00
|
|
|
fill_in 'note[note]', with: 'This is awsome!'
|
2014-10-17 00:10:50 -04:00
|
|
|
find('.js-md-preview-button').click
|
2016-03-04 05:44:04 -05:00
|
|
|
click_button 'Comment'
|
2014-08-07 13:46:17 -04:00
|
|
|
end
|
|
|
|
end
|
2013-06-26 10:32:34 -04:00
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'is added and form reset' do
|
2015-02-12 13:53:23 -05:00
|
|
|
is_expected.to have_content('This is awsome!')
|
2015-06-13 18:30:09 -04:00
|
|
|
page.within('.js-main-target-form') do
|
2014-10-18 19:24:12 -04:00
|
|
|
expect(page).to have_no_field('note[note]', with: 'This is awesome!')
|
2014-10-20 22:53:17 -04:00
|
|
|
expect(page).to have_css('.js-md-preview', visible: :hidden)
|
2014-10-17 00:10:50 -04:00
|
|
|
end
|
2015-06-13 18:30:09 -04:00
|
|
|
page.within('.js-main-target-form') do
|
2015-02-12 13:53:23 -05:00
|
|
|
is_expected.to have_css('.js-note-text', visible: true)
|
|
|
|
end
|
2014-08-07 13:46:17 -04:00
|
|
|
end
|
2013-06-26 10:32:34 -04:00
|
|
|
end
|
|
|
|
|
2015-02-12 13:53:23 -05:00
|
|
|
describe 'when editing a note', js: true do
|
2016-11-14 17:26:54 -05:00
|
|
|
it 'there should be a hidden edit form' do
|
2016-12-08 16:49:32 -05:00
|
|
|
is_expected.to have_css('.note-edit-form:not(.mr-note-edit-form)', visible: false, count: 1)
|
|
|
|
is_expected.to have_css('.note-edit-form.mr-note-edit-form', visible: false, count: 1)
|
2015-11-15 15:30:05 -05:00
|
|
|
end
|
|
|
|
|
2015-02-12 13:53:23 -05:00
|
|
|
describe 'editing the note' do
|
2014-08-07 13:46:17 -04:00
|
|
|
before do
|
|
|
|
find('.note').hover
|
2017-01-02 13:37:37 -05:00
|
|
|
find('.js-note-edit').click
|
2013-06-26 10:32:34 -04:00
|
|
|
end
|
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'shows the note edit form and hide the note body' do
|
2015-06-13 18:30:09 -04:00
|
|
|
page.within("#note_#{note.id}") do
|
2015-02-12 13:53:23 -05:00
|
|
|
expect(find('.current-note-edit-form', visible: true)).to be_visible
|
|
|
|
expect(find('.note-edit-form', visible: true)).to be_visible
|
2015-02-13 08:14:27 -05:00
|
|
|
expect(find(:css, '.note-body > .note-text', visible: false)).not_to be_visible
|
2014-08-07 13:46:17 -04:00
|
|
|
end
|
2013-06-26 10:32:34 -04:00
|
|
|
end
|
|
|
|
|
2016-08-11 11:30:18 -04:00
|
|
|
it 'resets the edit note form textarea with the original content of the note if cancelled' do
|
2017-01-02 13:37:37 -05:00
|
|
|
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 ''
|
|
|
|
end
|
|
|
|
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'
|
|
|
|
find('.btn-save').click
|
|
|
|
end
|
|
|
|
|
|
|
|
find('.note').hover
|
|
|
|
find('.js-note-edit').click
|
|
|
|
|
|
|
|
page.within('.current-note-edit-form') do
|
|
|
|
expect(find('#note_note').value).to eq('This is the new content')
|
|
|
|
find('.js-md:first-child').click
|
|
|
|
expect(find('#note_note').value).to eq('This is the new content****')
|
|
|
|
end
|
|
|
|
end
|
2013-06-26 10:32:34 -04:00
|
|
|
|
2015-02-12 13:53:23 -05:00
|
|
|
it 'appends the edited at time to the note' do
|
2015-06-13 18:30:09 -04:00
|
|
|
page.within('.current-note-edit-form') do
|
2015-02-12 13:53:23 -05:00
|
|
|
fill_in 'note[note]', with: 'Some new content'
|
|
|
|
find('.btn-save').click
|
2014-08-07 13:46:17 -04:00
|
|
|
end
|
|
|
|
|
2015-06-13 18:30:09 -04:00
|
|
|
page.within("#note_#{note.id}") do
|
2015-02-12 13:53:23 -05:00
|
|
|
is_expected.to have_css('.note_edited_ago')
|
|
|
|
expect(find('.note_edited_ago').text).
|
|
|
|
to match(/less than a minute ago/)
|
2014-08-07 13:46:17 -04:00
|
|
|
end
|
2013-06-26 10:32:34 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-02-12 13:53:23 -05:00
|
|
|
describe 'deleting an attachment' do
|
2014-08-07 13:46:17 -04:00
|
|
|
before do
|
|
|
|
find('.note').hover
|
2015-02-12 13:53:23 -05:00
|
|
|
find('.js-note-edit').click
|
2014-08-07 13:46:17 -04:00
|
|
|
end
|
2013-06-26 10:32:34 -04:00
|
|
|
|
2015-02-12 13:53:23 -05:00
|
|
|
it 'shows the delete link' do
|
2015-06-13 18:30:09 -04:00
|
|
|
page.within('.note-attachment') do
|
2015-02-12 13:53:23 -05:00
|
|
|
is_expected.to have_css('.js-note-attachment-delete')
|
2014-08-07 13:46:17 -04:00
|
|
|
end
|
2013-06-26 10:32:34 -04:00
|
|
|
end
|
|
|
|
|
2015-02-12 13:53:23 -05:00
|
|
|
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')
|
2015-12-07 17:08:22 -05:00
|
|
|
is_expected.not_to have_css('.current-note-edit-form')
|
|
|
|
wait_for_ajax
|
2014-08-07 13:46:17 -04:00
|
|
|
end
|
2013-06-26 10:32:34 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-01-14 18:27:59 -05:00
|
|
|
|
2016-07-04 01:31:43 -04:00
|
|
|
describe 'Handles cross-project system notes', js: true, feature: true do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:project) { create(:project, :public) }
|
|
|
|
let(:project2) { create(:project, :private) }
|
|
|
|
let(:issue) { create(:issue, project: project2) }
|
|
|
|
let(:merge_request) { create(:merge_request, source_project: project, source_branch: 'markdown') }
|
2016-11-23 01:55:23 -05:00
|
|
|
let!(:note) { create(:note_on_merge_request, :system, noteable: merge_request, project: project, note: "mentioned in #{issue.to_reference(project)}") }
|
2016-07-04 01:31:43 -04:00
|
|
|
|
|
|
|
it 'shows the system note' do
|
|
|
|
login_as :admin
|
|
|
|
visit namespace_project_merge_request_path(project.namespace, project, merge_request)
|
|
|
|
|
|
|
|
expect(page).to have_css('.system-note')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'hides redacted system note' do
|
|
|
|
visit namespace_project_merge_request_path(project.namespace, project, merge_request)
|
|
|
|
|
|
|
|
expect(page).not_to have_css('.system-note')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-02-12 13:53:23 -05:00
|
|
|
describe 'On a merge request diff', js: true, feature: true do
|
2014-08-07 13:46:17 -04:00
|
|
|
let(:merge_request) { create(:merge_request) }
|
|
|
|
let(:project) { merge_request.source_project }
|
2013-01-14 18:27:59 -05:00
|
|
|
|
|
|
|
before do
|
2014-08-07 13:46:17 -04:00
|
|
|
login_as :admin
|
2015-01-24 13:02:58 -05:00
|
|
|
visit diffs_namespace_project_merge_request_path(project.namespace, project, merge_request)
|
2013-01-14 18:27:59 -05:00
|
|
|
end
|
|
|
|
|
2014-08-07 13:46:17 -04:00
|
|
|
subject { page }
|
2013-01-14 18:27:59 -05:00
|
|
|
|
2015-02-12 13:53:23 -05:00
|
|
|
describe 'when adding a note' do
|
2014-08-07 13:46:17 -04:00
|
|
|
before do
|
2014-09-19 09:26:20 -04:00
|
|
|
click_diff_line
|
2013-01-14 18:27:59 -05:00
|
|
|
end
|
|
|
|
|
2015-02-12 13:53:23 -05:00
|
|
|
describe 'the notes holder' do
|
|
|
|
it { is_expected.to have_css('.js-temp-notes-holder') }
|
2013-01-14 18:27:59 -05:00
|
|
|
|
2015-02-12 13:53:23 -05:00
|
|
|
it 'has .new_note css class' do
|
2015-06-13 18:30:09 -04:00
|
|
|
page.within('.js-temp-notes-holder') do
|
2016-03-30 11:20:43 -04:00
|
|
|
expect(subject).to have_css('.new-note')
|
2015-02-12 13:53:23 -05:00
|
|
|
end
|
|
|
|
end
|
2013-01-14 18:27:59 -05:00
|
|
|
end
|
|
|
|
|
2015-02-12 13:53:23 -05:00
|
|
|
describe 'the note form' do
|
2016-08-11 11:30:18 -04:00
|
|
|
it "does not add a second form for same row" do
|
2014-09-19 09:26:20 -04:00
|
|
|
click_diff_line
|
2013-01-14 18:27:59 -05:00
|
|
|
|
2015-02-12 13:53:23 -05:00
|
|
|
is_expected.
|
2016-06-20 13:23:46 -04:00
|
|
|
to have_css("form[data-line-code='#{line_code}']",
|
2015-02-12 13:53:23 -05:00
|
|
|
count: 1)
|
2013-01-14 18:27:59 -05:00
|
|
|
end
|
2014-08-07 13:46:17 -04:00
|
|
|
|
2016-08-11 11:30:18 -04:00
|
|
|
it 'is removed when canceled' do
|
2016-06-20 13:23:46 -04:00
|
|
|
is_expected.to have_css('.js-temp-notes-holder')
|
|
|
|
|
|
|
|
page.within("form[data-line-code='#{line_code}']") do
|
2015-02-12 13:53:23 -05:00
|
|
|
find('.js-close-discussion-note-form').trigger('click')
|
2014-08-07 13:46:17 -04:00
|
|
|
end
|
|
|
|
|
2015-02-12 13:53:23 -05:00
|
|
|
is_expected.to have_no_css('.js-temp-notes-holder')
|
2013-01-14 18:27:59 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-02-12 13:53:23 -05:00
|
|
|
describe 'with muliple note forms' do
|
2013-01-14 18:27:59 -05:00
|
|
|
before do
|
2014-09-19 09:26:20 -04:00
|
|
|
click_diff_line
|
|
|
|
click_diff_line(line_code_2)
|
2014-08-07 13:46:17 -04:00
|
|
|
end
|
|
|
|
|
2015-02-12 13:53:23 -05:00
|
|
|
it { is_expected.to have_css('.js-temp-notes-holder', count: 2) }
|
2014-08-07 13:46:17 -04:00
|
|
|
|
2015-02-12 13:53:23 -05:00
|
|
|
describe 'previewing them separately' do
|
2014-08-07 13:46:17 -04:00
|
|
|
before do
|
|
|
|
# add two separate texts and trigger previews on both
|
2015-06-13 18:30:09 -04:00
|
|
|
page.within("tr[id='#{line_code}'] + .js-temp-notes-holder") do
|
2015-02-12 13:53:23 -05:00
|
|
|
fill_in 'note[note]', with: 'One comment on line 7'
|
2014-10-17 00:10:50 -04:00
|
|
|
find('.js-md-preview-button').click
|
2014-08-07 13:46:17 -04:00
|
|
|
end
|
2015-06-13 18:30:09 -04:00
|
|
|
page.within("tr[id='#{line_code_2}'] + .js-temp-notes-holder") do
|
2015-02-12 13:53:23 -05:00
|
|
|
fill_in 'note[note]', with: 'Another comment on line 10'
|
2014-10-17 00:10:50 -04:00
|
|
|
find('.js-md-preview-button').click
|
2014-08-07 13:46:17 -04:00
|
|
|
end
|
2013-01-14 18:27:59 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-02-12 13:53:23 -05:00
|
|
|
describe 'posting a note' do
|
2014-08-07 13:46:17 -04:00
|
|
|
before do
|
2015-06-13 18:30:09 -04:00
|
|
|
page.within("tr[id='#{line_code_2}'] + .js-temp-notes-holder") do
|
2015-02-12 13:53:23 -05:00
|
|
|
fill_in 'note[note]', with: 'Another comment on line 10'
|
2016-03-04 05:44:04 -05:00
|
|
|
click_button('Comment')
|
2014-08-07 13:46:17 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'adds as discussion' do
|
2015-02-12 13:53:23 -05:00
|
|
|
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)
|
2016-04-01 15:27:39 -04:00
|
|
|
is_expected.to have_button('Reply...')
|
2014-08-07 13:46:17 -04:00
|
|
|
end
|
2016-10-04 09:06:44 -04:00
|
|
|
|
|
|
|
it 'adds code to discussion' do
|
|
|
|
click_button 'Reply...'
|
|
|
|
|
|
|
|
page.within(first('.js-discussion-note-form')) do
|
|
|
|
fill_in 'note[note]', with: '```{{ test }}```'
|
|
|
|
|
|
|
|
click_button('Comment')
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(page).to have_content('{{ test }}')
|
|
|
|
end
|
2013-04-10 13:27:43 -04:00
|
|
|
end
|
2013-01-14 18:27:59 -05:00
|
|
|
end
|
|
|
|
end
|
2014-08-07 13:46:17 -04:00
|
|
|
|
|
|
|
def line_code
|
|
|
|
sample_compare.changes.first[:line_code]
|
|
|
|
end
|
|
|
|
|
|
|
|
def line_code_2
|
|
|
|
sample_compare.changes.last[:line_code]
|
|
|
|
end
|
2014-09-19 09:26:20 -04:00
|
|
|
|
2015-06-25 21:30:18 -04:00
|
|
|
def click_diff_line(data = line_code)
|
2016-07-07 19:49:19 -04:00
|
|
|
find(".line_holder[id='#{data}'] td.line_content").hover
|
2016-06-18 11:19:57 -04:00
|
|
|
find(".line_holder[id='#{data}'] button").trigger('click')
|
2014-09-19 09:26:20 -04:00
|
|
|
end
|
2013-01-14 18:27:59 -05:00
|
|
|
end
|