popup.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /**
  2. * Created by JetBrains PhpStorm.
  3. * User: dongyancen
  4. * Date: 12-4-12
  5. * Time: 下午4:47
  6. * To change this template use File | Settings | File Templates.
  7. */
  8. module( 'ui.popup' );
  9. test( '检查显示内容和隐藏方法:getContentHtmlTpl,show(),hide(),isHidden()', function() {
  10. var editor = new baidu.editor.ui.Editor();
  11. stop();
  12. setTimeout(function(){
  13. var autoTypeSetPicker = new baidu.editor.ui.AutoTypeSetPicker({editor:editor});
  14. var popup = new te.obj[0].Popup({content: autoTypeSetPicker,'editor':editor});
  15. var content = autoTypeSetPicker.getHtmlTpl().replace(/##/g, autoTypeSetPicker.id)
  16. .replace(/%%/g, (autoTypeSetPicker.uiName ? 'edui-'+autoTypeSetPicker.uiName : '') + ' ' + autoTypeSetPicker.className);
  17. equal(popup.getContentHtmlTpl(),content, '检查popup的内容');
  18. equal(popup.getDom(),null,'popup初始不显示');
  19. popup.show();
  20. equal(popup.getDom().style.display,'','popup显示成功');
  21. var popupContent = document.getElementById(popup.id+'_content');
  22. equal(popupContent.firstChild.id,autoTypeSetPicker.id,'popup内容autoTypeSetPicker显示');
  23. equal(popup.isHidden(),false,'isHidden==false');
  24. popup.hide();
  25. equal(popup.getDom().style.display,'none','popup隐藏成功');
  26. equal(popup.isHidden(),true,'isHidden==true');
  27. autoTypeSetPicker.dispose();
  28. popup.dispose();
  29. start();
  30. },50);
  31. } );
  32. test( '定位显示popup;mousedown时隐藏popup', function() {
  33. var editor = new baidu.editor.ui.Editor();
  34. editor.render('editor');
  35. editor.ready(function(){
  36. var autoTypeSetPicker = new baidu.editor.ui.AutoTypeSetPicker({editor:editor});
  37. var popup = new te.obj[0].Popup({content: autoTypeSetPicker,'editor':editor});
  38. var uiUtils = baidu.editor.ui.uiUtils;
  39. var leftLocation = 20;
  40. var topLocation = 100;
  41. popup.showAt({left:leftLocation,top:topLocation});
  42. equal($(popup.getDom()).css('top'),topLocation+'px','popup位置:top');
  43. equal($(popup.getDom()).css('left'),leftLocation+'px','popup位置:left');
  44. equal($(popup.getDom()).css('width'),uiUtils.getClientRect(popup.getDom('content')).width+'px','popup位置:width');
  45. ok(uiUtils.getClientRect(popup.getDom('content')).width>uiUtils.getClientRect(autoTypeSetPicker.getDom()).width,'popup的width大于其内容的width');
  46. equal($(popup.getDom()).css('height'),uiUtils.getClientRect(popup.getDom('content')).height+'px','popup位置:height');
  47. ok(uiUtils.getClientRect(popup.getDom('content')).height>uiUtils.getClientRect(autoTypeSetPicker.getDom()).height,'popup的height大于其内容的height');
  48. var popup2 = new te.obj[0].Popup({content: autoTypeSetPicker,'editor':editor});
  49. // var flag = 0;
  50. // popup2.addListener('postRenderAfter',function(){
  51. // flag = 1;
  52. // });
  53. // popup2.postRender();
  54. popup2.show();
  55. ua.mousedown(document.getElementById(popup.id+'_content'));
  56. equal(popup.isHidden(),false,'在popup上mousedown,popup不隐藏');
  57. equal(popup2.isHidden(),true,'在popup上mousedown,popup2隐藏');
  58. popup.show();
  59. popup2.show();
  60. ua.mousedown(document.getElementById('editor'));
  61. equal(popup.isHidden(),true,'在其他位置mousedown,popup隐藏');
  62. equal(popup2.isHidden(),true,'在其他位置mousedown,popup隐藏');
  63. popup.show();
  64. popup2.show();
  65. // $('#editor').scroll();
  66. //// window.scrollTo( 0, document.body.scrollHeight );
  67. // equal(popup.isHidden(),true);
  68. // equal(popup2.isHidden(),true);
  69. autoTypeSetPicker.dispose();
  70. popup.dispose();
  71. popup2.dispose();
  72. start();
  73. });
  74. stop();
  75. } );