diff --git a/app/assets/javascripts/tagging.js b/app/assets/javascripts/tagging.js index e6b893e19e9..e0dd8b4ade1 100644 --- a/app/assets/javascripts/tagging.js +++ b/app/assets/javascripts/tagging.js @@ -10,6 +10,18 @@ function addTag(tagname, selector) { } +function setupTagDelete(el) { + + el.click(function(e) { + $(this).css('opacity', 0.5) + }) + .bind('ajax:success', function(e, tid){ + $('#tag_' + tid).remove(); + }); + return el; + +} + function initTagForm(node_id, selector) { selector = selector || '#tagform'; @@ -29,9 +41,7 @@ function initTagForm(node_id, selector) { el.find('.tag-input').val("") el.find('.control-group').removeClass('has-error') el.find('.control-group .help-block').remove() - $('#tag_' + tag_id).bind('ajax:success', function(e, tid){ - $('#tag_' + tid).remove() - }); + setupTagDelete($('#tag_' + tag_id + ' .tag-delete')); }) if (response['errors'].length > 0) { el.find('.control-group').addClass('has-error') @@ -48,11 +58,7 @@ function initTagForm(node_id, selector) { el.find('.control-group').append('' + response.responseText + '') }); - // add el.bind('ajax:send' ... (look up event name) and turn tag grey - - $('.tag-delete').bind('ajax:success', function(e, tid){ - $('#tag_' + tid).remove(); - }); + setupTagDelete($('.tag-delete')); el.find('.tag-input').typeahead({ items: 8, @@ -71,4 +77,3 @@ function initTagForm(node_id, selector) { return el; } - diff --git a/app/views/tag/_tagging.html.erb b/app/views/tag/_tagging.html.erb index b0b600ac6b1..6c74c0d9e48 100644 --- a/app/views/tag/_tagging.html.erb +++ b/app/views/tag/_tagging.html.erb @@ -3,10 +3,10 @@

<% @node.community_tags.each do |tag| %> - + /tag/<%= tag.name %>"><%= tag.name %> <% if current_user && (tag.uid == @node.uid || current_user.role == "admin" || current_user.role == "moderator") %> - x + x <% end %> <% end %> diff --git a/spec/javascripts/fixtures/tagging.html b/spec/javascripts/fixtures/tagging.html new file mode 100644 index 00000000000..d5907de8d3b --- /dev/null +++ b/spec/javascripts/fixtures/tagging.html @@ -0,0 +1,11 @@ + + + blog + x + + + +

+ + +
diff --git a/spec/javascripts/tagging_spec.js b/spec/javascripts/tagging_spec.js new file mode 100644 index 00000000000..007bbeb8fc5 --- /dev/null +++ b/spec/javascripts/tagging_spec.js @@ -0,0 +1,56 @@ +//= require application +//= require jasmine-jquery +//= require tagging + +var editor; + +describe("Tagging", function() { + + beforeAll(function() { + + // for phantomjs running + jasmine.getFixtures().fixturesPath="../../spec/javascripts/fixtures"; + + loadFixtures('tagging.html'); + + initTagForm(2); + + }); + + + // this should test addTag(tagname, selector) from tagging.js, which is an ajax request + xit("tests tag deletion", function() { + + $('tags.label:first a.tag-delete').trigger('click'); + + setTimeout(0, function() { + + // expect tag to be greyed out + expect($('tags.label:first a.tag-delete').css('opacity')).toBe(0.5); + + }); + + + }); + + + // this should test addTag(tagname, selector) from tagging.js, which is an ajax request + xit("adds a tag", function(done) { + + addTag('boss'); + + el.bind('ajax:success', function(e, response){ + + // drop the test expectations to the bottom of the task queue + setTimeout(0, function() { + + // assert tag properly constructed here + // expect($('#tag_...).toBe(true); + + done(); + + }); + + }); + +});