2019-07-25 01:24:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-10 07:13:33 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-16 14:09:01 -04:00
|
|
|
RSpec.describe 'Create notes on issues', :js do
|
2017-05-10 07:13:33 -04:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
2018-08-28 12:19:52 -04:00
|
|
|
def submit_comment(text)
|
|
|
|
fill_in 'note[note]', with: text
|
|
|
|
click_button 'Comment'
|
|
|
|
wait_for_requests
|
|
|
|
end
|
|
|
|
|
2017-05-10 07:13:33 -04:00
|
|
|
shared_examples 'notes with reference' do
|
|
|
|
let(:issue) { create(:issue, project: project) }
|
|
|
|
let(:note_text) { "Check #{mention.to_reference}" }
|
|
|
|
|
|
|
|
before do
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_developer(user)
|
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-10 07:13:33 -04:00
|
|
|
|
2018-08-28 12:19:52 -04:00
|
|
|
submit_comment(note_text)
|
2017-05-10 07:13:33 -04:00
|
|
|
end
|
|
|
|
|
2019-10-23 05:06:03 -04:00
|
|
|
it 'creates a note with reference and cross references the issue', :sidekiq_might_not_need_inline do
|
2017-05-10 07:13:33 -04:00
|
|
|
page.within('div#notes li.note div.note-text') do
|
|
|
|
expect(page).to have_content(note_text)
|
|
|
|
expect(page.find('a')).to have_content(mention.to_reference)
|
|
|
|
end
|
|
|
|
|
|
|
|
find('div#notes li.note div.note-text a').click
|
|
|
|
|
|
|
|
page.within('div#notes li.note .system-note-message') do
|
|
|
|
expect(page).to have_content('mentioned in issue')
|
|
|
|
expect(page.find('a')).to have_content(issue.to_reference)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'mentioning issue on a private project' do
|
|
|
|
it_behaves_like 'notes with reference' do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project, :private) }
|
2017-05-10 07:13:33 -04:00
|
|
|
let(:mention) { create(:issue, project: project) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'mentioning issue on an internal project' do
|
|
|
|
it_behaves_like 'notes with reference' do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project, :internal) }
|
2017-05-10 07:13:33 -04:00
|
|
|
let(:mention) { create(:issue, project: project) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'mentioning issue on a public project' do
|
|
|
|
it_behaves_like 'notes with reference' do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project, :public) }
|
2017-05-10 07:13:33 -04:00
|
|
|
let(:mention) { create(:issue, project: project) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'mentioning merge request on a private project' do
|
|
|
|
it_behaves_like 'notes with reference' do
|
2017-07-26 17:49:06 -04:00
|
|
|
let(:project) { create(:project, :private, :repository) }
|
2017-05-10 07:13:33 -04:00
|
|
|
let(:mention) { create(:merge_request, source_project: project) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'mentioning merge request on an internal project' do
|
|
|
|
it_behaves_like 'notes with reference' do
|
2017-07-26 17:49:06 -04:00
|
|
|
let(:project) { create(:project, :internal, :repository) }
|
2017-05-10 07:13:33 -04:00
|
|
|
let(:mention) { create(:merge_request, source_project: project) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'mentioning merge request on a public project' do
|
|
|
|
it_behaves_like 'notes with reference' do
|
2017-07-26 17:49:06 -04:00
|
|
|
let(:project) { create(:project, :public, :repository) }
|
2017-05-10 07:13:33 -04:00
|
|
|
let(:mention) { create(:merge_request, source_project: project) }
|
|
|
|
end
|
|
|
|
end
|
2018-08-28 12:19:52 -04:00
|
|
|
|
|
|
|
it 'highlights the current user in a comment' do
|
|
|
|
project = create(:project)
|
|
|
|
issue = create(:issue, project: project)
|
|
|
|
project.add_developer(user)
|
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
visit project_issue_path(project, issue)
|
|
|
|
submit_comment("@#{user.username} note to self")
|
|
|
|
|
|
|
|
expect(page).to have_selector '.gfm-project_member.current-user', text: user.username
|
|
|
|
end
|
2022-02-03 19:13:53 -05:00
|
|
|
|
|
|
|
shared_examples "when reference belongs to a private project" do
|
|
|
|
let(:project) { create(:project, :private, :repository) }
|
|
|
|
let(:issue) { create(:issue, project: project) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the user does not have permission to see the reference' do
|
|
|
|
before do
|
|
|
|
project.add_guest(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not show the user the reference' do
|
|
|
|
visit project_issue_path(project, issue)
|
|
|
|
|
|
|
|
expect(page).not_to have_content('closed via')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the user has permission to see the reference' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows the user the reference' do
|
|
|
|
visit project_issue_path(project, issue)
|
|
|
|
|
|
|
|
page.within('div#notes li.note .system-note-message') do
|
|
|
|
expect(page).to have_content('closed via')
|
|
|
|
expect(page.find('a')).to have_content(reference_content)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the issue is closed via a merge request' do
|
|
|
|
it_behaves_like "when reference belongs to a private project" do
|
|
|
|
let(:reference) { create(:merge_request, source_project: project) }
|
|
|
|
let(:reference_content) { reference.to_reference }
|
|
|
|
|
|
|
|
before do
|
|
|
|
create(:resource_state_event, issue: issue, state: :closed, created_at: '2020-02-05', source_merge_request: reference)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the issue is closed via a commit' do
|
|
|
|
it_behaves_like "when reference belongs to a private project" do
|
|
|
|
let(:reference) { create(:commit, project: project) }
|
|
|
|
let(:reference_content) { reference.short_sha }
|
|
|
|
|
|
|
|
before do
|
|
|
|
create(:resource_state_event, issue: issue, state: :closed, created_at: '2020-02-05', source_commit: reference.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-05-10 07:13:33 -04:00
|
|
|
end
|