diff options
author | Marius Mathiesen <marius@shortcut.no> | 2009-11-30 12:09:56 +0100 |
---|---|---|
committer | Marius Mathiesen <marius@shortcut.no> | 2009-12-03 14:18:58 +0100 |
commit | be0fc04cb90d5fa418cf56f2ba96587e4e7919dc (patch) | |
tree | 8a77438f62a657cdb0b27c91ff5765f6cf31c8d3 /test | |
parent | 32790146f73f2ee8538ea236f1dbbc32fb3d6d4b (diff) | |
download | gitorious-mainline-outdated-be0fc04cb90d5fa418cf56f2ba96587e4e7919dc.zip gitorious-mainline-outdated-be0fc04cb90d5fa418cf56f2ba96587e4e7919dc.tar.gz gitorious-mainline-outdated-be0fc04cb90d5fa418cf56f2ba96587e4e7919dc.tar.bz2 |
Giving test coverage to link helper
Diffstat (limited to 'test')
-rw-r--r-- | test/javascripts/rails_form_replacer_test.js | 49 |
1 files changed, 42 insertions, 7 deletions
diff --git a/test/javascripts/rails_form_replacer_test.js b/test/javascripts/rails_form_replacer_test.js index 54b5313..aa8fdb3 100644 --- a/test/javascripts/rails_form_replacer_test.js +++ b/test/javascripts/rails_form_replacer_test.js @@ -18,13 +18,48 @@ */ TestCase("Replace Rails generated forms", { - "test stuff": function () { - /*DOC += <a data-request-method="delete">Foo</a*/ - var clicked = false; - var backend = function (options){ - clicked = true; - }; - var el = jQuery("a[data-request-method]").replaceRailsGeneratedForm(); + setUp: function (){ + /*:DOC += <p id="c"><a data-request-method="delete" id="me" href="/favorites/123">Stop the game</a></p>*/ + }, + "test original link should be replaced": function () { + var elementToReplace = jQuery("[data-request-method]"); + var api = jQuery("#me").replaceRailsGeneratedForm(); + var el = jQuery("a[href='#start_watching']"); assertEquals("start_watching", el.attr("id")); + assertEquals(0, jQuery("[data-request-method]:visible").length); + }, + "test success callback should toggle method": function() { + var api = jQuery("#me").replaceRailsGeneratedForm(); + assertEquals("delete", api.httpMethod()); + api.success(); + assertEquals("post", api.httpMethod()); + api.success(); + assertEquals("delete", api.httpMethod()); + }, + "test success callback should change inner HTML": function (){ + var api = jQuery("#me").replaceRailsGeneratedForm(); + var el = jQuery("#start_watching"); + api.success(); + assertEquals("Start the game", el.html()); + api.success(); + assertEquals("Stop the game", el.html()); + }, + "test complete callback should change location": function () { + var api = jQuery("#me").replaceRailsGeneratedForm(); + api.complete({getResponseHeader: function() {return "/people"}}); + assertEquals("/people", api.action()); + }, + "test should accept custom replacement texts": function () { + /*:DOC += <p id="c"><a data-request-method="post" id="f" href="/favorites/123">Let the party end</a></p>*/ + var api = jQuery("#f").replaceRailsGeneratedForm({replaceWords: ["begin","end"]}); + api.success(); + assertEquals("Let the party end", jQuery("#start_watching").html()); + api.success(); + assertEquals("Let the party begin", jQuery("#start_watching").html()); + }, + "test should accept custom id on inserted elements": function () { + var api = jQuery("#me").replaceRailsGeneratedForm({linkName: "newLink"}); + var el = api.element(); + assertEquals("newLink", el.attr("id")); } }); |