combox.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /**
  2. * Created by JetBrains PhpStorm.
  3. * User: dongyancen
  4. * Date: 12-4-12
  5. * Time: 下午4:44
  6. * To change this template use File | Settings | File Templates.
  7. */
  8. module( 'ui.combox' );
  9. test( 'combox', function() {
  10. var editor = new baidu.editor.ui.Editor();
  11. editor.render("editor");
  12. //设置菜单内容
  13. var list = [
  14. ['1',[1]],
  15. ['0',[0]],
  16. ['宋体',['宋体', 'SimSun']],
  17. ['楷体',['楷体', '楷体_GB2312', 'SimKai']],
  18. ['黑体',['黑体', 'SimHei']],
  19. ['隶书',['隶书', 'SimLi']],
  20. ['andale mono',['andale mono']],
  21. ['arial',['arial', 'helvetica', 'sans-serif']],
  22. ['arial black',['arial black', 'avant garde']],
  23. ['comic sans ms',['comic sans ms']],
  24. ['impact',['impact', 'chicago']],
  25. ['times new roman',['times new roman']]
  26. ];
  27. var title = list ;
  28. for(var i=0,ci,items=[];ci=list[i++];){
  29. (function(key,val){
  30. items.push({
  31. label: key,
  32. value: val,
  33. renderLabelHtml: function (){
  34. return '<div class="edui-label %%-label" style="font-family:' +
  35. utils.unhtml(this.value.join(',')) + '">' + (this.label || '') + '</div>';
  36. }
  37. });
  38. })(ci[0],ci[1])
  39. }
  40. editor.ready(function(){
  41. var combox = new te.obj[0].Combox({editor:editor,items :items,title: title, initValue:'字体',className: 'edui-for-fontfamily'});
  42. te.dom[0].innerHTML = combox.renderHtml();
  43. combox.postRender();
  44. combox.showPopup();
  45. //////// getItem
  46. equal(combox.getItem(0).label,'1','检查item内容');
  47. equal(combox.getItem(0).value[0],1,'');
  48. ///////getValue setValue
  49. combox.setValue(list[4][1]);
  50. equal(combox.getValue(),list[4][1],'设置内容');
  51. equal(combox.label,'黑体','');
  52. equal(combox.getDom('button_body').innerHTML,"黑体",'');
  53. ////////getLabelForUnknowValue
  54. combox.setValue(['黑体', 'chicago']);
  55. equal(combox.getValue()[0],"黑体",'设置一个不在原来列表的内容');
  56. equal(combox.getValue()[1],'chicago','');
  57. equal(combox.getValue(),combox.label,'');
  58. equal(combox.getDom('button_body').innerHTML,"黑体,chicago",'');
  59. /////selectByIndex
  60. combox.popup.items[2].onclick();
  61. equal(combox.getValue()[0],'宋体','检查onclick,设定选中内容');
  62. equal(combox.getValue()[1],'SimSun','');
  63. equal(items[2].label,combox.label,'');
  64. equal(combox.selectedIndex,2,'');
  65. combox.popup.hide();
  66. start();
  67. });
  68. stop();
  69. } );