cursorRenderer.spec.tsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import {vec2} from 'gl-matrix';
  2. import {LightFlamegraphTheme} from 'sentry/utils/profiling/flamegraph/flamegraphTheme';
  3. import {transformMatrixBetweenRect} from 'sentry/utils/profiling/gl/utils';
  4. import {CursorRenderer} from 'sentry/utils/profiling/renderers/cursorRenderer';
  5. import {Rect} from 'sentry/utils/profiling/speedscope';
  6. describe('CursorRenderer', () => {
  7. it('renders cursor in center screen', () => {
  8. const context = {
  9. beginPath: jest.fn(),
  10. moveTo: jest.fn(),
  11. lineTo: jest.fn(),
  12. strokeStyle: undefined,
  13. stroke: jest.fn(),
  14. };
  15. const canvasMock = {
  16. getContext: jest.fn().mockReturnValue(context),
  17. } as unknown as HTMLCanvasElement;
  18. const renderer = new CursorRenderer(canvasMock, LightFlamegraphTheme);
  19. const cursor = vec2.fromValues(0.5, 0.5);
  20. const physicalSpace = new Rect(0, 0, 1000, 1000);
  21. const configViewToPhysicalSpace = transformMatrixBetweenRect(
  22. new Rect(0, 0, 1, 1),
  23. physicalSpace
  24. );
  25. renderer.draw(cursor, physicalSpace, configViewToPhysicalSpace);
  26. expect(context.beginPath).toHaveBeenCalled();
  27. // Draws vertical line
  28. expect(context.moveTo.mock.calls[0]).toEqual([500, 0]);
  29. expect(context.lineTo.mock.calls[0]).toEqual([500, 1000]);
  30. // Draws horizontal line
  31. expect(context.moveTo.mock.calls[1]).toEqual([0, 500]);
  32. expect(context.lineTo.mock.calls[1]).toEqual([1000, 500]);
  33. expect(context.strokeStyle).toBe(LightFlamegraphTheme.COLORS.CURSOR_CROSSHAIR);
  34. expect(context.stroke).toHaveBeenCalledTimes(1);
  35. });
  36. });