positionIndicatorRenderer.spec.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import {mat3, vec2} from 'gl-matrix';
  2. import {LightFlamegraphTheme} from 'sentry/utils/profiling/flamegraph/flamegraphTheme';
  3. import {Rect} from 'sentry/utils/profiling/gl/utils';
  4. import {PositionIndicatorRenderer} from 'sentry/utils/profiling/renderers/positionIndicatorRenderer';
  5. describe('PositionIndicatorRenderer', () => {
  6. it('draws nothing if view is not zoomed', () => {
  7. const configView = new Rect(0, 0, 100, 100);
  8. const configSpace = new Rect(0, 0, 100, 100);
  9. const context: Partial<CanvasRenderingContext2D> = {
  10. beginPath: jest.fn(),
  11. rect: jest.fn(),
  12. fill: jest.fn(),
  13. strokeRect: jest.fn(),
  14. fillStyle: undefined,
  15. strokeStyle: undefined,
  16. lineWidth: undefined,
  17. };
  18. const canvas: Partial<HTMLCanvasElement> = {
  19. getContext: jest.fn().mockReturnValue(context),
  20. };
  21. const renderer = new PositionIndicatorRenderer(
  22. canvas as HTMLCanvasElement,
  23. LightFlamegraphTheme
  24. );
  25. renderer.draw(configView, configSpace, mat3.identity(mat3.create()));
  26. expect(context.beginPath).not.toHaveBeenCalled();
  27. });
  28. it('draws if view is not zoomed', () => {
  29. const configView = new Rect(40, 40, 20, 100);
  30. const configSpace = new Rect(0, 0, 100, 100);
  31. const context: Partial<CanvasRenderingContext2D> = {
  32. beginPath: jest.fn(),
  33. rect: jest.fn(),
  34. fill: jest.fn(),
  35. strokeRect: jest.fn(),
  36. fillStyle: undefined,
  37. strokeStyle: undefined,
  38. lineWidth: undefined,
  39. };
  40. const canvas: Partial<HTMLCanvasElement> = {
  41. getContext: jest.fn().mockReturnValue(context),
  42. };
  43. const renderer = new PositionIndicatorRenderer(
  44. canvas as HTMLCanvasElement,
  45. LightFlamegraphTheme
  46. );
  47. renderer.draw(
  48. configView,
  49. configSpace,
  50. mat3.fromScaling(mat3.create(), vec2.fromValues(2, 2))
  51. );
  52. expect(context.beginPath).toHaveBeenCalled();
  53. // @ts-ignore this is a mock
  54. expect(context.rect.mock.calls[0]).toEqual([0, 0, 200, 200]);
  55. // @ts-ignore this is a mock
  56. // We offset x by width of the border be
  57. expect(context.rect.mock.calls[1]).toEqual([
  58. 80 - LightFlamegraphTheme.SIZES.MINIMAP_POSITION_OVERLAY_BORDER_WIDTH,
  59. 80,
  60. 40 + LightFlamegraphTheme.SIZES.MINIMAP_POSITION_OVERLAY_BORDER_WIDTH,
  61. 200,
  62. ]);
  63. });
  64. });