popup.test.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. describe("popup",function(){
  2. before(function(){
  3. $("#popuptest").remove();
  4. $(document.body).append("<div id='popuptest'></div>");
  5. $("#popuptest").append(__html__['test/fixtures/popup.html']);
  6. $.afui.isLaunching=false;
  7. $.afui.hasLaunched=true;
  8. $.afui.launchCompleted=false;
  9. $.afui.defaultPanel=null;
  10. $.afui.activeDiv=null;
  11. $.afui.launch();
  12. });
  13. after(function(){
  14. $("#popuptest").remove();
  15. });
  16. it("should display a popup and dismiss it",function(done){
  17. var msg="Hello 1";
  18. $(document.body).popup({title:'Alert',id:'myTestPopup'});
  19. setTimeout(function(){
  20. $('#myTestPopup').length.should.eql(1);
  21. $("#myTestPopup").trigger("close");
  22. setTimeout(function(){
  23. $('#myTestPopup').length.should.eql(0);
  24. done();
  25. },300);
  26. },200);
  27. });
  28. it("should display a popup execute the done callback",function(done){
  29. var msg="Hello 1";
  30. var what=false;
  31. $(document.body).popup({
  32. id:"myTestPopup",
  33. title:"Alert! Alert!",
  34. message:"This is a test of the emergency alert system!! Don't PANIC!",
  35. cancelText:"Cancel me",
  36. cancelCallback: function(){console.log("cancelled");},
  37. doneText:"I'm done!",
  38. doneCallback: function(){what=true;},
  39. cancelOnly:false,
  40. doneClass:'button',
  41. cancelClass:'button',
  42. onShow:function(){},
  43. autoCloseDone:true, //default is true will close the popup when done is clicked.
  44. suppressTitle:false //Do not show the title if set to true
  45. });
  46. setTimeout(function(){
  47. $('#myTestPopup').length.should.eql(1);
  48. $("#myTestPopup #action").trigger("click");
  49. setTimeout(function(){
  50. $('#myTestPopup').length.should.eql(0);
  51. expect(what).to.be.true;
  52. done();
  53. },300);
  54. },200);
  55. });
  56. it("should display a popup execute the cancel callback",function(done){
  57. var msg="Hello 1";
  58. var what=false;
  59. $(document.body).popup({
  60. id:"myTestPopup",
  61. title:"Alert! Alert!",
  62. message:"This is a test of the emergency alert system!! Don't PANIC!",
  63. cancelText:"Cancel me",
  64. cancelOnly:true,
  65. cancelCallback: function(){what=true;},
  66. doneText:"I'm done!",
  67. doneCallback: function(){what=false;},
  68. cancelOnly:false,
  69. doneClass:'button',
  70. cancelClass:'button',
  71. onShow:function(){},
  72. autoCloseDone:true, //default is true will close the popup when done is clicked.
  73. suppressTitle:false //Do not show the title if set to true
  74. });
  75. setTimeout(function(){
  76. $('#myTestPopup').length.should.eql(1);
  77. $("#myTestPopup #cancel").trigger("click");
  78. setTimeout(function(){
  79. $('#myTestPopup').length.should.eql(0);
  80. expect(what).to.be.true;
  81. done();
  82. },300);
  83. },200);
  84. });
  85. it("should display a popup and dismiss it",function(done){
  86. var msg="Hello 1";
  87. $(document.body).popup({title:'Alert',id:'myTestPopup'});
  88. setTimeout(function(){
  89. $('#myTestPopup').length.should.eql(1);
  90. $("#myTestPopup").trigger("close");
  91. setTimeout(function(){
  92. $('#myTestPopup').length.should.eql(0);
  93. done();
  94. },300);
  95. },200);
  96. });
  97. it("should launch and dispatch ready function",function(done){
  98. $.afui.ready(function(){
  99. done();
  100. });
  101. $.afui.launch();
  102. });
  103. /// data directives
  104. /*
  105. it("should display a data directive popup and dismiss it",function(done){
  106. $("#popuptest a").trigger("click");
  107. setTimeout(function(){
  108. $('.afPopup').length.should.eql(1);
  109. $(".afPopup").trigger("close");
  110. setTimeout(function(){
  111. $('.afPopup').length.should.eql(0);
  112. done();
  113. },300);
  114. },200);
  115. });
  116. */
  117. });