VirtualizedTreeNode.spec.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import {VirtualizedTreeNode} from 'sentry/utils/profiling/hooks/useVirtualizedTree/VirtualizedTreeNode';
  2. describe('VirtualizedTreeNode', () => {
  3. describe('getVisibleChildrenCount', () => {
  4. it('should return 0 if the node is not expanded', () => {
  5. const root = new VirtualizedTreeNode({id: 0}, null, 0);
  6. const child_1 = new VirtualizedTreeNode({id: 1}, root, 1);
  7. const child_2 = new VirtualizedTreeNode({id: 2}, root, 1);
  8. root.children = [child_1, child_2];
  9. expect(root.getVisibleChildrenCount()).toBe(0);
  10. });
  11. it('should return children count if the root is expanded', () => {
  12. const root = new VirtualizedTreeNode({id: 0}, null, 0);
  13. const child_1 = new VirtualizedTreeNode({id: 1}, root, 1);
  14. const child_2 = new VirtualizedTreeNode({id: 2}, root, 1);
  15. root.children = [child_1];
  16. child_1.children = [child_2];
  17. root.setExpanded(true);
  18. expect(root.getVisibleChildrenCount()).toBe(1);
  19. child_1.setExpanded(true);
  20. expect(root.getVisibleChildrenCount()).toBe(2);
  21. });
  22. });
  23. describe('setExpanded', () => {
  24. it('expands node', () => {
  25. const root = new VirtualizedTreeNode({id: 0}, null, 0);
  26. const child_1 = new VirtualizedTreeNode({id: 1}, root, 1);
  27. root.children = [child_1];
  28. root.setExpanded(true, {expandChildren: false});
  29. expect(root.expanded).toBe(true);
  30. expect(child_1.expanded).toBe(false);
  31. });
  32. it('expands all children', () => {
  33. const root = new VirtualizedTreeNode({id: 0}, null, 0);
  34. const child_1 = new VirtualizedTreeNode({id: 1}, root, 1);
  35. const child_2 = new VirtualizedTreeNode({id: 2}, root, 1);
  36. root.children = [child_1];
  37. child_1.children = [child_2];
  38. root.setExpanded(true, {expandChildren: true});
  39. expect(root.expanded).toBe(true);
  40. expect(child_1.expanded).toBe(true);
  41. expect(child_2.expanded).toBe(true);
  42. });
  43. });
  44. });