completed the xml tests - and lots of them run successfully
This commit is contained in:
@@ -4,6 +4,7 @@ should = chai.should()
|
||||
sinon = require('sinon')
|
||||
sinonChai = require('sinon-chai')
|
||||
_ = require("underscore")
|
||||
$ = require('jquery')
|
||||
|
||||
chai.use(sinonChai)
|
||||
|
||||
@@ -27,7 +28,7 @@ class XmlTest extends Test
|
||||
super new Y conn
|
||||
|
||||
initUsers: (u)->
|
||||
u.val("xml",new Y.Xml("root"))
|
||||
u.val("xml",new Y.Xml("div"))
|
||||
|
||||
type: "XmlTest"
|
||||
|
||||
@@ -175,7 +176,7 @@ describe "Y-Xml", ->
|
||||
child2 = new Y.Xml("child2")
|
||||
@u1.append child
|
||||
@u1.append child2
|
||||
expect(@u1.toString()).to.equal("<root><child></child><child2></child2></root>")
|
||||
expect(@u1.toString()).to.equal("<div><child></child><child2></child2></div>")
|
||||
@yTest.compareAll()
|
||||
|
||||
it "prepend", ->
|
||||
@@ -183,31 +184,31 @@ describe "Y-Xml", ->
|
||||
child2 = new Y.Xml("child2")
|
||||
@u1.prepend child2
|
||||
@u1.prepend child
|
||||
expect(@u1.toString()).to.equal("<root><child></child><child2></child2></root>")
|
||||
expect(@u1.toString()).to.equal("<div><child></child><child2></child2></div>")
|
||||
@yTest.compareAll()
|
||||
|
||||
it "after", ->
|
||||
child = new Y.Xml("child")
|
||||
@u1.append child
|
||||
child.after new Y.Xml("right-child")
|
||||
expect(@u1.toString()).to.equal("<root><child></child><right-child></right-child></root>")
|
||||
expect(@u1.toString()).to.equal("<div><child></child><right-child></right-child></div>")
|
||||
@yTest.compareAll()
|
||||
|
||||
it "before", ->
|
||||
child = new Y.Xml("child")
|
||||
@u1.append child
|
||||
child.before new Y.Xml("left-child")
|
||||
expect(@u1.toString()).to.equal("<root><left-child></left-child><child></child></root>")
|
||||
expect(@u1.toString()).to.equal("<div><left-child></left-child><child></child></div>")
|
||||
@yTest.compareAll()
|
||||
|
||||
it "empty", ->
|
||||
child = new Y.Xml("child")
|
||||
@u1.append child
|
||||
child.before new Y.Xml("left-child")
|
||||
expect(@u1.toString()).to.equal("<root><left-child></left-child><child></child></root>")
|
||||
expect(@u1.toString()).to.equal("<div><left-child></left-child><child></child></div>")
|
||||
@yTest.compareAll()
|
||||
@u1.empty()
|
||||
expect(@u1.toString()).to.equal("<root></root>")
|
||||
expect(@u1.toString()).to.equal("<div></div>")
|
||||
@yTest.compareAll()
|
||||
|
||||
it "remove", ->
|
||||
@@ -215,10 +216,10 @@ describe "Y-Xml", ->
|
||||
child2 = new Y.Xml("child2")
|
||||
@u1.prepend child2
|
||||
@u1.prepend child
|
||||
expect(@u1.toString()).to.equal("<root><child></child><child2></child2></root>")
|
||||
expect(@u1.toString()).to.equal("<div><child></child><child2></child2></div>")
|
||||
@yTest.compareAll()
|
||||
child2.remove()
|
||||
expect(@u1.toString()).to.equal("<root><child></child></root>")
|
||||
expect(@u1.toString()).to.equal("<div><child></child></div>")
|
||||
|
||||
it "removeAttr", ->
|
||||
@u1.attr("dtrn", "stuff")
|
||||
@@ -258,4 +259,216 @@ describe "Y-Xml", ->
|
||||
@u1.prepend(child)
|
||||
expect(@u1.getChildren()[0]).to.equal(child)
|
||||
|
||||
if not window?
|
||||
describe "skip DOM tests (only in browser environment)", ->
|
||||
it "", ->
|
||||
else
|
||||
describe "DOM binding ", ->
|
||||
beforeEach (done)->
|
||||
@dom = @u1.getDom()
|
||||
@j = $(@dom)
|
||||
done()
|
||||
|
||||
it "can transform to a new real Dom element", ->
|
||||
expect(@dom).to.not.be.undefined
|
||||
|
||||
it "supports dom.insertBefore", ->
|
||||
newdom = $("<p>dtrn</p>")[0]
|
||||
newdom2 = $("<p>dtrn2</p>")[0]
|
||||
@dom.insertBefore(newdom2, null)
|
||||
@dom.insertBefore(newdom, newdom2)
|
||||
expect(@u1+"").to.equal("<div><p>dtrn</p><p>dtrn2</p></div>")
|
||||
expect(@dom.outerHTML).to.equal("<div><p>dtrn</p><p>dtrn2</p></div>")
|
||||
|
||||
it "supports dom.appendChild", ->
|
||||
newdom = $("<p>dtrn</p>")[0]
|
||||
@dom.appendChild(newdom)
|
||||
expect(@u1+"").to.equal("<div><p>dtrn</p></div>")
|
||||
|
||||
it "supports dom.setAttribute", ->
|
||||
@dom.setAttribute("test_attribute", "newVal")
|
||||
expect(@u1.attr("test_attribute")).to.equal("newVal")
|
||||
expect(@dom.getAttribute("test_attribute")).to.equal("newVal")
|
||||
|
||||
it "supports dom.removeAttribute", ->
|
||||
@dom.setAttribute("test_attribute", "newVal")
|
||||
expect(@u1.attr("test_attribute")).to.equal("newVal")
|
||||
expect(@dom.getAttribute("test_attribute")).to.equal("newVal")
|
||||
@dom.removeAttribute("test_attribute")
|
||||
expect(@u1.attr("test_attribute")).to.be.undefined
|
||||
expect(@dom.getAttribute("test_attribute")).to.be.undefined
|
||||
|
||||
it "supports dom.removeChild", ->
|
||||
newdom = $("<p>dtrn</p>")[0]
|
||||
@dom.appendChild(newdom)
|
||||
expect(@u1+"").to.equal("<div><p>dtrn</p></div>")
|
||||
expect(@dom.outerHTML).to.equal("<div><p>dtrn</p></div>")
|
||||
|
||||
@dom.removeChild(newdom)
|
||||
expect(@dom.childNodes.length).to.equal(0)
|
||||
expect(@u1.getChildren().length).to.equal(0)
|
||||
|
||||
it "supports dom.replaceChild", ->
|
||||
dom = $("<p>dtrn</p>")[0]
|
||||
@dom.appendChild(newdom)
|
||||
expect(@u1+"").to.equal("<div><p>dtrn</p></div>")
|
||||
expect(@dom.outerHTML).to.equal("<div><p>dtrn</p></div>")
|
||||
|
||||
newdom = $("<p>replaced</p>")[0]
|
||||
@dom.replaceChild(dom,newdom)
|
||||
expect(@dom.outerHTML).to.equal("<div><p>replaced</p></div>")
|
||||
expect(@u1+"").to.equal("<div><p>replaced</p></div>")
|
||||
|
||||
it "supports dom.classList.add", ->
|
||||
@dom.classList.add "classy"
|
||||
@dom.classList.add "moreclassy"
|
||||
expect(@u1.attr("class")).to.equal("classy moreclassy")
|
||||
expect(@dom.getAttribute("class")).to.equal("classy moreclassy")
|
||||
|
||||
|
||||
it "supports dom.textContent", ->
|
||||
dom = $("<p>dtrn</p>")[0]
|
||||
@dom.appendChild(newdom)
|
||||
expect(@u1+"").to.equal("<div><p>dtrn</p></div>")
|
||||
expect(@dom.outerHTML).to.equal("<div><p>dtrn</p></div>")
|
||||
|
||||
@dom.textContent = ""
|
||||
expect(@u1+"").to.equal("<div></div>")
|
||||
expect(@dom.outerHTML).to.equal("<div></div>")
|
||||
|
||||
it "suppports dom.textContent (non empty string)", ->
|
||||
dom = $("<p>dtrn</p>")[0]
|
||||
@dom.appendChild(newdom)
|
||||
expect(@u1+"").to.equal("<div><p>dtrn</p></div>")
|
||||
expect(@dom.outerHTML).to.equal("<div><p>dtrn</p></div>")
|
||||
|
||||
@dom.textContent = "stuff"
|
||||
expect(@u1+"").to.equal("<div>stuff</div>")
|
||||
expect(@dom.outerHTML).to.equal("<div>stuff</div>")
|
||||
|
||||
it "supports jquery.addClass", ->
|
||||
@j.addClass("testy")
|
||||
@j.addClass("testedy tested")
|
||||
expect(@dom.getAttribute("class")).to.equal("testy testedy tested")
|
||||
|
||||
it "supports jquery.after", ->
|
||||
d = $("<span></span>")
|
||||
@dom.appendChild(d[0], null)
|
||||
d.after("<div>after</div>")
|
||||
expect(@dom.outerHTML).to.equal("<div><span></span><div>after</div></div>")
|
||||
expect(@u1+"").to.equal("<div><span></span><div>after</div></div>")
|
||||
|
||||
it "supports jquery.append", ->
|
||||
d = $("<span></span>")[0]
|
||||
@j.append(d)
|
||||
d = $("<div></div>")[0]
|
||||
@dom.append(d)
|
||||
expect(@dom.outerHTML).to.equal("<div><span></span><div></div></div>")
|
||||
expect(@u1+"").to.equal("<div><span></span><div></div></div>")
|
||||
|
||||
it "supports jquery.appendTo", ->
|
||||
$("<b>appendedTo</b>").appendTo(@dom)
|
||||
$("p").appendTo(@dom)
|
||||
expect(@dom.outerHTML).to.equal("<div><b>appendedTo</b><p></p></div>")
|
||||
expect(@u1+"").to.equal("<div><b>appendedTo</b><p></p></div>")
|
||||
|
||||
it "supports jquery.before", ->
|
||||
newdom = $("p")
|
||||
$(@dom).append(newdom)
|
||||
newdom.before("<div>before</div>")
|
||||
expect(@dom.outerHTML).to.equal("<div><div>before</div><p></p></div>")
|
||||
expect(@u1+"").to.equal("<div><div>before</div><p></p></div>")
|
||||
|
||||
it "supports jquery.detach", ->
|
||||
d = $("p")
|
||||
$j.append(d)
|
||||
$j.detach("p")
|
||||
expect(@dom.outerHTML).to.equal("<div></div>")
|
||||
expect(@u1+"").to.equal("<div></div>")
|
||||
|
||||
it "supports jquery.empty", ->
|
||||
d = $("<p />")
|
||||
d.appendTo(@dom)
|
||||
d = $("<div />")
|
||||
d.appendTo(@dom)
|
||||
@j.empty()
|
||||
expect(@dom.outerHTML).to.equal("<div></div>")
|
||||
expect(@u1+"").to.equal("<div></div>")
|
||||
|
||||
it "supports jquery.insertAfter", ->
|
||||
d = $("span")
|
||||
d.appendTo(@dom)
|
||||
$("<p>after</p>").insertAfter(d)
|
||||
expect(@dom.outerHTML).to.equal("<div><span></span><p>after</p></div>")
|
||||
expect(@u1+"").to.equal("<div><span></span><p>after</p></div>")
|
||||
|
||||
it "supports jquery.insertBefore", ->
|
||||
d = $("span")
|
||||
d.appendTo(@j)
|
||||
$("<p>after</p>").insertAfter(d)
|
||||
expect(@dom.outerHTML).to.equal("<div><p>before</p><span></span></div>")
|
||||
expect(@u1+"").to.equal("<div><p>before</p><span></span></div>")
|
||||
|
||||
it "supports jquery.prepend", ->
|
||||
@j.prepend("<p>prepended2</p>")
|
||||
@j.prepend("<p>prepended1</p>")
|
||||
expect(@dom.outerHTML).to.equal("<div><p>prepended1</p><p>prepended2</p></div>")
|
||||
expect(@u1+"").to.equal("<div><p>prepended1</p><p>prepended2</p></div>")
|
||||
|
||||
it "supports jquery.prependTo", ->
|
||||
$("<p>prepended2</p>").prependTo(@j)
|
||||
$("<p>prepended1</p>").prependTo(@j)
|
||||
expect(@dom.outerHTML).to.equal("<div><p>prepended1</p><p>prepended2</p></div>")
|
||||
expect(@u1+"").to.equal("<div><p>prepended1</p><p>prepended2</p></div>")
|
||||
|
||||
it "supports jquery.remove", ->
|
||||
d = $("<div />")
|
||||
d.prependTo(@j)
|
||||
d.remove()
|
||||
expect(@dom.outerHTML).to.equal("<div></div>")
|
||||
expect(@u1+"").to.equal("<div></div>")
|
||||
|
||||
it "supports jquery.removeAttr", ->
|
||||
@dom.setAttribute("test_attribute", "newVal")
|
||||
expect(@u1.attr("test_attribute")).to.equal("newVal")
|
||||
expect(@dom.getAttribute("test_attribute")).to.equal("newVal")
|
||||
|
||||
@j.removeAttr("test_attribute")
|
||||
expect(@u1.attr("test_attribute")).to.be.undefined
|
||||
expect(@j.attr("test_attribute")).to.be.undefined
|
||||
|
||||
it "supports jquery.removeClass", ->
|
||||
@j.addClass("testy")
|
||||
@j.addClass("testedy tested")
|
||||
expect(@dom.getAttribute("class")).to.equal("testy testedy tested")
|
||||
|
||||
@j.removeClass("testedy")
|
||||
expect(@dom.getAttribute("class")).to.equal("testy tested")
|
||||
expect(@u1.hasClass("testedy")).to.be.false
|
||||
|
||||
it "supports jquery.attr", ->
|
||||
@j.attr("atone", "yeah")
|
||||
expect(@u1.attr("atone")).to.equal("yeah")
|
||||
|
||||
it "supports jquery.replaceAll", ->
|
||||
$("<span>New span content </span>").replaceAll("#test_dom div")
|
||||
@check()
|
||||
|
||||
it "supports jquery.replaceWith", ->
|
||||
d = $("span")
|
||||
@j.prepend(d)
|
||||
d = $("span")
|
||||
@j.prepend(d)
|
||||
d = $("span")
|
||||
@j.prepend(d)
|
||||
d = @j.getElementsByTagName("span")
|
||||
d.replaceWith("<div></div>")
|
||||
|
||||
expect(@dom.outerHTML).to.equal("<div><div></div><div></div><div></div></div>")
|
||||
expect(@u1+"").to.equal("<div><div></div><div></div><div></div></div>")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user