node.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. describe("node", function () {
  2. //初始化kityminder
  3. var kityMinderDiv = document.createElement("div");
  4. kityMinderDiv.id = "kityminder";
  5. kityMinderDiv.style.height = "500px";
  6. kityMinderDiv.style.position = "relative";
  7. var obj;
  8. var km;
  9. beforeEach(function(){
  10. document.body.appendChild(kityMinderDiv);
  11. km = KM.getMinder('kityminder', window.KITYMINDER_CONFIG);
  12. obj = document.getElementById('kityminder');
  13. });
  14. afterEach(function(){
  15. // obj = null;
  16. // document.body.removeChild(kityMinderDiv);
  17. });
  18. //kityminder初始化end
  19. var root = new KM.MinderNode('root');
  20. var first = new KM.MinderNode('first');
  21. first.appendChild(new KM.MinderNode('first.first'));
  22. first.setData({
  23. 'layout':{
  24. x:1,
  25. y:1
  26. }
  27. })
  28. var second = new KM.MinderNode('second');
  29. second.appendChild(new KM.MinderNode('second.first'));
  30. root.appendChild(first);
  31. root.appendChild(second);
  32. describe('clone',function(){
  33. var _tmp = root.clone();
  34. it('克隆的root有2级孩子',function(){
  35. expect(_tmp.getFirstChild()).not.toBeNull();
  36. expect(_tmp.getFirstChild().getFirstChild()).not.toBeNull();
  37. expect(_tmp.getFirstChild().getData('text')).toBe('first');
  38. expect(_tmp.getFirstChild().getFirstChild().getData('text')).toBe('first.first');
  39. });
  40. it('检测属性的深度复制',function(){
  41. first.getData('layout').x = 2;
  42. expect(_tmp.getFirstChild().getData('layout').x).toBe(1);
  43. })
  44. });
  45. describe('contains',function(){
  46. it('root contain first',function(){
  47. expect(root.contains(first)).toBeTruthy();
  48. });
  49. it('root contain first.first',function(){
  50. expect(root.contains(first.getFirstChild())).toBeTruthy();
  51. });
  52. it('first not contain second',function(){
  53. expect(root.contains(first.getFirstChild())).toBeTruthy();
  54. });
  55. it('first contain first',function(){
  56. expect(first.contains(first)).toBeTruthy();
  57. });
  58. });
  59. describe('getCommonAncestor',function(){
  60. it('first second commonAncestor is root',function(){
  61. expect(first.getCommonAncestor(second)).toBe(root);
  62. });
  63. it('root first.first commonAncestor is root',function(){
  64. expect(first.getFirstChild().getCommonAncestor(root)).toBe(root);
  65. });
  66. it('second.first first.first commonAncestor is root',function(){
  67. var a = first.getFirstChild(),b=second.getFirstChild();
  68. expect(a.getCommonAncestor(b)).toBe(root);
  69. });
  70. });
  71. describe('setData',function(){
  72. it('name and value both exist',function(){
  73. root.setData('test',1);
  74. expect(root.getData('test')).toBe(1);
  75. });
  76. it('name only exist clear property',function(){
  77. root.setData('test');
  78. expect(root.getData('test')).toBeUndefined();
  79. });
  80. it('name is object',function(){
  81. root.setData({
  82. 'test':1
  83. });
  84. expect(root.getData('test')).toBe(1);
  85. });
  86. it('name and value both empty',function(){
  87. root.setData('test',1);
  88. root.setData('test1',2);
  89. root.setData();
  90. expect(root.getData('test')).toBeUndefined();
  91. expect(root.getData('test1')).toBeUndefined();
  92. });
  93. it('layout:{x:1,y:1}',function(){
  94. root.setData({
  95. 'layout':{
  96. x:1,
  97. y:1
  98. }
  99. });
  100. expect(root.getData('layout').x).toBe(1);
  101. });
  102. });
  103. });