debian-mirror-gitlab/spec/features/issues/note_polling_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

116 lines
3.4 KiB
Ruby
Raw Permalink Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2015-12-23 02:04:40 +05:30
require 'spec_helper'
2023-03-04 22:38:38 +05:30
RSpec.describe 'Issue notes polling', :js, feature_category: :team_planning do
2017-09-10 17:25:29 +05:30
include NoteInteractionHelpers
let(:project) { create(:project, :public) }
2017-08-17 22:00:37 +05:30
let(:issue) { create(:issue, project: project) }
2015-12-23 02:04:40 +05:30
2017-08-17 22:00:37 +05:30
describe 'creates' do
before do
2017-09-10 17:25:29 +05:30
visit project_issue_path(project, issue)
2017-08-17 22:00:37 +05:30
end
it 'displays the new comment' do
note = create(:note, noteable: issue, project: project, note: 'Looks good!')
2018-03-17 18:26:18 +05:30
wait_for_requests
2017-08-17 22:00:37 +05:30
expect(page).to have_selector("#note_#{note.id}", text: 'Looks good!')
end
2015-12-23 02:04:40 +05:30
end
2017-08-17 22:00:37 +05:30
describe 'updates' do
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-08-17 22:00:37 +05:30
before do
2017-09-10 17:25:29 +05:30
sign_in(user)
visit project_issue_path(project, issue)
2017-08-17 22:00:37 +05:30
end
it 'displays the updated content' do
expect(page).to have_selector("#note_#{existing_note.id}", text: note_text)
update_note(existing_note, updated_text)
expect(page).to have_selector("#note_#{existing_note.id}", text: updated_text)
end
2018-03-17 18:26:18 +05:30
it 'when editing but have not changed anything, and an update comes in, show warning and does not update the note' do
2017-09-10 17:25:29 +05:30
click_edit_action(existing_note)
2017-08-17 22:00:37 +05:30
expect(page).to have_field("note[note]", with: note_text)
update_note(existing_note, updated_text)
2018-03-17 18:26:18 +05:30
expect(page).not_to have_field("note[note]", with: updated_text)
2017-08-17 22:00:37 +05:30
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-09-10 17:25:29 +05:30
click_edit_action(existing_note)
2017-08-17 22:00:37 +05:30
expect(page).to have_field("note[note]", with: note_text)
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
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) }
before do
2017-09-10 17:25:29 +05:30
sign_in(user2)
visit project_issue_path(project, issue)
2017-08-17 22:00:37 +05:30
end
2018-03-17 18:26:18 +05:30
it 'displays the updated content' do
2017-08-17 22:00:37 +05:30
expect(page).to have_selector("#note_#{existing_note.id}", text: note_text)
update_note(existing_note, updated_text)
expect(page).to have_selector("#note_#{existing_note.id}", text: updated_text)
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-09-10 17:25:29 +05:30
sign_in(user)
visit project_issue_path(project, issue)
2017-08-17 22:00:37 +05:30
end
2018-03-17 18:26:18 +05:30
it 'shows the system note' do
2017-08-17 22:00:37 +05:30
expect(page).to have_selector("#note_#{system_note.id}", text: note_text)
end
end
end
def update_note(note, new_text)
2021-04-29 21:17:54 +05:30
note.update!(note: new_text)
2018-03-17 18:26:18 +05:30
wait_for_requests
2015-12-23 02:04:40 +05:30
end
2017-09-10 17:25:29 +05:30
def click_edit_action(note)
note_element = find("#note_#{note.id}")
note_element.find('.js-note-edit').click
end
2015-12-23 02:04:40 +05:30
end