selectedFrameRenderer.spec.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import {mat3, vec2} from 'gl-matrix';
  2. import {Rect} from 'sentry/utils/profiling/gl/utils';
  3. import {SelectedFrameRenderer} from 'sentry/utils/profiling/renderers/selectedFrameRenderer';
  4. describe('SelectedFrameRenderer', () => {
  5. it('draws rect in center', () => {
  6. const context: Partial<CanvasRenderingContext2D> = {
  7. measureText: jest.fn().mockImplementation(n => {
  8. return {width: n.length};
  9. }),
  10. strokeStyle: undefined,
  11. lineWidth: undefined,
  12. beginPath: jest.fn(),
  13. fillText: jest.fn(),
  14. strokeRect: jest.fn(),
  15. };
  16. const canvas: Partial<HTMLCanvasElement> = {
  17. getContext: jest.fn().mockReturnValue(context),
  18. };
  19. const renderer = new SelectedFrameRenderer(canvas as HTMLCanvasElement);
  20. renderer.draw(
  21. new Rect(0, 0, 100, 100),
  22. {BORDER_COLOR: 'red', BORDER_WIDTH: 1},
  23. mat3.scale(mat3.create(), mat3.identity(mat3.create()), vec2.fromValues(2, 2))
  24. );
  25. expect(context.beginPath).toHaveBeenCalled();
  26. expect(context.strokeStyle).toBe('red');
  27. expect(context.lineWidth).toBe(1);
  28. expect(context.strokeRect).toHaveBeenLastCalledWith(0.5, 0.5, 199, 199);
  29. });
  30. });