cursorRenderer.spec.tsx 1.5 KB

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