diff --git a/tests/lib/execute-scripts.js b/tests/lib/execute-scripts.js index 2fdd39e..0d93e15 100644 --- a/tests/lib/execute-scripts.js +++ b/tests/lib/execute-scripts.js @@ -14,3 +14,16 @@ tape("test executeScripts method when the script tag is inside a container", fun t.end() }) + +tape("test executeScripts method with just a script tag", function(t) { + document.body.className = "" + + var script = document.createElement("script") + script.innerHTML = "document.body.className = 'executed correctly';" + + t.equal(document.body.className, "", "script hasn't been executed yet") + executeScripts(script) + t.equal(document.body.className, "executed correctly", "script has been properly executed") + + t.end() +}) diff --git a/tests/lib/proto/attach-form.js b/tests/lib/proto/attach-form.js index fbb243d..249afc8 100644 --- a/tests/lib/proto/attach-form.js +++ b/tests/lib/proto/attach-form.js @@ -98,3 +98,57 @@ tape("test options are not modified by attachForm", function(t) { t.end() }) + +tape("test submit triggered by keyboard", function(t) { + var form = document.createElement("form") + var pjax = { + options: {}, + loadUrl: function() { + t.equal(form.getAttribute(attr), "submit", "triggering a internal link actually submits the form") + } + } + + t.plan(2) + + attachForm.call(pjax, form) + + form.action = window.location.protocol + "//" + window.location.host + "/internal" + + trigger(form, "keyup", {keyCode: 14}) + t.equal(form.getAttribute(attr), "", "keycode other than 13 doesn't trigger anything") + + trigger(form, "keyup", {keyCode: 13}) + // see loadUrl defined above + + t.end() +}) + +tape("test form elements parsed correctly", function(t) { + t.plan(1) + + var form = document.createElement("form") + var input = document.createElement("input") + input.name = "input" + input.value = "value" + form.appendChild(input) + + var params = [{ + name: "input", + value: "value" + }] + var pjax = { + options: {}, + loadUrl: function(href, options) { + t.same(options.requestOptions.requestParams, params, "form elements parsed correctly") + } + } + + attachForm.call(pjax, form) + + form.action = window.location.protocol + "//" + window.location.host + "/internal" + + trigger(form, "submit") + // see loadUrl defined above + + t.end() +}) diff --git a/tests/lib/proto/attach-link.js b/tests/lib/proto/attach-link.js index 113ea83..fb88682 100644 --- a/tests/lib/proto/attach-link.js +++ b/tests/lib/proto/attach-link.js @@ -88,3 +88,56 @@ tape("test options are not modified by attachLink", function(t) { t.end() }) + +tape("test link triggered by keyboard", function(t) { + var a = document.createElement("a") + var pjax = { + options: {}, + loadUrl: function() { + t.equal(a.getAttribute(attr), "load", "triggering a internal link actually loads the page") + } + } + + t.plan(3) + + attachLink.call(pjax, a) + + a.href = window.location.protocol + "//" + window.location.host + "/internal" + + trigger(a, "keyup", {keyCode: 14}) + t.equal(a.getAttribute(attr), "", "keycode other than 13 doesn't trigger anything") + + trigger(a, "keyup", {keyCode: 13, metaKey: true}) + t.equal(a.getAttribute(attr), "modifier", "event key modifier stop behavior") + + trigger(a, "keyup", {keyCode: 13}) + // see loadUrl defined above + + t.end() +}) + +tape("test link with the same URL as the current one, when currentUrlFullReload set to true", function(t) { + var a = document.createElement("a") + var pjax = { + options: { + currentUrlFullReload: true + }, + reload: function() { + t.pass("this.reload() was called correctly") + }, + loadUrl: function() { + t.fail("loadUrl() was called wrongly") + } + } + + t.plan(2) + + attachLink.call(pjax, a) + + a.href = window.location.href + + trigger(a, "click") + t.equal(a.getAttribute(attr), "reload", "reload stop behavior") + + t.end() +}) diff --git a/tests/lib/proto/parse-element.js b/tests/lib/proto/parse-element.js index 9d64e34..e58ef67 100644 --- a/tests/lib/proto/parse-element.js +++ b/tests/lib/proto/parse-element.js @@ -18,5 +18,10 @@ tape("test parse element prototype method", function(t) { parseElement.call(pjax, form) }, "