New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor JS Function add_tag() and create add_comment() for Javascript API #6422
Changes from all commits
5b51885
b3478f2
9be74a0
a71e1c6
30320ef
0395e81
bb096aa
54fff67
8dc0c8c
2d3c642
08962f6
49008c6
3895a72
85b0497
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Takes in a data object that contains the info to be submitted in the form property: dataString | ||
// and the url to submit to the controller | ||
// Allows data to be submitted from anywhere on the page using Javascript without using the form itself | ||
function sendFormSubmissionAjax(dataObj, submitTo) { | ||
let url = ''; | ||
if(submitTo.slice(0,1) === "/") { | ||
url = submitTo; | ||
} else { | ||
url = $(submitTo).attr('action'); | ||
} | ||
$.ajax({ | ||
url: url, | ||
data: dataObj, | ||
success: (event, success) => { | ||
if (url !== submitTo) { | ||
$(submitTo).trigger('ajax:success', event); | ||
} | ||
} | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
require 'test_helper' | ||
require "application_system_test_case" | ||
# https://guides.rubyonrails.org/testing.html#implementing-a-system-test | ||
|
||
class CommentTest < ApplicationSystemTestCase | ||
Capybara.default_max_wait_time = 60 | ||
|
||
test 'adding a comment via javascript' do | ||
visit '/' | ||
|
||
click_on 'Login' | ||
|
||
fill_in("username-login", with: "jeff") | ||
fill_in("password-signup", with: "secretive") | ||
click_on "Log in" | ||
|
||
visit "/wiki/wiki-page-path/comments" | ||
|
||
# run the javascript function | ||
page.evaluate_script("addComment('fantastic four')") | ||
|
||
# check that the tag showed up on the page | ||
assert_selector('#comments-list .comment-body p', text: 'fantastic four') | ||
end | ||
|
||
test 'adding a comment via javascript with url only' do | ||
visit '/' | ||
|
||
click_on 'Login' | ||
|
||
fill_in("username-login", with: "jeff") | ||
fill_in("password-signup", with: "secretive") | ||
click_on "Log in" | ||
|
||
visit "/wiki/wiki-page-path/comments" | ||
|
||
# run the javascript function | ||
page.evaluate_script("addComment('superhero', '/comment/create/11')") | ||
|
||
# check that the tag showed up on the page | ||
assert_selector('#comments-list .comment-body p', text: 'superhero') | ||
end | ||
|
||
test 'adding a reply comment via javascript with url only' do | ||
visit '/' | ||
|
||
click_on 'Login' | ||
|
||
fill_in("username-login", with: "jeff") | ||
fill_in("password-signup", with: "secretive") | ||
click_on "Log in" | ||
|
||
visit "/wiki/wiki-page-path/comments" | ||
|
||
# run the javascript function | ||
parentid = "#" + page.find('#comments-list').first('.comment')[:id] | ||
parentid_num = parentid.slice(2..-1) | ||
page.evaluate_script("addComment('batman', '/comment/create/11', #{parentid_num})") | ||
|
||
# check that the tag showed up on the page | ||
assert_selector("#{parentid} .comment .comment-body p", text: 'batman') | ||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
require 'test_helper' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wow, really awesome tests!!!! |
||
require "application_system_test_case" | ||
# https://guides.rubyonrails.org/testing.html#implementing-a-system-test | ||
|
||
class TagTest < ApplicationSystemTestCase | ||
Capybara.default_max_wait_time = 60 | ||
|
||
test 'adding a tag via javascript' do | ||
visit '/' | ||
|
||
click_on 'Login' | ||
|
||
fill_in("username-login", with: "jeff") | ||
fill_in("password-signup", with: "secretive") | ||
click_on "Log in" | ||
|
||
visit "/wiki/wiki-page-path" | ||
|
||
# run the javascript function | ||
page.evaluate_script("addTag('bluebell')") | ||
|
||
# check that the tag showed up on the page | ||
assert_selector('.tags-list .tag-name', text: 'bluebell') | ||
|
||
end | ||
|
||
test 'adding a tag via javascript with url only' do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Love this. Just one more question - does adding tags to your profile also still work? I think that might've become broken at some point because we (unfortunately) share code between node tags and user tags, but just curious if this touches that at all? Thanks! |
||
visit '/' | ||
|
||
click_on 'Login' | ||
|
||
fill_in("username-login", with: "jeff") | ||
fill_in("password-signup", with: "secretive") | ||
click_on "Log in" | ||
|
||
visit "/wiki/wiki-page-path" | ||
|
||
# run the javascript function | ||
page.evaluate_script("addTag('roses', '/tag/create/11')") | ||
|
||
visit "/wiki/wiki-page-path" # refresh page | ||
|
||
# check that the tag showed up on the page | ||
assert_selector('.tags-list .card-body h5', text: 'roses') | ||
|
||
end | ||
|
||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉