define(["intern!object","intern/chai!assert","sinon","../../dom-construct","../../dom-attr","../../has"],function(e,r,a,l,o,t){var n,i,c,d,u,m=0;function h(){return"dom-construct"+m++}function s(e,t){return e.id===t.id&&e.tagName===t.tagName&&e.innerHTML===t.innerHTML}e({name:"dojo/dom-construct",toDom:{"returns expected node when one requested":function(){var e=l.toDom("
");r.equal(e.nodeName.toLowerCase(),"div")},"returns expected result when tree requested":function(){var e=document.createElement("div"),t=document.createElement("span");e.appendChild(t);var n=l.toDom(e.outerHTML);r.equal(n.outerHTML,n.outerHTML)},"returns expected result when forest requested":function(){var e=document.createElement("div"),t=[document.createElement("span"),document.createElement("span")];for(var n in t)e.appendChild(t[n]);var a=l.toDom(e.innerHTML);r.equal(a.outerHTML,a.innerHTML)},"able to create tag, which must be created in context of ":function(){var e=l.toDom("");r.equal(e.nodeName.toLowerCase(),"option")},"able to create tag, which must be created in context of
":function(){var e=l.toDom("");r.equal(e.nodeName.toLowerCase(),"tbody")},"able to create tag, which must be created in context of
":function(){var e=l.toDom("");r.equal(e.nodeName.toLowerCase(),"thead")},"able to create tag, which must be created in context of
":function(){var e=l.toDom("");r.equal(e.nodeName.toLowerCase(),"tfoot")},"able to create
tag, which must be created in context of
":function(){var e=l.toDom("
");r.equal(e.nodeName.toLowerCase(),"tr")},"able to create
tag, which must be created in context of
":function(){var e=l.toDom("
");r.equal(e.nodeName.toLowerCase(),"td")},"able to create
tag, which must be created in context of
":function(){var e=l.toDom("
");r.equal(e.nodeName.toLowerCase(),"th")},"able to create tag, which must be created in context of ":function(){var e=l.toDom("");r.equal(e.nodeName.toLowerCase(),"legend")},"able to create
tag, which must be created in context of
":function(){var e=l.toDom("
");r.equal(e.nodeName.toLowerCase(),"caption")},"able to create
tag, which must be created in context of
":function(){var e=l.toDom("
");r.equal(e.nodeName.toLowerCase(),"colgroup")},"able to create
tag, which must be created in context of
":function(){var e=l.toDom("
");r.equal(e.nodeName.toLowerCase(),"col")},"able to create tag, which must be created in context of
":function(){var e=l.toDom("");r.equal(e.nodeName.toLowerCase(),"li")}},place:{"when first arg is rawHTML, then it is converted to DOM and placed":function(){var e=document.createElement("div"),t=document.createElement("span"),n=document.createElement("h1");e.appendChild(t),l.place(e.outerHTML,n,"only"),r.equal(n.firstElementChild.nodeName,e.nodeName),r.equal(n.firstElementChild.firstElementChild.nodeName,t.nodeName)},"when first arg is a node id, then the correct node is placed":function(){var e=document.createElement("div"),t=document.createElement("h1"),n=h();e.id=n,document.body.appendChild(e),l.place(n,t,"only"),r.equal(t.firstElementChild.nodeName,e.nodeName)},"when first arg is a node, then it is placed":function(){var e=document.createElement("div"),t=document.createElement("h1");document.body.appendChild(e),l.place(e,t,"only"),r.equal(t.firstElementChild.nodeName,e.nodeName)},"when second arg is a string, then the node with that id is used as reference":function(){var e=document.createElement("div"),t=document.createElement("h1"),n=h();document.body.appendChild(t),t.id=n,l.place(e,n,"only"),r.equal(t.firstElementChild.nodeName,e.nodeName)},"when second arg is a node, then it is used as the reference node":function(){var e=document.createElement("div"),t=document.createElement("h1");document.body.appendChild(t),l.place(e,t,"only"),r.equal(t.firstElementChild.nodeName,e.nodeName)},"when third argument is 'before', then the first arg is placed before the second":function(){var e=document.createElement("div"),t=document.createElement("h1");document.body.appendChild(t),l.place(e,t,"before"),r.equal(t.previousSibling.nodeName,e.nodeName)},"when third argument is 'after', then the first arg is placed after the second":function(){var e=document.createElement("div"),t=document.createElement("h1");document.body.appendChild(t),l.place(e,t,"after"),r.equal(t.nextSibling.nodeName,e.nodeName)},"when third argument is 'replace', then the first arg replaces the second":function(){var e=document.createElement("div"),t=document.createElement("span"),n=document.createElement("h1");document.body.appendChild(e),e.appendChild(n),l.place(t,n,"replace"),r.equal(e.firstElementChild.nodeName,t.nodeName)},"when third argument is 'only', then the first arg is placed as only content of second":function(){var e=document.createElement("span"),t=document.createElement("h1"),n=[document.createElement("button"),document.createElement("button"),document.createElement("button")];for(var a in n)t.appendChild(n[a]);document.body.appendChild(t),l.place(e,t,"only"),r.equal(t.firstElementChild.nodeName,e.nodeName),r.equal(t.children.length,1)},"when third argument is 'first', then the first arg is placed as first child of second":function(){var e=document.createElement("span"),t=document.createElement("h1"),n=[document.createElement("button"),document.createElement("button"),document.createElement("button")];for(var a in n)t.appendChild(n[a]);document.body.appendChild(t),l.place(e,t,"first"),r.equal(t.firstElementChild.nodeName,e.nodeName),r.equal(t.children.length,n.length+1)},"when third argument is 'last', then the first arg is placed as last child of second":function(){var e=document.createElement("span"),t=document.createElement("h1"),n=[document.createElement("button"),document.createElement("button"),document.createElement("button")];for(var a in n)t.appendChild(n[a]);document.body.appendChild(t),l.place(e,t,"last"),r.equal(t.lastElementChild.nodeName,e.nodeName),r.equal(t.children.length,n.length+1)},"when third argument is a number, then the first arg is placed as the correct child of second":function(){var e=document.createElement("span"),t=document.createElement("h1"),n=[document.createElement("button"),document.createElement("button"),document.createElement("button")];for(var a in n)t.appendChild(n[a]);document.body.appendChild(t),l.place(e,t,2),r.equal(t.children[2].nodeName,e.nodeName),r.equal(t.children.length,n.length+1)},"when third argument is a number and the reference node is empty, then the first arg is placed as the first child of second":function(){var e=document.createElement("span"),t=document.createElement("h1");document.body.appendChild(t),l.place(e,t,2),r.equal(t.firstElementChild.nodeName,e.nodeName),r.equal(t.children.length,1)},"when third argument is a number that is greater than the number of children in the reference, then the first arg is placed as the first child of second":function(){var e=document.createElement("span"),t=document.createElement("h1"),n=[document.createElement("button"),document.createElement("button"),document.createElement("button")],a=n+42;for(var o in n)t.appendChild(n[o]);document.body.appendChild(t),l.place(e,t,a),r.equal(t.lastElementChild.nodeName,e.nodeName),r.equal(t.children.length,n.length+1)}},create:{"when first arg is a string, then correct element type is created":function(){var e=l.create("div");r.equal(e.nodeName.toLowerCase(),"div")},"when attributes provided, then dojo/dom-attr:set called with correct args":function(){var e=document.createElement("div"),t={foo:"bar",baz:"buz"},n=a.spy(o,"set");l.create(e,t),r.isTrue(n.calledWith(e,t)),n.restore()},"when reference node provided, then dojo/dom-construct::place() called with correct args":function(){var e=document.createElement("div"),t=document.createElement("h1"),n=a.spy(l,"place");l.create(e,null,t,"only"),r.isTrue(n.calledWith(e,t,"only")),n.restore()},"when reference node not part of global document, then new element created in correct context":function(){var e=document.createElement("iframe");document.body.appendChild(e),tagType="div",reference=e.contentDocument.createElement("h1"),position="only";var t=l.create(tagType,null,reference,position);r.equal(t.ownerDocument,e.contentDocument)}},empty:{"when given a node's id, then the related node is emptied":function(){var e=document.createElement("div"),t=document.createElement("button"),n=h();e.id=n,e.appendChild(t),document.body.appendChild(e),l.empty(n),r.equal(e.children.length,0)},"when given a node, then it is emptied":function(){var e=document.createElement("div"),t=document.createElement("button");e.appendChild(t),l.empty(e),r.equal(e.children.length,0)},"when given an svg element, then it is emptied":function(){document.createElement("div");var e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.innerHTML="",l.empty(e),null==e.children?r.equal(e.innerHTML,""):r.equal(e.children.length,0)}},destroy:{"when given a node's id, then it is removed":function(){var e=document.createElement("h1"),t=document.createElement("div"),n=h();e.id=n,document.body.appendChild(t),t.appendChild(e),l.destroy(n),r.equal(t.children.length,0)},"when given a node, then it is removed":function(){var e=document.createElement("h1"),t=document.createElement("div");document.body.appendChild(t),t.appendChild(e),l.destroy(e),r.equal(t.children.length,0)}},"validation tests":(d='
"),c.appendChild(u.last),c.appendChild(u.first),c.appendChild(u.before),c.appendChild(u.after),c.appendChild(u.replace),c.appendChild(u.only),c.appendChild(u.pos),(i=document.createDocumentFragment()).appendChild(document.createElement("div")),i.appendChild(document.createElement("div")),i.appendChild(document.createElement("div"))},"last - place html string with node reference":function(){l.place(d,u.last),r.isTrue(s(n,u.last.lastChild))},"last - place html string with id reference":function(){l.place(d,"last"),r.isTrue(s(n,u.last.lastChild))},"last - place html string with fragment reference":function(){l.place(d,i),r.isTrue(s(n,i.lastChild))},"last - place node with node reference":function(){l.place(n,u.last),r.equal(u.last.lastChild,n)},"last - place node with id reference":function(){l.place(n,"last"),r.equal(u.last.lastChild,n)},"last - place node with fragment reference":function(){l.place(n,i),r.equal(i.lastChild,n)},"first - place html string with node reference":function(){l.place(d,u.first,"first"),r.isTrue(s(n,u.first.firstChild))},"first - place html string with id reference":function(){l.place(d,"first","first"),r.isTrue(s(n,u.first.firstChild))},"first - place html string with fragment reference":function(){l.place(d,i,"first"),r.isTrue(s(n,i.firstChild))},"first - place node with node reference":function(){l.place(n,u.first,"first"),r.equal(u.first.firstChild,n)},"first - place node with id reference":function(){l.place(n,"first","first"),r.equal(u.first.firstChild,n)},"first - place node with fragment reference":function(){l.place(n,i,"first"),r.equal(i.firstChild,n)},"before - place html string with node reference":function(){l.place(d,u.before,"before"),r.isTrue(s(n,u.before.previousSibling))},"before - place html string with id reference":function(){l.place(d,"before","before"),r.isTrue(s(n,u.before.previousSibling))},"before - place node with node reference":function(){l.place(n,u.before,"before"),r.equal(u.before.previousSibling,n)},"before - place node with id reference":function(){l.place(n,"before","before"),r.equal(u.before.previousSibling,n)},"after - place html string with node reference":function(){l.place(d,u.after,"after"),r.isTrue(s(n,u.after.nextSibling))},"after - place html string with id reference":function(){l.place(d,"after","after"),r.isTrue(s(n,u.after.nextSibling))},"after - place node with node reference":function(){l.place(n,u.after,"after"),r.equal(u.after.nextSibling,n)},"after - place node with id reference":function(){l.place(n,"after","after"),r.equal(u.after.nextSibling,n)},"replace - place html string with node reference":function(){l.place(d,u.replace,"replace"),r.equal(void 0,document.getElementById("replace")),r.isTrue(s(n,document.getElementById("test")))},"replace - place html string with id reference":function(){l.place(d,"replace","replace"),r.equal(void 0,document.getElementById("replace")),r.isTrue(s(n,document.getElementById("test")))},"replace - place node with node reference":function(){l.place(n,u.replace,"replace"),r.equal(document.getElementById("replace"),void 0),r.equal(n,document.getElementById("test"))},"replace - place node with id reference":function(){l.place(n,"replace","replace"),r.equal(void 0,document.getElementById("replace")),r.equal(document.getElementById("test"),n)},"only - place html string with node reference":function(){l.place(d,u.only,"only"),r.equal(1,u.only.children.length),r.isTrue(s(n,u.only.firstChild))},"only - place html string with id reference":function(){l.place(d,"only","only"),r.equal(1,u.only.children.length),r.isTrue(s(n,u.only.firstChild))},"only - place html string with fragment reference":function(){l.place(d,i,"only"),r.equal(1,i.childNodes.length),r.isTrue(s(n,i.firstChild))},"only - place node with node reference":function(){l.place(n,u.only,"only"),r.equal(u.only.firstChild,n),r.equal(u.only.children.length,1)},"only - place node with id reference":function(){l.place(n,"only","only"),r.equal(u.only.firstChild,n),r.equal(u.only.children.length,1)},"only - place node with fragment reference":function(){l.place(n,i,"only"),r.equal(1,i.childNodes.length),r.equal(i.firstChild,n)},"pos - place html string with node reference":function(){l.place(d,u.pos,2),r.isTrue(s(n,u.pos.children[2]))},"pos - place html string with id reference":function(){l.place(d,"pos",2),r.isTrue(s(n,u.pos.children[2]))},"pos - place html string with fragment reference":function(){l.place(d,i,2),r.isTrue(s(n,i.childNodes[2]))},"pos - place node with node reference":function(){l.place(n,u.pos,2),r.equal(u.pos.children[2],n)},"pos - place node with id reference":function(){l.place(n,"pos",2),r.equal(u.pos.children[2],n)},"pos - place node with fragment reference":function(){l.place(n,i,2),r.equal(i.childNodes[2],n)}})})});