text: require(["chai","jquery","underscore","tests/utils","text!static/core/test1.xml","text!static/core/group-rename.xml","text!static/core/invalid-questions.xml","text!static/core/increment-item.xml","text!static/core/hidden-value-in-repeat.xml","text!static/core/hidden-among-questions.xml","text!static/core/insert-questions.xml"],function(e,t,d,i,n,o,a,r,s,u,l){var x=e.assert,h=i.call,c=d(i.options.options.plugins||[]).without("itemset");describe("Vellum core",function(){before(function(e){i.init({core:{onReady:function(){e()}}})}),it("should display non-widget message",function(){i.loadXML("");var d=i.addQuestion("Text","text"),n="Test non-widget message.";d.addMessage(null,{key:"testing-1-2-3",level:"error",message:n});var o=t(".fd-content-right").find(".messages");e.expect(i.getMessages(d)).to.include(n),e.expect(o.text()).to.include(n)}),it("should load form with save button in 'saved' state",function(e){i.init({core:{form:n,onReady:function(){x.equal(this.data.core.saveButton.state,"saved"),e()}}})}),it("should allow mug rename with itemset in form when the itemset plugin is disabled",function(e){i.init({plugins:c,core:{form:n,onReady:function(){var t=h("getMugByPath","/data/state"),d=t.form.getChildren(t)[0];x.equal(t.form.getAbsolutePath(d,!0),null),t.p.nodeID="stat",e()}}})}),it("should update child references on group rename",function(){i.loadXML(o);var e=h("getMugByPath","/data/group"),t=h("getMugByPath","/data/group/question1"),d=h("getMugByPath","/data/question2");e.p.nodeID="g8",x.equal(t.form.getAbsolutePath(t),"/data/g8/question1"),x.equal(d.p.relevantAttr,"/data/g8/question1 = 'valley girl' and /data/g8/question2 = 'dude'")}),it("should show warning icons on invalid questions",function(){i.loadXML(a);var e=h("getMugByPath","/data/q0"),t=h("getMugByPath","/data/q1"),d=h("getMugByPath","/data/h1");x(i.isTreeNodeValid(e),"q0 is invalid: sanity check failed"),x(!i.isTreeNodeValid(t),"q1 should not be valid"),x(!i.isTreeNodeValid(d),"h1 should not be valid")}),it("should increment item value on insert new select item as child of select",function(){i.loadXML(r),i.clickQuestion("question1");var e=i.addQuestion("Item");x.equal(e.p.nodeID,"item3")}),it("should increment item value on insert new select item after sibling item",function(){i.loadXML(r),i.clickQuestion("question1/item1");var e=i.addQuestion("Item");x.equal(e.p.nodeID,"item3")}),it("should add hidden value in repeat group",function(){i.loadXML(""),i.addQuestion("Repeat","repeat"),i.addQuestion.bind({prevId:"repeat"})("Text","text"),i.addQuestion.bind({prevId:"repeat"})("DataBindOnly","hidden"),i.assertXmlEqual(h("createXML"),s,{normalize_xmlns:!0})}),it("should add question outside of collapsed group (ref group)",function(){i.loadXML("");var e=i.addQuestion("Group","group");i.addQuestion("Text","text1"),i.collapseGroup(e),i.addQuestion.bind({prevId:"group"})("Text","text2"),i.expandGroup(e),i.assertJSTreeState("group","  text1","text2")}),it("should add question outside of collapsed group (ref inner question)",function(){i.loadXML("");var e,t=i.addQuestion("Group","group"),d=i.addQuestion("Text","text1");i.clickQuestion("group/text1"),e=h("getCurrentlySelectedMug"),x.equal(e,d,"wrong selected mug: "+(e&&e.p.nodeID)),i.collapseGroup(t),i.addQuestion("Text","text2"),i.expandGroup(t),i.assertJSTreeState("group","  text1","text2")}),it("should not be able to add choice to collapsed select",function(){i.loadXML("");var t=i.addQuestion("Select","select");i.addQuestion("Item","item3"),i.collapseGroup(t),e.expect(function(){i.addQuestion.bind({prevId:"select"})("Item","item4")}).to["throw"](Error)}),it("should add text outside of collapsed select",function(){i.loadXML("");var e=i.addQuestion("Select","select");i.collapseGroup(e),i.addQuestion.bind({prevId:"select"})("Text","text1"),i.expandGroup(e),i.assertJSTreeState("select","  item1","  item2","text1")}),it("should select group of selected child question on collapse group",function(){i.loadXML("");var e,t,d=i.addQuestion("Group","group");i.addQuestion("Group","group"),e=i.addQuestion("Text","text"),i.clickQuestion("group/group/text"),t=h("getCurrentlySelectedMug"),x.equal(t,e,"wrong selected mug: "+(t&&t.p.nodeID)),i.collapseGroup(d),t=h("getCurrentlySelectedMug"),x.equal(t,d,"wrong selected mug: "+(t&&t.p.nodeID))}),it("should not select group if external question is selected on collapse group",function(){i.loadXML("");var e,t=i.addQuestion("Text","text1"),d=i.addQuestion("Group","group");i.clickQuestion("text1"),e=h("getCurrentlySelectedMug"),x.equal(e,t,"wrong selected mug: "+(e&&e.p.nodeID)),i.collapseGroup(d),e=h("getCurrentlySelectedMug"),x.equal(e,t,"wrong selected mug: "+(e&&e.p.nodeID))}),it("should load hidden value in repeat group",function(){i.loadXML(s),i.assertJSTreeState("repeat","  text","  hidden")}),it("should load hidden values interspersed with other questions",function(){i.loadXML(u),i.assertJSTreeState("hidden1","select1","  item1","  item2","hidden2","select2","  item1","  item2","hidden3","group","  hidden4","  text3","  hidden5","  text4","  hidden6","hidden7","text5","hidden8")}),it("should add hidden value at end of group",function(){i.loadXML(l),i.addQuestion.bind({prevId:"hidden1"})("DataBindOnly","hiddenA"),i.addQuestion.bind({prevId:"group/hidden2"})("DataBindOnly","hiddenB"),i.assertJSTreeState("text1","text2","group","  text3","  text4","  hidden2","  hiddenB","text5","hidden1","hiddenA")}),it("should add hidden value among other questions",function(){i.loadXML(l),i.addQuestion.bind({prevId:"text1"})("DataBindOnly","hiddenA"),i.addQuestion.bind({prevId:"group/text3"})("DataBindOnly","hiddenB"),i.assertJSTreeState("text1","hiddenA","text2","group","  text3","  hiddenB","  text4","  hidden2","text5","hidden1")}),it("should add question after selected question",function(){i.loadXML(l),i.addQuestion.bind({prevId:"text1"})("Text","textA"),i.addQuestion.bind({prevId:"group/text3"})("Text","textB"),i.assertJSTreeState("text1","textA","text2","group","  text3","  textB","  text4","  hidden2","text5","hidden1")}),it("should add question after hidden value",function(){i.loadXML(l),i.addQuestion.bind({prevId:"hidden1"})("Text","textA"),i.addQuestion.bind({prevId:"group/hidden2"})("Text","textB"),i.assertJSTreeState("text1","text2","group","  text3","  text4","  hidden2","  textB","text5","hidden1","textA")}),it("should add question after sole hidden value",function(e){i.init({core:{onReady:function(){i.addQuestion("DataBindOnly","hidden"),i.addQuestion.bind({prevId:"hidden"})("Text","text"),i.assertJSTreeState("hidden","text"),e()}}})}),it("should display welcome message whenever there are no questions",function(){i.loadXML(""),i.addQuestion("Text","text1"),i.addQuestion("Text","text2"),i.deleteQuestion("/data/text1"),x(!t(".fd-default-panel").is(":visible")),x(t(".fd-question-changer").is(":visible")),i.deleteQuestion("/data/text2"),x(t(".fd-default-panel").is(":visible"))}),describe("should",function(){var e,t;before(function(){e=i.loadXML(""),i.addQuestion("Text","question1"),t=i.addQuestion("Text","question2")}),it("show validation error on add question with duplicate path",function(){t.p.nodeID="question1",x(e.vellum.ensureCurrentMugIsSaved(),"mug is not saved"),x(!i.isTreeNodeValid(t),"mug should not be valid")}),it("reset question ID on dismiss duplicate path error",function(){t.p.nodeID="question1";var e=t.messages.get("nodeID","mug-conflictedNodeId-warning");x(e,"unexpected: validation error is missing"),t.dropMessage("nodeID","mug-conflictedNodeId-warning"),x(i.isTreeNodeValid(t),i.getMessages(t)),x.match(t.p.nodeID,/^copy-\d+-of-question1$/),x(!t.p.conflictedNodeId,"conflictedNodeId should not be set; got "+t.p.conflictedNodeId)})}),describe("type changer",function(){function e(e,i,n){var o=n?"show ":"not show ";it("should "+o+i+" in menu for "+e,function(){var o=d[e],a=t.vellum.getQuestionTypeChanger(o),r=a.find("[data-qtype="+i+"]");x(r.length===(n?1:0),r.parent().html()||i+" not found in menu")})}var t,d={};before(function(){t=i.loadXML(""),d.Text=i.addQuestion("Text"),d.Select=i.addQuestion("Select"),d.SelectDynamic=i.addQuestion("SelectDynamic"),d.Transfer=i.addQuestion("Transfer"),d.Dispense=i.addQuestion("Dispense"),d.Receive=i.addQuestion("Receive")}),e("Text","Trigger",!0),e("Text","Item"),e("Text","Group"),e("Text","DataBindOnly"),e("Text","Select",!0),e("Text","MSelect",!0),e("Text","SelectDynamic"),e("Text","MSelectDynamic"),e("Text","Transfer"),e("Select","MSelect",!0),e("Select","Text"),e("Select","SelectDynamic"),e("Select","MSelectDynamic"),e("SelectDynamic","MSelectDynamic",!0),e("SelectDynamic","Select"),e("SelectDynamic","MSelect"),e("Transfer","Text"),e("Transfer","Dispense",!0),e("Transfer","Receive",!0),e("Dispense","Transfer",!0),e("Dispense","Receive",!0),e("Receive","Transfer",!0),e("Receive","Dispense",!0)}),describe("drag+drop should",function(){var e;before(function(){i.loadXML(l),i.addQuestion.bind({prevId:"text2"})("Repeat","repeat"),e={text1:h("getMugByPath","/data/text1"),text2:h("getMugByPath","/data/text2"),repeat:h("getMugByPath","/data/repeat"),group:h("getMugByPath","/data/group"),text3:h("getMugByPath","/data/group/text3"),text4:h("getMugByPath","/data/group/text4"),hidden2:h("getMugByPath","/data/group/hidden2"),text5:h("getMugByPath","/data/text5"),hidden1:h("getMugByPath","/data/hidden1")}});var t=[["text1","before","text1",!0],["text1","inside","text1",!0],["text1","after","text1",!0],["text1","into","text1",!0],["text1","before","text2",!0],["text1","inside","text2",!0],["text1","after","text2",!0],["text1","before","repeat",!0],["text1","inside","repeat",!0],["text1","after","repeat",!0],["text1","first","group",!0],["text1","before","group",!0],["text1","inside","group",!0],["text1","after","group",!0],["text1","last","group",!0],["text1","into","group",!0],["text1","before","text3",!0],["text1","inside","text3",!0],["text1","after","text3",!0],["text1","before","text4",!0],["text1","inside","text4",!0],["text1","after","text4",!0],["text1","before","hidden2",!0],["text1","inside","hidden2",!0],["text1","after","hidden2",!0],["text1","into","hidden2",!0],["text1","before","text5",!0],["text1","inside","text5",!0],["text1","after","text5",!0],["text1","before","hidden1",!0],["text1","inside","hidden1",!0],["text1","after","hidden1",!0],["hidden1","before","text1",!0],["hidden1","inside","text1",!0],["hidden1","after","text1",!0],["hidden1","into","text1",!0],["hidden1","before","text2",!0],["hidden1","inside","text2",!0],["hidden1","after","text2",!0],["hidden1","first","repeat",!0],["hidden1","before","repeat",!0],["hidden1","inside","repeat",!0],["hidden1","after","repeat",!0],["hidden1","into","repeat",!0],["hidden1","last","repeat",!0],["hidden1","first","group",!0],["hidden1","before","group",!0],["hidden1","inside","group",!0],["hidden1","after","group",!0],["hidden1","into","group",!0],["hidden1","last","group",!0],["hidden1","before","text3",!0],["hidden1","inside","text3",!0],["hidden1","after","text3",!0],["hidden1","before","text4",!0],["hidden1","inside","text4",!0],["hidden1","after","text4",!0],["hidden1","before","hidden2",!0],["hidden1","inside","hidden2",!0],["hidden1","after","hidden2",!0],["hidden1","before","text5",!0],["hidden1","inside","text5",!0],["hidden1","after","text5",!0],["hidden1","before","hidden1",!0],["hidden1","inside","hidden1",!0],["hidden1","after","hidden1",!0],["hidden2","before","text1",!0],["hidden2","inside","text1",!0],["hidden2","after","text1",!0],["hidden2","before","text2",!0],["hidden2","inside","text2",!0],["hidden2","after","text2",!0],["hidden2","before","repeat",!0],["hidden2","inside","repeat",!0],["hidden2","after","repeat",!0],["hidden2","before","group",!0],["hidden2","inside","group",!0],["hidden2","after","group",!0],["hidden2","before","text3",!0],["hidden2","inside","text3",!0],["hidden2","after","text3",!0],["hidden2","before","text4",!0],["hidden2","inside","text4",!0],["hidden2","after","text4",!0],["hidden2","before","hidden2",!0],["hidden2","inside","hidden2",!0],["hidden2","after","hidden2",!0],["hidden2","before","text5",!0],["hidden2","inside","text5",!0],["hidden2","after","text5",!0],["hidden2","before","hidden1",!0],["hidden2","inside","hidden1",!0],["hidden2","after","hidden1",!0]];d(t).each(function(t){var d=t[3],i=d?"allow move ":"prevent move ",n=t[0],o=t[2],a=t[1];it(i+n+" "+a+" "+o,function(){var t=e[n],i=e[o],r=h("checkMove",t.ufid,t.__className,i.ufid,i.__className,a);x(d?r:!r,["move",n,a,o,"->",r].join(" "))})});var n=[[null,"first",null,"first"],[null,"last",null,"last"],["group","first","group","first"],["group","last","group","last"],["group","before","group","before"],["group","after","group","after"],["text1","before","text1","before"],["text1","after","text1","after"],[null,0,null,"first"],[null,1,"text1","after"],[null,2,"text2","after"],[null,3,"repeat","after"],[null,4,"group","after"],[null,5,"text5","after"],[null,6,"hidden1","after"],[null,7,null,"last"],[null,8,null,"last"],["repeat",0,"repeat","first"],["repeat",1,"repeat","last"],["repeat",2,"repeat","last"],["group",0,"group","first"],["group",1,"text3","after"],["group",2,"text4","after"],["group",3,"hidden2","after"],["group",4,"group","last"],["group",5,"group","last"]];d(n).each(function(t){var d=t[0],i=t[1],n=t[2],o=t[3],a="produce relative position "+d+"["+i+"] => "+o+" "+n;it(a,function(){var t=d?e[d]:null,a=n?e[n]:null,r=h("getRelativePosition",t,i),s=String(r.position),u=r.mug?r.mug.p.nodeID:String(r.mug);x(r.position===o&&r.mug===a,[i,d,"->",s,u].join(" "))})})})})});