helpers.canvas.tests.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. 'use strict';
  2. describe('Chart.helpers.canvas', function() {
  3. var helpers = Chart.helpers;
  4. describe('clear', function() {
  5. it('should clear the chart canvas', function() {
  6. var chart = acquireChart({}, {
  7. canvas: {
  8. style: 'width: 150px; height: 245px'
  9. }
  10. });
  11. spyOn(chart.ctx, 'clearRect');
  12. helpers.canvas.clear(chart);
  13. expect(chart.ctx.clearRect.calls.count()).toBe(1);
  14. expect(chart.ctx.clearRect.calls.first().object).toBe(chart.ctx);
  15. expect(chart.ctx.clearRect.calls.first().args).toEqual([0, 0, 150, 245]);
  16. });
  17. });
  18. describe('roundedRect', function() {
  19. it('should create a rounded rectangle path', function() {
  20. var context = window.createMockContext();
  21. helpers.canvas.roundedRect(context, 10, 20, 30, 40, 5);
  22. expect(context.getCalls()).toEqual([
  23. {name: 'moveTo', args: [15, 20]},
  24. {name: 'lineTo', args: [35, 20]},
  25. {name: 'quadraticCurveTo', args: [40, 20, 40, 25]},
  26. {name: 'lineTo', args: [40, 55]},
  27. {name: 'quadraticCurveTo', args: [40, 60, 35, 60]},
  28. {name: 'lineTo', args: [15, 60]},
  29. {name: 'quadraticCurveTo', args: [10, 60, 10, 55]},
  30. {name: 'lineTo', args: [10, 25]},
  31. {name: 'quadraticCurveTo', args: [10, 20, 15, 20]}
  32. ]);
  33. });
  34. it('should optimize path if radius is 0', function() {
  35. var context = window.createMockContext();
  36. helpers.canvas.roundedRect(context, 10, 20, 30, 40, 0);
  37. expect(context.getCalls()).toEqual([{name: 'rect', args: [10, 20, 30, 40]}]);
  38. });
  39. });
  40. });