Skip to content

Commit

Permalink
Merge branch 'main' into test/note-comment-response
Browse files Browse the repository at this point in the history
  • Loading branch information
noi5e authored Dec 14, 2020
2 parents a5d4ace + 1afa0a1 commit 7f5b8a6
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 27 deletions.
7 changes: 7 additions & 0 deletions test/fixtures/comments.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,13 @@ comment_by_first_time_user:
timestamp: <%= Time.now.to_i + 10 %>
thread: /01

reply_to_this_comment:
uid: 1
nid: 37
status: 1
comment: Uhh...
timestamp: <%= Time.now.to_i + 10 %>

note_comment_for_responses:
uid: 1
nid: 38
Expand Down
24 changes: 12 additions & 12 deletions test/fixtures/nodes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -446,18 +446,6 @@ sun_question:
cached_likes: 0
slug: "note-tagged-with-question-sun"

comment_note: # for testing comments on notes
nid: 38
uid: 2
title: "Please don't comment here"
path: "/notes/jeff/12-08-2020/please-don-t-comment-here"
created: <%= DateTime.new(2020,12,8).to_i %>
changed: <%= DateTime.new(2020,12,8).to_i %>
status: 1
type: "note"
cached_likes: 0
slug: "note-please-don-t-comment-here"

question4: # for testing comments on questions
nid: 37
uid: 2
Expand All @@ -469,3 +457,15 @@ question4: # for testing comments on questions
type: "note"
cached_likes: 0
slug: jeff-12-07-2020-can-i-post-comments-here

comment_note: # for testing comments on notes
nid: 38
uid: 2
title: "Please don't comment here"
path: "/notes/jeff/12-08-2020/please-don-t-comment-here"
created: <%= DateTime.new(2020,12,8).to_i %>
changed: <%= DateTime.new(2020,12,8).to_i %>
status: 1
type: "note"
cached_likes: 0
slug: "note-please-don-t-comment-here"
17 changes: 9 additions & 8 deletions test/fixtures/revisions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -403,18 +403,19 @@ sun_question:
timestamp: <%= DateTime.new(2020,2,12).to_i %>
status: 1

question4: # for testing comments on questions
nid: 37
uid: 2
title: "Can I post comments here"
body: "I'm gonna do it"
timestamp: <%= DateTime.new(2020,12,7).to_i %>
status: 1

comment_note: # for testing comments on notes
nid: 38
uid: 2
title: "Please don't comment here"
body: "I beg you, please"
timestamp: <%= DateTime.new(2020,12,8).to_i %>
status: 1

question4: # for testing comments on questions
nid: 37
uid: 2
title: "Can I post comments here"
body: "I'm gonna do it"
timestamp: <%= DateTime.new(2020,12,7).to_i %>
status: 1

4 changes: 2 additions & 2 deletions test/functional/notes_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ def teardown

assert_response :success
selector = css_select 'div.note'
assert_equal 27, selector.size
assert_equal 28, selector.size
assert_select "div p", 'Pending approval by community moderators. Please be patient!'
end

Expand Down Expand Up @@ -397,7 +397,7 @@ def teardown

assert_response :success
selector = css_select 'div.note'
assert_equal 27, selector.size
assert_equal 28, selector.size
assert_select 'a[data-test="spam"]','Spam'
end

Expand Down
28 changes: 24 additions & 4 deletions test/system/comment_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def setup
find(".login-modal-form #login-button").click()
end

test 'adding a comment via javascript' do
test 'wiki: comment via JavaScript, with comment body ONLY' do
visit "/wiki/wiki-page-path/comments"

# run the javascript function
Expand All @@ -25,7 +25,7 @@ def setup
assert_selector('#comments-list .comment-body p', text: 'fantastic four')
end

test 'adding a comment via javascript with url only' do
test 'wiki: comment via JavaScript, with comment body + URL' do
visit "/wiki/wiki-page-path/comments"

# run the javascript function
Expand All @@ -35,7 +35,7 @@ def setup
assert_selector('#comments-list .comment-body p', text: 'superhero')
end

test 'adding a reply comment via javascript with url only' do
test 'wiki: reply to comment via JavaScript with comment body + URL' do
visit "/wiki/wiki-page-path/comments"

# run the javascript function
Expand All @@ -47,6 +47,12 @@ def setup
assert_selector("#{parentid} .comment .comment-body p", text: 'batman')
end

test 'note: comment via JavaScript, with comment body + URL' do
visit nodes(:comment_note).path
page.evaluate_script("addComment('hahaha', '/comment/create/38')")
assert_selector('#comments-list .comment-body p', text: 'hahaha')
end

test 'note: respond to existing comment' do
visit nodes(:comment_note).path
# find comment ID of the first comment on page
Expand All @@ -60,7 +66,7 @@ def setup
assert_selector("#{parent_id} .comment .comment-body p", text: 'I admire you')
end

test "add a comment manually" do
test "note: comment manually" do
visit nodes(:one).path

fill_in("body", with: "Awesome comment! :)")
Expand Down Expand Up @@ -89,6 +95,20 @@ def setup
page.evaluate_script("addComment('yes you can', '/comment/create/37')")
assert_selector('#comments-list .comment-body p', text: 'yes you can')
end

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

# find comment ID of the first comment on page
parent_id = "#" + page.find('#comments-list').first('.comment')[:id]
parent_id_num = /c(\d+)/.match(parent_id)[1] # eg. comment ID format is id="c9834"

# addComment(comment text, submitURL, comment's parent ID)
page.evaluate_script("addComment(\"no you can't\", '/comment/create/37', #{parent_id_num})")

# check for comment text
assert_selector("#{parent_id} .comment .comment-body p", text: 'no you can\'t')
end

test 'comment preview button' do
visit "/wiki/wiki-page-path/comments"
Expand Down
2 changes: 1 addition & 1 deletion test/unit/node_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ def setup
nodes(:draft), nodes(:post_test1), nodes(:post_test2),
nodes(:post_test3), nodes(:post_test4), nodes(:scraped_image), nodes(:search_trawling),
nodes(:purple_air_without_hyphen), nodes(:purple_air_with_hyphen),
nodes(:sun_note), nodes(:sunny_day_note)]
nodes(:sun_note), nodes(:sunny_day_note), nodes(:comment_note)]
assert_equal expected, notes
end

Expand Down

0 comments on commit 7f5b8a6

Please sign in to comment.