2019-07-25 01:24:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-04-03 06:27:56 -04:00
|
|
|
require "spec_helper"
|
|
|
|
|
2020-06-16 14:09:01 -04:00
|
|
|
RSpec.describe "User comments on issue", :js do
|
2018-04-03 06:27:56 -04:00
|
|
|
include Spec::Support::Helpers::Features::NotesHelpers
|
|
|
|
|
|
|
|
let(:project) { create(:project_empty_repo, :public) }
|
|
|
|
let(:issue) { create(:issue, project: project) }
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.add_guest(user)
|
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
visit(project_issue_path(project, issue))
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when adding comments" do
|
|
|
|
it "adds comment" do
|
|
|
|
content = "XML attached"
|
|
|
|
target_form = ".js-main-target-form"
|
|
|
|
|
|
|
|
add_note(content)
|
|
|
|
|
|
|
|
page.within(".note") do
|
|
|
|
expect(page).to have_content(content)
|
|
|
|
end
|
|
|
|
|
|
|
|
page.within(target_form) do
|
|
|
|
find(".error-alert", visible: false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "adds comment with code block" do
|
2018-06-13 15:18:08 -04:00
|
|
|
code_block_content = "Command [1]: /usr/local/bin/git , see [text](doc/text)"
|
|
|
|
comment = "```\n#{code_block_content}\n```"
|
2018-04-03 06:27:56 -04:00
|
|
|
|
|
|
|
add_note(comment)
|
|
|
|
|
2018-06-13 15:18:08 -04:00
|
|
|
wait_for_requests
|
|
|
|
|
|
|
|
expect(page.find('pre code').text).to eq code_block_content
|
2018-04-03 06:27:56 -04:00
|
|
|
end
|
2018-11-28 13:39:27 -05:00
|
|
|
|
2020-01-13 01:08:10 -05:00
|
|
|
it "renders HTML content as text in Mermaid" do
|
2018-11-28 13:39:27 -05:00
|
|
|
html_content = "<img onerror=location=`javascript\\u003aalert\\u0028document.domain\\u0029` src=x>"
|
|
|
|
mermaid_content = "graph LR\n B-->D(#{html_content});"
|
|
|
|
comment = "```mermaid\n#{mermaid_content}\n```"
|
|
|
|
|
|
|
|
add_note(comment)
|
|
|
|
|
|
|
|
wait_for_requests
|
|
|
|
|
2020-01-13 01:08:10 -05:00
|
|
|
expect(page.find('svg.mermaid')).to have_content html_content
|
|
|
|
within('svg.mermaid') { expect(page).not_to have_selector('img') }
|
2018-11-28 13:39:27 -05:00
|
|
|
end
|
2019-09-02 06:42:11 -04:00
|
|
|
|
|
|
|
it 'opens autocomplete menu for quick actions and have `/label` first choice' do
|
|
|
|
project.add_maintainer(user)
|
|
|
|
create(:label, project: project, title: 'label')
|
|
|
|
|
|
|
|
page.within '.timeline-content-form' do
|
|
|
|
find('#note-body').native.send_keys('/l')
|
|
|
|
end
|
|
|
|
|
|
|
|
wait_for_requests
|
|
|
|
|
|
|
|
expect(page).to have_selector('.atwho-container')
|
|
|
|
|
|
|
|
page.within '.atwho-container #at-view-commands' do
|
|
|
|
expect(find('li', match: :first)).to have_content('/label')
|
|
|
|
end
|
|
|
|
end
|
2018-04-03 06:27:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when editing comments" do
|
|
|
|
it "edits comment" do
|
|
|
|
add_note("# Comment with a header")
|
|
|
|
|
|
|
|
page.within(".note-body > .note-text") do
|
|
|
|
expect(page).to have_content("Comment with a header").and have_no_css("#comment-with-a-header")
|
|
|
|
end
|
|
|
|
|
|
|
|
page.within(".main-notes-list") do
|
|
|
|
note = find(".note")
|
|
|
|
|
|
|
|
note.hover
|
|
|
|
note.find(".js-note-edit").click
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(page).to have_css(".current-note-edit-form textarea")
|
|
|
|
|
|
|
|
comment = "+1 Awesome!"
|
|
|
|
|
|
|
|
page.within(".current-note-edit-form") do
|
|
|
|
fill_in("note[note]", with: comment)
|
2018-07-05 07:59:57 -04:00
|
|
|
find('textarea').send_keys [:control, :shift, 'p']
|
|
|
|
expect(page).to have_selector('.current-note-edit-form .md-preview-holder')
|
|
|
|
expect(page.find('.current-note-edit-form .md-preview-holder p')).to have_content(comment)
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(page).to have_selector('.new-note .note-textarea')
|
|
|
|
|
|
|
|
page.within(".current-note-edit-form") do
|
2018-04-03 06:27:56 -04:00
|
|
|
click_button("Save comment")
|
|
|
|
end
|
|
|
|
|
|
|
|
wait_for_requests
|
|
|
|
|
|
|
|
page.within(".note") do
|
|
|
|
expect(page).to have_content(comment)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|