afui.test.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. describe("afui", function () {
  2. before(function(){
  3. $("#afuitest").remove();
  4. $(document.body).append("<div id='afuitest'></div>");
  5. $("#afuitest").append(__html__['test/fixtures/afui.html']);
  6. $.afui.isLaunching=false;
  7. $.afui.hasLaunched=true;
  8. $.afui.launchCompleted=false;
  9. $.afui.defaultPanel=null;
  10. $.afui.activeDiv=null;
  11. });
  12. after(function(){
  13. $("#afuitest").remove();
  14. })
  15. it("should not be launched", function () {
  16. expect($.afui.launchCompleted).to.be.false;
  17. });
  18. it("should launch and dispatch ready function",function(done){
  19. $.afui.ready(function(){
  20. done();
  21. })
  22. $.afui.launch();
  23. });
  24. it("should be launched",function(){
  25. expect($.afui.launchCompleted).to.be.true;
  26. });
  27. it("should have an active view",function(){
  28. $("#afuitest").find(".view.active").length.should.equal(1);
  29. });
  30. it("should have an active panel",function(){
  31. $("#afuitest").find(".panel.active").length.should.equal(1);
  32. });
  33. //View testing
  34. it("should have a title",function(){
  35. var item=$("#afuitest").find(".view.active header h1");
  36. item.html().should.eql("hello");
  37. });
  38. it("should change the title by string",function(){
  39. var title="New Title";
  40. $.afui.setTitle(title);
  41. var item=$("#afuitest").find(".view.active header h1");
  42. item.html().should.eql(title);
  43. });
  44. it("should change the title by attribute",function(){
  45. var elem=$("<div data-title='New Title'></div>");
  46. $.afui.setTitle(elem);
  47. var item=$("#afuitest").find(".view.active header h1");
  48. item.html().should.eql('New Title');
  49. });
  50. it("should get the current title",function(){
  51. $.afui.getTitle().should.eql("New Title");
  52. });
  53. it("should load a panel",function(done){
  54. $.afui.loadContent("#foobar");
  55. setTimeout(function(){
  56. $.afui.activeDiv.should.eql(document.getElementById("foobar"));
  57. $("#afuitest").find(".view.active header h1").html().should.eql("foobar");
  58. done();
  59. },500);
  60. });
  61. it("should load a panel from a footer link",function(done){
  62. $("#afuitest footer a").eq(0).trigger("click");
  63. setTimeout(function(){
  64. $.afui.activeDiv.should.eql(document.getElementById("hello"));
  65. $("#afuitest").find(".view.active header h1").html().should.eql("hello");
  66. done();
  67. },500);
  68. });
  69. it("should go back in the view history stack",function(done){
  70. $.afui.goBack();
  71. setTimeout(function(){
  72. $.afui.activeDiv.should.eql(document.getElementById("foobar"));
  73. $("#afuitest").find(".view.active header h1").html().should.eql("foobar");
  74. done();
  75. },500);
  76. });
  77. it("should load a panel from a footer link",function(done){
  78. $("#afuitest footer a").eq(0).trigger("click");
  79. setTimeout(function(){
  80. $.afui.activeDiv.should.eql(document.getElementById("hello"));
  81. $("#afuitest").find(".view.active header h1").html().should.eql("hello");
  82. done();
  83. },500);
  84. });
  85. it("should go back in the view history stack",function(done){
  86. window.history.go(-1);
  87. setTimeout(function(){
  88. $.afui.activeDiv.should.eql(document.getElementById("foobar"));
  89. $("#afuitest").find(".view.active header h1").html().should.eql("foobar");
  90. done();
  91. },500);
  92. });
  93. it("should not go back with an empty history",function(done){
  94. $.afui.clearHistory();
  95. setTimeout(function(){
  96. $.afui.activeDiv.should.eql(document.getElementById("foobar"));
  97. $("#afuitest").find(".view.active header h1").html().should.eql("foobar");
  98. done();
  99. },500);
  100. });
  101. //Test animating the header
  102. it("should animate the header",function(done){
  103. $.afui.animateHeader(true);
  104. var div="hello";
  105. $.afui.loadContent("#"+div);
  106. var hdr=$($.afui.activeDiv).closest('.view').children("header");
  107. hdr.find("h1").eq(0).html().should.eql("hello");
  108. hdr.find("h1").length.should.eql(2);
  109. hdr.find("h1").eq(1).html().should.eql("foobar");
  110. //wait for the animation to finish
  111. setTimeout(function(){
  112. done();
  113. },550);
  114. });
  115. it("should test animate header functions",function(){
  116. var title=$.afui.getTitle();
  117. $.afui.setTitle();
  118. $.afui.getTitle().should.eql(title);
  119. //shouldn't animate
  120. $.afui.setTitle("foobar",null,null,true);
  121. var hdr=$($.afui.activeDiv).closest('.view').children("header");
  122. hdr.find("h1").eq(0).html().should.eql("foobar");
  123. hdr.find("h1").length.should.eql(1);
  124. });
  125. it("should disable animating the headers",function(){
  126. $.afui.animateHeader(false);
  127. var div="foobar";
  128. $.afui.loadContent("#"+div);
  129. var hdr=$($.afui.activeDiv).closest('.view').children("header");
  130. hdr.find("h1").eq(0).html().should.eql("foobar");
  131. hdr.find("h1").length.should.eql(1);
  132. });
  133. //Should load a new view
  134. it("Should load a new view",function(done){
  135. var view=$($.afui.activeDiv).closest('.view');
  136. view.find("footer a").eq(2).trigger("click");
  137. setTimeout(function(){
  138. var newView=$($.afui.activeDiv).closest('.view');
  139. expect(view.get(0)).to.not.eql(newView.get(0));
  140. done();
  141. },300);
  142. done();
  143. });
  144. it("should click a tab bar and keep the state",function(done){
  145. $(".tabbed .button").eq(1).trigger("click");
  146. setTimeout(function(){
  147. expect($(".tabbed .button").eq(1).hasClass('pressed')).to.be.true;
  148. done();
  149. },100);
  150. });
  151. it("should disable tab bar",function(done){
  152. $.afui.disableTabBar();
  153. $(".tabbed .button").eq(1).trigger("click");
  154. setTimeout(function(){
  155. //expect($(".tabbed .button").eq(1).hasClass('pressed')).to.be.false;
  156. done();
  157. },100);
  158. });
  159. it("should update a badge",function(){
  160. $.afui.updateBadge("#badgeTest","1","bl","green");
  161. $("#badgeTest").html().should.eql('3<span class="af-badge bl" style="background: green;">1</span>');
  162. })
  163. });