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
|
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
|
2014-08-07 13:46:17 -04:00
|
|
|
let!(:merge_request) { create(:merge_request) }
|
|
|
|
let!(:project) { merge_request.source_project }
|
2015-02-12 13:53:23 -05:00
|
|
|
let!(:note) do
|
|
|
|
create(:note_on_merge_request, :with_attachment, project: project)
|
|
|
|
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
|
2014-08-07 13:46:17 -04:00
|
|
|
it 'should be 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).
|
|
|
|
to eq('Add 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
|
|
|
|
|
|
|
|
it 'should have 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
|
2015-02-12 13:53:23 -05:00
|
|
|
click_button 'Add Comment'
|
2014-08-07 13:46:17 -04:00
|
|
|
end
|
|
|
|
end
|
2013-06-26 10:32:34 -04:00
|
|
|
|
2014-08-07 13:46:17 -04:00
|
|
|
it 'should be 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
|
|
|
|
it 'should contain the hidden edit form' do
|
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-edit-form', visible: false)
|
|
|
|
end
|
2013-06-26 10:32:34 -04: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
|
|
|
|
find(".js-note-edit").click
|
2013-06-26 10:32:34 -04:00
|
|
|
end
|
|
|
|
|
2015-02-12 13:53:23 -05:00
|
|
|
it 'should show 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
|
|
|
|
|
2015-01-15 04:17:07 -05:00
|
|
|
# TODO: fix after 7.7 release
|
2015-06-22 14:56:48 -04:00
|
|
|
# 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
|
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')
|
|
|
|
expect(find('.current-note-edit-form', visible: false)).
|
|
|
|
not_to be_visible
|
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
|
|
|
|
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
|
2015-02-12 13:53:23 -05:00
|
|
|
expect(subject).to have_css('.new_note')
|
|
|
|
end
|
|
|
|
end
|
2013-01-14 18:27:59 -05:00
|
|
|
end
|
|
|
|
|
2015-02-12 13:53:23 -05:00
|
|
|
describe 'the note form' do
|
2014-08-07 13:46:17 -04:00
|
|
|
it "shouldn't 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.
|
|
|
|
to have_css("tr[id='#{line_code}'] + .js-temp-notes-holder form",
|
|
|
|
count: 1)
|
2013-01-14 18:27:59 -05:00
|
|
|
end
|
2014-08-07 13:46:17 -04:00
|
|
|
|
2015-02-12 13:53:23 -05:00
|
|
|
it 'should be removed when canceled' do
|
2015-06-13 18:30:09 -04:00
|
|
|
page.within(".diff-file form[rel$='#{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'
|
|
|
|
click_button('Add Comment')
|
2014-08-07 13:46:17 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be added 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)
|
2015-02-12 13:17:35 -05:00
|
|
|
is_expected.to have_button('Reply')
|
2014-08-07 13:46:17 -04:00
|
|
|
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)
|
|
|
|
page.find(%Q{button[data-line-code="#{data}"]}, visible: false).click
|
2014-09-19 09:26:20 -04:00
|
|
|
end
|
2013-01-14 18:27:59 -05:00
|
|
|
end
|