2015-12-12 17:42:52 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-06-29 00:13:10 -04:00
|
|
|
feature 'Issue notes polling', :js do
|
2017-06-07 14:33:50 -04:00
|
|
|
include NoteInteractionHelpers
|
|
|
|
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project, :public) }
|
2017-04-19 15:48:48 -04:00
|
|
|
let(:issue) { create(:issue, project: project) }
|
2015-12-12 17:42:52 -05:00
|
|
|
|
2017-05-03 13:41:16 -04:00
|
|
|
describe 'creates' do
|
|
|
|
before do
|
2017-07-06 12:20:50 -04:00
|
|
|
visit project_issue_path(project, issue)
|
2017-05-03 13:41:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'displays the new comment' do
|
|
|
|
note = create(:note, noteable: issue, project: project, note: 'Looks good!')
|
2017-07-17 13:12:55 -04:00
|
|
|
wait_for_requests
|
2017-05-03 13:41:16 -04:00
|
|
|
|
|
|
|
expect(page).to have_selector("#note_#{note.id}", text: 'Looks good!')
|
|
|
|
end
|
2015-12-12 17:42:52 -05:00
|
|
|
end
|
|
|
|
|
2017-05-03 13:41:16 -04:00
|
|
|
describe 'updates' do
|
2017-05-18 03:46:44 -04:00
|
|
|
context 'when from own user' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:note_text) { "Hello World" }
|
|
|
|
let(:updated_text) { "Bye World" }
|
|
|
|
let!(:existing_note) { create(:note, noteable: issue, project: project, author: user, note: note_text) }
|
2017-05-03 13:41:16 -04:00
|
|
|
|
2017-05-18 03:46:44 -04:00
|
|
|
before do
|
2017-06-21 19:44:10 -04:00
|
|
|
sign_in(user)
|
2017-07-06 12:20:50 -04:00
|
|
|
visit project_issue_path(project, issue)
|
2017-05-18 03:46:44 -04:00
|
|
|
end
|
2017-05-03 13:41:16 -04:00
|
|
|
|
2017-05-18 03:46:44 -04:00
|
|
|
it 'displays the updated content' do
|
|
|
|
expect(page).to have_selector("#note_#{existing_note.id}", text: note_text)
|
2017-05-03 13:41:16 -04:00
|
|
|
|
2017-05-18 03:46:44 -04:00
|
|
|
update_note(existing_note, updated_text)
|
2017-05-03 13:41:16 -04:00
|
|
|
|
2017-05-18 03:46:44 -04:00
|
|
|
expect(page).to have_selector("#note_#{existing_note.id}", text: updated_text)
|
|
|
|
end
|
2017-05-03 13:41:16 -04:00
|
|
|
|
2017-08-12 18:57:41 -04:00
|
|
|
it 'when editing but have not changed anything, and an update comes in, show warning and does not update the note' do
|
2017-06-07 14:33:50 -04:00
|
|
|
click_edit_action(existing_note)
|
2017-05-03 13:41:16 -04:00
|
|
|
|
2017-08-12 18:57:41 -04:00
|
|
|
expect(page).to have_field("note[note]", with: note_text)
|
2016-04-26 07:52:18 -04:00
|
|
|
|
2017-05-18 03:46:44 -04:00
|
|
|
update_note(existing_note, updated_text)
|
2017-05-03 13:41:16 -04:00
|
|
|
|
2017-08-12 18:57:41 -04:00
|
|
|
expect(page).not_to have_field("note[note]", with: updated_text)
|
2017-05-18 03:46:44 -04:00
|
|
|
expect(page).to have_selector(".alert")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'when editing but you changed some things, an update comes in, and you press cancel, show the updated content' do
|
2017-06-07 14:33:50 -04:00
|
|
|
click_edit_action(existing_note)
|
2017-05-18 03:46:44 -04:00
|
|
|
|
2017-08-12 18:57:41 -04:00
|
|
|
expect(page).to have_field("note[note]", with: note_text)
|
2017-05-18 03:46:44 -04:00
|
|
|
|
|
|
|
update_note(existing_note, updated_text)
|
|
|
|
|
|
|
|
find("#note_#{existing_note.id} .note-edit-cancel").click
|
|
|
|
|
|
|
|
expect(page).to have_selector("#note_#{existing_note.id}", text: updated_text)
|
|
|
|
end
|
|
|
|
end
|
2017-05-03 13:41:16 -04:00
|
|
|
|
2017-05-18 03:46:44 -04:00
|
|
|
context 'when from another user' do
|
|
|
|
let(:user1) { create(:user) }
|
|
|
|
let(:user2) { create(:user) }
|
|
|
|
let(:note_text) { "Hello World" }
|
|
|
|
let(:updated_text) { "Bye World" }
|
|
|
|
let!(:existing_note) { create(:note, noteable: issue, project: project, author: user1, note: note_text) }
|
2017-05-03 13:41:16 -04:00
|
|
|
|
2017-05-18 03:46:44 -04:00
|
|
|
before do
|
2017-06-21 19:44:10 -04:00
|
|
|
sign_in(user2)
|
2017-07-06 12:20:50 -04:00
|
|
|
visit project_issue_path(project, issue)
|
2017-05-18 03:46:44 -04:00
|
|
|
end
|
2017-05-03 13:41:16 -04:00
|
|
|
|
2017-07-17 18:08:00 -04:00
|
|
|
it 'displays the updated content' do
|
2017-05-18 03:46:44 -04:00
|
|
|
expect(page).to have_selector("#note_#{existing_note.id}", text: note_text)
|
2017-05-03 13:41:16 -04:00
|
|
|
|
2017-05-18 03:46:44 -04:00
|
|
|
update_note(existing_note, updated_text)
|
2017-05-03 13:41:16 -04:00
|
|
|
|
2017-05-18 03:46:44 -04:00
|
|
|
expect(page).to have_selector("#note_#{existing_note.id}", text: updated_text)
|
2017-05-19 02:37:53 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'system notes' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:note_text) { "Some system note" }
|
|
|
|
let!(:system_note) { create(:system_note, noteable: issue, project: project, author: user, note: note_text) }
|
|
|
|
|
|
|
|
before do
|
2017-06-21 19:44:10 -04:00
|
|
|
sign_in(user)
|
2017-07-06 12:20:50 -04:00
|
|
|
visit project_issue_path(project, issue)
|
2017-05-19 02:37:53 -04:00
|
|
|
end
|
|
|
|
|
2017-07-17 18:08:00 -04:00
|
|
|
it 'shows the system note' do
|
2017-05-19 02:37:53 -04:00
|
|
|
expect(page).to have_selector("#note_#{system_note.id}", text: note_text)
|
2017-05-18 03:46:44 -04:00
|
|
|
end
|
2017-05-03 13:41:16 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_note(note, new_text)
|
|
|
|
note.update(note: new_text)
|
2017-07-17 13:12:55 -04:00
|
|
|
wait_for_requests
|
2015-12-12 17:42:52 -05:00
|
|
|
end
|
2017-06-07 14:33:50 -04:00
|
|
|
|
|
|
|
def click_edit_action(note)
|
|
|
|
note_element = find("#note_#{note.id}")
|
|
|
|
|
|
|
|
note_element.find('.js-note-edit').click
|
|
|
|
end
|
2015-12-12 17:42:52 -05:00
|
|
|
end
|