Skip to content
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 functions add_tag() and create add_comment() for pure JS API #6411

Closed
jywarren opened this issue Oct 7, 2019 · 2 comments · Fixed by #6422
Closed

Refactor JS functions add_tag() and create add_comment() for pure JS API #6411

jywarren opened this issue Oct 7, 2019 · 2 comments · Fixed by #6422
Labels
feature explains that the issue is to add a new feature help wanted requires help by anyone willing to contribute JavaScript testing issues are usually for adding unit tests, integration tests or any other tests for a feature

Comments

@jywarren
Copy link
Member

jywarren commented Oct 7, 2019

We have a JavaScript function to add tags, here:

function addTag(tagname, selector) {
selector = selector || '#tagform';
if (tagname.slice(0,5).toLowerCase() === "place") {
place = tagname.split(":")[1];
place.replace("-", " ");
geo = geocodeStringAndPan(place);
}
else {
var el = $(selector);
el.find('.tag-input').val(tagname);
el.submit();
}
}

However, it uses the on-page HTML tag form to do this. We should be able to do this directly using AJAX without using an HTML form.

Secondly, we should implement the same functionality for an add_comment('Comment body here') function, similarly AJAX based.

Our functional tests show how these should be possible to run directly, instead of via the HTML page:

test 'should create note comments' do
UserSession.create(users(:bob))
assert_difference 'Comment.count' do
post :create, params: { id: nodes(:one).nid, body: '[notes:awesome]' }, xhr: true
end
assert_response :success
assert_not_nil :comment
assert_template partial: 'notes/_comment'
assert_template partial: 'grids/_notes'
# assert_equal 1, css_select(".comment table").size # test inline grid rendering
end

test 'add one or two tags' do
UserSession.create(users(:bob))
post :create, params: { name: 'mytag', nid: nodes(:one).nid, uid: users(:bob).id }

We should create a system test to confirm that these javascript functions actually work! You can run javascript in a system test like this:

assert page.evaluate_script("$('.typeahead.dropdown-menu').is(':visible')")
assert_equal 6, page.evaluate_script("$('.typeahead.dropdown-menu').find('li').length")

@jywarren jywarren added feature explains that the issue is to add a new feature help wanted requires help by anyone willing to contribute JavaScript testing issues are usually for adding unit tests, integration tests or any other tests for a feature labels Oct 7, 2019
@nstjean
Copy link
Contributor

nstjean commented Oct 8, 2019

I'll try this out!

@nstjean
Copy link
Contributor

nstjean commented Oct 8, 2019

So to check in, what we are doing for that tag form is accepting whatever value is sent in and instead of loading it into the HTML form and submitting the form it is instead sending a POST request via AJAX, right?

$.ajax({ async: false, type: 'POST', url: $('#tagform').attr('action'), data: "name+" + tagname })

The URL of the POST request I either have to grab from the form (as above), or I'd have to have some way to pass the node ID value into the function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature explains that the issue is to add a new feature help wanted requires help by anyone willing to contribute JavaScript testing issues are usually for adding unit tests, integration tests or any other tests for a feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants