toasts.test.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. describe("toast",function(){
  2. before(function(){
  3. $("#toasttest").remove();
  4. $(document.body).append("<div id='toasttest'></div>");
  5. $("#toasttest").append(__html__['test/fixtures/toast.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. $("#toasttest").remove();
  15. });
  16. it("should display a toast and auto hide",function(done){
  17. var msg="Hello 1";
  18. $(document.body).toast({message:msg,delay:100});
  19. setTimeout(function(){
  20. $('.afToastContainer').find(".afToast div").html().should.eql(msg);
  21. setTimeout(function(){
  22. expect( $('.afToastContainer').find(".afToast").length===0).to.be.true;
  23. done();
  24. },500);
  25. },50);
  26. });
  27. it("should display a toast and stay open",function(done){
  28. var msg="Hello 2";
  29. $(document.body).toast({message:msg,autoClose:false});
  30. setTimeout(function(){
  31. $('.afToastContainer').find(".afToast div").html().should.eql(msg);
  32. setTimeout(function(){
  33. expect( $('.afToastContainer').find(".afToast").length===1).to.be.true;
  34. done();
  35. },500);
  36. },50);
  37. });
  38. it("should close a toast by clicking it",function(done){
  39. expect( $('.afToastContainer').find(".afToast").length===1).to.be.true;
  40. $('.afToastContainer').find(".afToast").trigger("click");
  41. setTimeout(function(){
  42. expect( $('.afToastContainer').find(".afToast").length===0).to.be.true;
  43. done();
  44. },350);
  45. });
  46. it("should not animate hiding",function(done){
  47. var msg="Hello 2";
  48. $.os.android=true;
  49. $(document.body).toast({message:msg,autoClose:true,delay:100});
  50. setTimeout(function(){
  51. $('.afToastContainer').find(".afToast div").html().should.eql(msg);
  52. setTimeout(function(){
  53. expect( $('.afToastContainer').find(".afToast").length===0).to.be.true;
  54. $.os.android=false;
  55. done();
  56. },300);
  57. },50);
  58. });
  59. it("should be bottom center with warning class",function(done){
  60. var msg="Hello 6";
  61. $(document.body).toast({message:msg,autoClose:true,delay:100,position:"bc",type:"warning"});
  62. setTimeout(function(){
  63. var elem=$('.afToastContainer').find(".afToast");
  64. expect(elem.hasClass("warning")).to.be.true;
  65. expect(elem.parent().hasClass("bc")).to.be.true;
  66. setTimeout(function(){
  67. expect( $('.afToastContainer').find(".afToast").length===0).to.be.true;
  68. done();
  69. },500);
  70. },50);
  71. });
  72. it("should launch and dispatch ready function",function(done){
  73. $.afui.ready(function(){
  74. done();
  75. });
  76. $.afui.launch();
  77. });
  78. it("should use the data directive for a toast",function(done){
  79. var item=$("#toasttest").find("a").eq(1);
  80. item.trigger("click");
  81. setTimeout(function(){
  82. $('.afToastContainer').find(".afToast div").html().should.eql(item.attr("data-message"));
  83. var elem=$('.afToastContainer').find(".afToast");
  84. expect(elem.hasClass(item.attr("data-type"))).to.be.true;
  85. expect(elem.parent().hasClass(item.attr("data-position"))).to.be.true;
  86. $('.afToastContainer').find(".afToast div").trigger("click");
  87. setTimeout(function(){
  88. expect( $('.afToastContainer').find(".afToast").length===0).to.be.true;
  89. done();
  90. },500);
  91. },50);
  92. })
  93. });