Relocate all the things
This commit is contained in:
17
tests/lib/clone.js
Normal file
17
tests/lib/clone.js
Normal file
@@ -0,0 +1,17 @@
|
||||
var tape = require("tape")
|
||||
|
||||
var clone = require("../../lib/clone")
|
||||
|
||||
tape("test clone method", function(t) {
|
||||
var obj = {one: 1, two: 2}
|
||||
var cloned = clone(obj)
|
||||
|
||||
t.notEqual(obj, cloned, "cloned object isn't the object")
|
||||
|
||||
t.same(obj, cloned, "cloned object have the same values than object")
|
||||
|
||||
cloned.tree = 3
|
||||
t.notSame(obj, cloned, "modified cloned object haven't the same values than object")
|
||||
|
||||
t.end()
|
||||
})
|
||||
22
tests/lib/eval-scripts.js
Normal file
22
tests/lib/eval-scripts.js
Normal file
@@ -0,0 +1,22 @@
|
||||
var tape = require("tape")
|
||||
|
||||
var evalScript = require("../../lib/eval-script")
|
||||
|
||||
tape("test evalScript method", function(t) {
|
||||
document.body.className = ""
|
||||
|
||||
var script = document.createElement("script")
|
||||
script.innerHTML = "document.body.className = 'executed'"
|
||||
|
||||
t.equal(document.body.className, "", "script hasn't been executed yet")
|
||||
|
||||
evalScript(script)
|
||||
t.equal(document.body.className, "executed", "script has been properly executed")
|
||||
|
||||
// script.innerHTML = "document.write('failure')"
|
||||
// var bodyText = document.body.text
|
||||
// evalScript(script)
|
||||
// t.equal(document.body.text, bodyText, "document.write hasn't been executed")
|
||||
|
||||
t.end()
|
||||
})
|
||||
92
tests/lib/events.js
Normal file
92
tests/lib/events.js
Normal file
@@ -0,0 +1,92 @@
|
||||
var tape = require("tape")
|
||||
|
||||
var on = require("../../lib/events/on")
|
||||
var off = require("../../lib/events/off")
|
||||
var trigger = require("../../lib/events/trigger")
|
||||
|
||||
var el = document.createElement("div")
|
||||
var el2 = document.createElement("span")
|
||||
var els = [el, el2]
|
||||
var eventType2 = "resize"
|
||||
var eventsType = "click resize"
|
||||
var classCb = function() {
|
||||
this.className += "on"
|
||||
}
|
||||
var attrCb = function() {
|
||||
this.setAttribute("data-state", this.getAttribute("data-state") + "ON")
|
||||
}
|
||||
|
||||
tape("test events on/off/trigger for one element, one event", function(t) {
|
||||
el.className = ""
|
||||
on(el, "click", classCb)
|
||||
trigger(el, "click")
|
||||
t.equal(el.className, "on", "attached callback has been fired properly")
|
||||
|
||||
el.className = "off"
|
||||
off(el, "click", classCb)
|
||||
trigger(el, "click")
|
||||
t.equal(el.className, "off", "triggered event didn't fire detached callback")
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape("test events on/off/trigger for multiple elements, one event", function(t) {
|
||||
el.className = ""
|
||||
el2.className = ""
|
||||
|
||||
on(els, "click", classCb)
|
||||
trigger(els, "click")
|
||||
t.equal(el.className, "on", "attached callback has been fired properly on the first element")
|
||||
t.equal(el2.className, "on", "attached callback has been fired properly on the second element")
|
||||
|
||||
el.className = "off"
|
||||
el2.className = "off"
|
||||
off(els, "click", classCb)
|
||||
trigger(els, "click")
|
||||
t.equal(el.className, "off", "triggered event didn't fire detached callback on the first element")
|
||||
t.equal(el2.className, "off", "triggered event didn't fire detached callback on the second element")
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape("test events on/off/trigger for one element, multiple events", function(t) {
|
||||
el.className = ""
|
||||
on(el, "click mouseover", classCb)
|
||||
trigger(el, "click mouseover")
|
||||
t.equal(el.className, "onon", "attached callbacks have been fired properly")
|
||||
|
||||
el.className = "off"
|
||||
off(el, "click mouseover", classCb)
|
||||
trigger(el, "click mouseover")
|
||||
t.equal(el.className, "off", "triggered events didn't fire detached callback")
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape("test events on/off/trigger for multiple elements, multiple events", function(t) {
|
||||
el.className = ""
|
||||
el2.className = ""
|
||||
el.setAttribute("data-state", "")
|
||||
el2.setAttribute("data-state", "")
|
||||
on(els, "click mouseover", classCb)
|
||||
on(els, "resize scroll", attrCb)
|
||||
trigger(els, "click mouseover resize scroll")
|
||||
t.equal(el.className, "onon", "attached callbacks has been fired properly on the first element")
|
||||
t.equal(el.getAttribute("data-state"), "ONON", "attached callbacks has been fired properly on the first element")
|
||||
t.equal(el2.className, "onon", "attached callbacks has been fired properly on the second element")
|
||||
t.equal(el2.getAttribute("data-state"), "ONON", "attached callbacks has been fired properly on the second element")
|
||||
|
||||
el.className = "off"
|
||||
el2.className = "off"
|
||||
el.setAttribute("data-state", "off")
|
||||
el2.setAttribute("data-state", "off")
|
||||
off(els, "click mouseover", classCb)
|
||||
off(els, "resize scroll", attrCb)
|
||||
trigger(els, "click mouseover resize scroll")
|
||||
t.equal(el.className, "off", "triggered events didn't fire detached callbacks on the first element")
|
||||
t.equal(el.getAttribute("data-state"), "off", "triggered events didn't fire detached callbacks on the first element")
|
||||
t.equal(el2.className, "off", "triggered events didn't fire detached callbacks on the first element")
|
||||
t.equal(el2.getAttribute("data-state"), "off", "triggered events didn't fire detached callbacks on the first element")
|
||||
|
||||
t.end()
|
||||
})
|
||||
16
tests/lib/execute-scripts.js
Normal file
16
tests/lib/execute-scripts.js
Normal file
@@ -0,0 +1,16 @@
|
||||
var tape = require("tape")
|
||||
|
||||
var executeScripts = require("../../lib/execute-scripts")
|
||||
|
||||
tape("test executeScripts method", function(t) {
|
||||
document.body.className = ""
|
||||
|
||||
var container = document.createElement("div")
|
||||
container.innerHTML = "<" + "script" + ">document.body.className = 'executed';</" + "script" + "><" + "script" + ">document.body.className += ' correctly';</" + "script" + ">"
|
||||
|
||||
t.equal(document.body.className, "", "script hasn't been executed yet")
|
||||
executeScripts(container)
|
||||
t.equal(document.body.className, "executed correctly", "script has been properly executed")
|
||||
|
||||
t.end()
|
||||
})
|
||||
45
tests/lib/foreach-els.js
Normal file
45
tests/lib/foreach-els.js
Normal file
@@ -0,0 +1,45 @@
|
||||
var tape = require("tape")
|
||||
|
||||
var forEachEls = require("../../lib/foreach-els.js")
|
||||
|
||||
var div = document.createElement("div")
|
||||
var span = document.createElement("span")
|
||||
var cb = function(el) {
|
||||
el.innerHTML = "boom"
|
||||
}
|
||||
|
||||
tape("test forEachEls on one element", function(t) {
|
||||
div.innerHTML = "div tag"
|
||||
forEachEls(div, cb)
|
||||
|
||||
t.equal(div.innerHTML, "boom", "works correctly on one element")
|
||||
t.end()
|
||||
})
|
||||
|
||||
|
||||
tape("test forEachEls on an array", function(t) {
|
||||
div.innerHTML = "div tag"
|
||||
span.innerHTML = "span tag"
|
||||
|
||||
forEachEls([div, span], cb)
|
||||
|
||||
t.equal(div.innerHTML, "boom", "works correctly on the first element of the array")
|
||||
t.equal(span.innerHTML, "boom", "works correctly on the last element of the array")
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape("test forEachEls on a NodeList", function(t) {
|
||||
div.innerHTML = "div tag"
|
||||
span.innerHTML = "span tag"
|
||||
|
||||
var frag = document.createDocumentFragment()
|
||||
frag.appendChild(div)
|
||||
frag.appendChild(span)
|
||||
forEachEls(frag.childNodes, cb)
|
||||
|
||||
t.equal(div.innerHTML, "boom", "works correctly on the first element of the document fragment")
|
||||
t.equal(span.innerHTML, "boom", "works correctly on the last element of the document fragment")
|
||||
|
||||
t.end()
|
||||
})
|
||||
24
tests/lib/foreach-selectors.js
Normal file
24
tests/lib/foreach-selectors.js
Normal file
@@ -0,0 +1,24 @@
|
||||
var tape = require("tape")
|
||||
|
||||
var forEachEls = require("../../lib/foreach-selectors.js")
|
||||
|
||||
var cb = function(el) {
|
||||
el.className = "modified"
|
||||
}
|
||||
|
||||
tape("test forEachSelector", function(t) {
|
||||
forEachEls(["html", "body"], cb)
|
||||
|
||||
t.equal(document.documentElement.className, "modified", "callback has been executed on first selector")
|
||||
t.equal(document.body.className, "modified", "callback has been executed on first selector")
|
||||
|
||||
document.documentElement.className = ""
|
||||
document.body.className = ""
|
||||
|
||||
forEachEls(["html", "body"], cb, null, document.documentElement)
|
||||
|
||||
t.equal(document.documentElement.className, "", "callback has not been executed on first selector when context is used")
|
||||
t.equal(document.body.className, "modified", "callback has been executed on first selector when context is used")
|
||||
|
||||
t.end()
|
||||
})
|
||||
8
tests/lib/is-supported.js
Normal file
8
tests/lib/is-supported.js
Normal file
@@ -0,0 +1,8 @@
|
||||
var tape = require("tape")
|
||||
|
||||
var isSupported = require("../../lib/is-supported.js")
|
||||
|
||||
tape("test isSupported method", function(t) {
|
||||
t.true(isSupported(), "well, we run test on supported browser, so it should be ok here")
|
||||
t.end()
|
||||
})
|
||||
58
tests/lib/proto/attach-link.js
Normal file
58
tests/lib/proto/attach-link.js
Normal file
@@ -0,0 +1,58 @@
|
||||
var tape = require("tape")
|
||||
|
||||
var on = require("../../../lib/events/on")
|
||||
var trigger = require("../../../lib/events/trigger")
|
||||
var attachLink = require("../../../lib/proto/attach-link")
|
||||
|
||||
var a = document.createElement("a")
|
||||
var attr = "data-pjax-click-state"
|
||||
var preventDefault = function(e) { e.preventDefault() }
|
||||
|
||||
tape("test attach link prototype method", function(t) {
|
||||
t.plan(7)
|
||||
|
||||
attachLink.call({
|
||||
options: {},
|
||||
refresh: function() {
|
||||
t.equal(a.getAttribute(attr), "refresh", "triggering exact same url refresh the page")
|
||||
},
|
||||
loadUrl: function() {
|
||||
t.equal(a.getAttribute(attr), "load", "triggering a internal link actually load the page")
|
||||
}
|
||||
}, a)
|
||||
|
||||
var internalUri = window.location.protocol + "//" + window.location.host + window.location.pathname + window.location.search
|
||||
|
||||
a.href = internalUri
|
||||
on(a, "click", preventDefault) // to avoid link to be open (break testing env)
|
||||
trigger(a, "click", {metaKey: true})
|
||||
t.equal(a.getAttribute(attr), "modifier", "event key modifier stop behavior")
|
||||
|
||||
a.href = "http://external.com/"
|
||||
trigger(a, "click")
|
||||
t.equal(a.getAttribute(attr), "external", "external url stop behavior")
|
||||
|
||||
a.href = internalUri + "#anchor"
|
||||
trigger(a, "click")
|
||||
t.equal(a.getAttribute(attr), "anchor-present", "internal anchor stop behavior")
|
||||
|
||||
window.location.hash = "#anchor"
|
||||
a.href = internalUri + "#another-anchor"
|
||||
trigger(a, "click")
|
||||
t.notEqual(a.getAttribute(attr), "anchor", "differents anchors stop behavior")
|
||||
window.location.hash = ""
|
||||
|
||||
a.href = internalUri + "#"
|
||||
trigger(a, "click")
|
||||
t.equal(a.getAttribute(attr), "anchor-empty", "empty anchor stop behavior")
|
||||
|
||||
a.href = internalUri
|
||||
trigger(a, "click")
|
||||
// see refresh defined above
|
||||
|
||||
a.href = window.location.protocol + "//" + window.location.host + "/internal"
|
||||
trigger(a, "click")
|
||||
// see loadUrl defined above
|
||||
|
||||
t.end()
|
||||
})
|
||||
18
tests/lib/proto/parse-element.js
Normal file
18
tests/lib/proto/parse-element.js
Normal file
@@ -0,0 +1,18 @@
|
||||
var tape = require("tape")
|
||||
|
||||
var parseElement = require("../../../lib/proto/parse-element")
|
||||
var protoMock = {attachLink: function() { return true}}
|
||||
tape("test parse element prototype method", function(t) {
|
||||
|
||||
t.doesNotThrow(function() {
|
||||
var a = document.createElement("a")
|
||||
parseElement.call(protoMock, a)
|
||||
}, "<a> element can be parsed")
|
||||
|
||||
t.throws(function() {
|
||||
var form = document.createElement("form")
|
||||
parseElement.call(protoMock, form)
|
||||
}, "<form> cannot be used (for now)")
|
||||
|
||||
t.end()
|
||||
})
|
||||
16
tests/lib/request.js
Normal file
16
tests/lib/request.js
Normal file
@@ -0,0 +1,16 @@
|
||||
var tape = require("tape")
|
||||
|
||||
var request = require("../../lib/request.js")
|
||||
|
||||
tape("test xhr request", function(t) {
|
||||
var xhr = request("https://api.github.com/", function(result) {
|
||||
try {
|
||||
result = JSON.parse(result)
|
||||
}
|
||||
catch (e) {
|
||||
t.fail("xhr doesn't get a JSON response")
|
||||
}
|
||||
t.same(typeof result, "object", "xhr request get a result")
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
9
tests/lib/switch-selectors.js
Normal file
9
tests/lib/switch-selectors.js
Normal file
@@ -0,0 +1,9 @@
|
||||
var tape = require("tape")
|
||||
|
||||
var switchesSelectors = require("../../lib/switches-selectors.js")
|
||||
|
||||
tape("test switchesSelectors", function(t) {
|
||||
t.fail()
|
||||
|
||||
t.end()
|
||||
})
|
||||
Reference in New Issue
Block a user