2017-04-27 06:41:26 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-06-29 00:13:10 -04:00
|
|
|
describe 'Comments on personal snippets', :js do
|
2017-06-07 14:33:50 -04:00
|
|
|
include NoteInteractionHelpers
|
|
|
|
|
2017-04-27 06:41:26 -04:00
|
|
|
let!(:user) { create(:user) }
|
|
|
|
let!(:snippet) { create(:personal_snippet, :public) }
|
|
|
|
let!(:snippet_notes) do
|
|
|
|
[
|
|
|
|
create(:note_on_personal_snippet, noteable: snippet, author: user),
|
|
|
|
create(:note_on_personal_snippet, noteable: snippet)
|
|
|
|
]
|
|
|
|
end
|
|
|
|
let!(:other_note) { create(:note_on_personal_snippet) }
|
|
|
|
|
|
|
|
before do
|
2017-06-21 19:44:10 -04:00
|
|
|
sign_in user
|
2017-04-27 06:41:26 -04:00
|
|
|
visit snippet_path(snippet)
|
2018-07-16 12:18:52 -04:00
|
|
|
|
|
|
|
wait_for_requests
|
2017-04-27 06:41:26 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
subject { page }
|
|
|
|
|
2017-05-03 04:48:01 -04:00
|
|
|
context 'when viewing the snippet detail page' do
|
2017-04-27 06:41:26 -04:00
|
|
|
it 'contains notes for a snippet with correct action icons' do
|
|
|
|
expect(page).to have_selector('#notes-list li', count: 2)
|
|
|
|
|
2017-06-07 14:33:50 -04:00
|
|
|
open_more_actions_dropdown(snippet_notes[0])
|
|
|
|
|
2017-04-27 06:41:26 -04:00
|
|
|
# comment authored by current user
|
|
|
|
page.within("#notes-list li#note_#{snippet_notes[0].id}") do
|
|
|
|
expect(page).to have_content(snippet_notes[0].note)
|
|
|
|
expect(page).to have_selector('.js-note-delete')
|
|
|
|
expect(page).to have_selector('.note-emoji-button')
|
|
|
|
end
|
|
|
|
|
2017-06-27 11:41:56 -04:00
|
|
|
find('body').click # close dropdown
|
2017-06-07 14:33:50 -04:00
|
|
|
open_more_actions_dropdown(snippet_notes[1])
|
|
|
|
|
2017-04-27 06:41:26 -04:00
|
|
|
page.within("#notes-list li#note_#{snippet_notes[1].id}") do
|
|
|
|
expect(page).to have_content(snippet_notes[1].note)
|
|
|
|
expect(page).not_to have_selector('.js-note-delete')
|
|
|
|
expect(page).to have_selector('.note-emoji-button')
|
|
|
|
end
|
|
|
|
end
|
2018-07-16 12:18:52 -04:00
|
|
|
|
|
|
|
it 'shows the status of a note author' do
|
|
|
|
status = create(:user_status, user: user)
|
|
|
|
visit snippet_path(snippet)
|
|
|
|
|
|
|
|
within("#note_#{snippet_notes[0].id}") do
|
|
|
|
expect(page).to show_user_status(status)
|
|
|
|
end
|
|
|
|
end
|
2017-04-27 06:41:26 -04:00
|
|
|
end
|
2017-05-03 04:48:01 -04:00
|
|
|
|
|
|
|
context 'when submitting a note' do
|
|
|
|
it 'shows a valid form' do
|
|
|
|
is_expected.to have_css('.js-main-target-form', visible: true, count: 1)
|
2017-06-21 09:48:12 -04:00
|
|
|
expect(find('.js-main-target-form .js-comment-button').value)
|
|
|
|
.to eq('Comment')
|
2017-05-03 04:48:01 -04:00
|
|
|
|
|
|
|
page.within('.js-main-target-form') do
|
|
|
|
expect(page).not_to have_link('Cancel')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'previews a note' do
|
|
|
|
fill_in 'note[note]', with: 'This is **awesome**!'
|
|
|
|
find('.js-md-preview-button').click
|
|
|
|
|
|
|
|
page.within('.new-note .md-preview') do
|
|
|
|
expect(page).to have_content('This is awesome!')
|
|
|
|
expect(page).to have_selector('strong')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates a note' do
|
|
|
|
fill_in 'note[note]', with: 'This is **awesome**!'
|
|
|
|
click_button 'Comment'
|
|
|
|
|
|
|
|
expect(find('div#notes')).to have_content('This is awesome!')
|
|
|
|
end
|
2017-06-12 15:42:12 -04:00
|
|
|
|
|
|
|
it 'should not have autocomplete' do
|
|
|
|
wait_for_requests
|
|
|
|
|
|
|
|
find('#note_note').native.send_keys('')
|
|
|
|
fill_in 'note[note]', with: '@'
|
|
|
|
|
|
|
|
wait_for_requests
|
|
|
|
|
|
|
|
# This selector probably won't be in place even if autocomplete was enabled
|
|
|
|
# but we want to make sure
|
|
|
|
expect(page).not_to have_selector('.atwho-view')
|
|
|
|
end
|
2017-05-03 04:48:01 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when editing a note' do
|
|
|
|
it 'changes the text' do
|
2017-09-26 11:30:26 -04:00
|
|
|
find('.js-note-edit').click
|
2017-05-03 04:48:01 -04:00
|
|
|
|
|
|
|
page.within('.current-note-edit-form') do
|
|
|
|
fill_in 'note[note]', with: 'new content'
|
2018-09-18 05:58:22 -04:00
|
|
|
find('.btn-success').click
|
2017-05-03 04:48:01 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
page.within("#notes-list li#note_#{snippet_notes[0].id}") do
|
2017-05-08 07:06:09 -04:00
|
|
|
edited_text = find('.edited-text')
|
|
|
|
|
2017-05-03 04:48:01 -04:00
|
|
|
expect(page).to have_css('.note_edited_ago')
|
|
|
|
expect(page).to have_content('new content')
|
2017-05-08 07:06:09 -04:00
|
|
|
expect(edited_text).to have_selector('.note_edited_ago')
|
2017-05-03 04:48:01 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when deleting a note' do
|
|
|
|
it 'removes the note from the snippet detail page' do
|
2017-06-07 14:33:50 -04:00
|
|
|
open_more_actions_dropdown(snippet_notes[0])
|
|
|
|
|
2017-05-03 04:48:01 -04:00
|
|
|
page.within("#notes-list li#note_#{snippet_notes[0].id}") do
|
2017-10-24 09:59:29 -04:00
|
|
|
accept_confirm { click_on 'Delete comment' }
|
2017-05-03 04:48:01 -04:00
|
|
|
end
|
|
|
|
|
2017-05-17 14:25:13 -04:00
|
|
|
wait_for_requests
|
2017-05-03 04:48:01 -04:00
|
|
|
|
|
|
|
expect(page).not_to have_selector("#notes-list li#note_#{snippet_notes[0].id}")
|
|
|
|
end
|
|
|
|
end
|
2017-04-27 06:41:26 -04:00
|
|
|
end
|