Skip to content

Commit

Permalink
[Outreachy Comment Editor] New test: Post comment on question, then r…
Browse files Browse the repository at this point in the history
…espond to it (#8851)

* add test for question: comment then respond

* fixtures for question w/ comment
  • Loading branch information
noi5e authored Dec 15, 2020
1 parent 80648fe commit 4bf41ff
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion test/system/comment_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def setup
assert_selector('#comments-list .comment-body p', text: 'yes you can')
end

test 'question page: respond to existing comment with addComment' do
test 'question page: respond to existing comment' do
visit "/questions/jeff/12-07-2020/can-i-post-comments-here"

# find comment ID of the first comment on page
Expand All @@ -110,6 +110,23 @@ def setup
assert_selector("#{parent_id} .comment .comment-body p", text: 'no you can\'t')
end

test 'question page: reply to freshly posted comment' do
visit nodes(:question4).path
# post new comment
comment_text = 'woot woot'
page.evaluate_script("addComment('#{comment_text}', '/comment/create/#{nodes(:question4).nid}')")
# we need the ID of parent div that contains <p>comment_text</p>:
parent_id = page.find('p', text: comment_text).find(:xpath, '..')[:id]
# regex to strip the ID number out of string. ID format is comment-body-4231
parent_id_num = /comment-body-(\d+)/.match(parent_id)[1]
# reply to comment
comment_response_text = 'wooly woot!'
# addComment(comment text, submitURL, comment's parent ID)
page.evaluate_script("addComment('#{comment_response_text}', '/comment/create/#{nodes(:question4).nid}', #{parent_id_num})")
# assert that <div id="c1show"> has child div[div[p[text="wooly woot!"]]]
assert_selector("#{'#c' + parent_id_num + 'show'} div div div p", text: comment_response_text)
end

test 'comment preview button' do
visit "/wiki/wiki-page-path/comments"

Expand Down

0 comments on commit 4bf41ff

Please sign in to comment.