virtualizedViewManager.spec.tsx 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. import {TraceScheduler} from 'sentry/views/performance/newTraceDetails/traceRenderers/traceScheduler';
  2. import {TraceView} from 'sentry/views/performance/newTraceDetails/traceRenderers/traceView';
  3. import {VirtualizedViewManager} from 'sentry/views/performance/newTraceDetails/traceRenderers/virtualizedViewManager';
  4. describe('VirtualizedViewManger', () => {
  5. it('initializes space', () => {
  6. const manager = new VirtualizedViewManager(
  7. {
  8. list: {width: 0.5},
  9. span_list: {width: 0.5},
  10. },
  11. new TraceScheduler(),
  12. new TraceView()
  13. );
  14. manager.view.setTraceSpace([10_000, 0, 1000, 1]);
  15. expect(manager.view.trace_space.serialize()).toEqual([0, 0, 1000, 1]);
  16. expect(manager.view.trace_view.serialize()).toEqual([0, 0, 1000, 1]);
  17. });
  18. it('initializes physical space', () => {
  19. const manager = new VirtualizedViewManager(
  20. {
  21. list: {width: 0.5},
  22. span_list: {width: 0.5},
  23. },
  24. new TraceScheduler(),
  25. new TraceView()
  26. );
  27. manager.view.setTracePhysicalSpace([0, 0, 1000, 1], [0, 0, 500, 1]);
  28. expect(manager.view.trace_container_physical_space.serialize()).toEqual([
  29. 0, 0, 1000, 1,
  30. ]);
  31. expect(manager.view.trace_physical_space.serialize()).toEqual([0, 0, 500, 1]);
  32. });
  33. describe('computeSpanCSSMatrixTransform', () => {
  34. it('enforces min scaling', () => {
  35. const manager = new VirtualizedViewManager(
  36. {
  37. list: {width: 0},
  38. span_list: {width: 1},
  39. },
  40. new TraceScheduler(),
  41. new TraceView()
  42. );
  43. manager.view.setTraceSpace([0, 0, 1000, 1]);
  44. manager.view.setTracePhysicalSpace([0, 0, 1000, 1], [0, 0, 1000, 1]);
  45. expect(manager.computeSpanCSSMatrixTransform([0, 0.1])).toEqual([
  46. 0.001, 0, 0, 1, 0, 0,
  47. ]);
  48. });
  49. it('computes width scaling correctly', () => {
  50. const manager = new VirtualizedViewManager(
  51. {
  52. list: {width: 0},
  53. span_list: {width: 1},
  54. },
  55. new TraceScheduler(),
  56. new TraceView()
  57. );
  58. manager.view.setTraceSpace([0, 0, 100, 1]);
  59. manager.view.setTracePhysicalSpace([0, 0, 1000, 1], [0, 0, 1000, 1]);
  60. expect(manager.computeSpanCSSMatrixTransform([0, 100])).toEqual([1, 0, 0, 1, 0, 0]);
  61. });
  62. it('computes x position correctly', () => {
  63. const manager = new VirtualizedViewManager(
  64. {
  65. list: {width: 0},
  66. span_list: {width: 1},
  67. },
  68. new TraceScheduler(),
  69. new TraceView()
  70. );
  71. manager.view.setTraceSpace([0, 0, 1000, 1]);
  72. manager.view.setTracePhysicalSpace([0, 0, 1000, 1], [0, 0, 1000, 1]);
  73. expect(manager.computeSpanCSSMatrixTransform([50, 1000])).toEqual([
  74. 1, 0, 0, 1, 50, 0,
  75. ]);
  76. });
  77. it('computes span x position correctly', () => {
  78. const manager = new VirtualizedViewManager(
  79. {
  80. list: {width: 0},
  81. span_list: {width: 1},
  82. },
  83. new TraceScheduler(),
  84. new TraceView()
  85. );
  86. manager.view.setTraceSpace([0, 0, 1000, 1]);
  87. manager.view.setTracePhysicalSpace([0, 0, 1000, 1], [0, 0, 1000, 1]);
  88. expect(manager.computeSpanCSSMatrixTransform([50, 1000])).toEqual([
  89. 1, 0, 0, 1, 50, 0,
  90. ]);
  91. });
  92. describe('when start is not 0', () => {
  93. it('computes width scaling correctly', () => {
  94. const manager = new VirtualizedViewManager(
  95. {
  96. list: {width: 0},
  97. span_list: {width: 1},
  98. },
  99. new TraceScheduler(),
  100. new TraceView()
  101. );
  102. manager.view.setTraceSpace([100, 0, 100, 1]);
  103. manager.view.setTracePhysicalSpace([0, 0, 1000, 1], [0, 0, 1000, 1]);
  104. expect(manager.computeSpanCSSMatrixTransform([100, 100])).toEqual([
  105. 1, 0, 0, 1, 0, 0,
  106. ]);
  107. });
  108. it('computes x position correctly when view is offset', () => {
  109. const manager = new VirtualizedViewManager(
  110. {
  111. list: {width: 0},
  112. span_list: {width: 1},
  113. },
  114. new TraceScheduler(),
  115. new TraceView()
  116. );
  117. manager.view.setTraceSpace([100, 0, 100, 1]);
  118. manager.view.setTracePhysicalSpace([0, 0, 1000, 1], [0, 0, 1000, 1]);
  119. expect(manager.computeSpanCSSMatrixTransform([100, 100])).toEqual([
  120. 1, 0, 0, 1, 0, 0,
  121. ]);
  122. });
  123. });
  124. });
  125. describe('transformXFromTimestamp', () => {
  126. it('computes x position correctly', () => {
  127. const manager = new VirtualizedViewManager(
  128. {
  129. list: {width: 0},
  130. span_list: {width: 1},
  131. },
  132. new TraceScheduler(),
  133. new TraceView()
  134. );
  135. manager.view.setTraceSpace([0, 0, 1000, 1]);
  136. manager.view.setTracePhysicalSpace([0, 0, 1000, 1], [0, 0, 1000, 1]);
  137. expect(manager.transformXFromTimestamp(50)).toEqual(50);
  138. });
  139. it('computes x position correctly when view is offset', () => {
  140. const manager = new VirtualizedViewManager(
  141. {
  142. list: {width: 0},
  143. span_list: {width: 1},
  144. },
  145. new TraceScheduler(),
  146. new TraceView()
  147. );
  148. manager.view.setTraceSpace([50, 0, 1000, 1]);
  149. manager.view.setTracePhysicalSpace([0, 0, 1000, 1], [0, 0, 1000, 1]);
  150. manager.view.trace_view.x = 50;
  151. expect(manager.transformXFromTimestamp(-50)).toEqual(-150);
  152. });
  153. it('when view is offset and scaled', () => {
  154. const manager = new VirtualizedViewManager(
  155. {
  156. list: {width: 0},
  157. span_list: {width: 1},
  158. },
  159. new TraceScheduler(),
  160. new TraceView()
  161. );
  162. manager.view.setTraceSpace([100, 0, 1000, 1]);
  163. manager.view.setTracePhysicalSpace([0, 0, 1000, 1], [0, 0, 1000, 1]);
  164. manager.view.setTraceView({width: 500, x: 500});
  165. expect(Math.round(manager.transformXFromTimestamp(100))).toEqual(-500);
  166. });
  167. });
  168. });