standard.spec.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. 'use strict'
  2. /* global describe, it, jsPDF, comparePdf */
  3. /**
  4. * Standard spec tests
  5. *
  6. * These tests return the datauristring so that reference files can be generated.
  7. * We compare the exact output.
  8. */
  9. describe('Drawing functions', () => {
  10. it('should draw circles', () => {
  11. const doc = jsPDF()
  12. doc.ellipse(40, 20, 10, 5)
  13. doc.setFillColor(0, 0, 255)
  14. doc.ellipse(80, 20, 10, 5, 'F')
  15. doc.setLineWidth(1)
  16. doc.setDrawColor(0)
  17. doc.setFillColor(255, 0, 0)
  18. doc.circle(120, 20, 5, 'FD')
  19. comparePdf(doc.output(), 'circles.pdf', 'shapes')
  20. })
  21. it('should draw rectangles', () => {
  22. const doc = jsPDF()
  23. // Empty square
  24. doc.rect(20, 20, 10, 10)
  25. // Filled square
  26. doc.rect(40, 20, 10, 10, 'F')
  27. // Empty red square
  28. doc.setDrawColor(255, 0, 0)
  29. doc.rect(60, 20, 10, 10)
  30. // Filled square with red borders
  31. doc.setDrawColor(255, 0, 0)
  32. doc.rect(80, 20, 10, 10, 'FD')
  33. // Filled red square
  34. doc.setDrawColor(0)
  35. doc.setFillColor(255, 0, 0)
  36. doc.rect(100, 20, 10, 10, 'F')
  37. // Filled red square with black borders
  38. doc.setDrawColor(0)
  39. doc.setFillColor(255, 0, 0)
  40. doc.rect(120, 20, 10, 10, 'FD')
  41. // Black square with rounded corners
  42. doc.setDrawColor(0)
  43. doc.setFillColor(255, 255, 255)
  44. doc.roundedRect(140, 20, 10, 10, 3, 3, 'FD')
  45. comparePdf(doc.output(), 'rectangles.pdf', 'shapes')
  46. })
  47. it('should draw a line', () => {
  48. const doc = jsPDF()
  49. // horizontal line
  50. doc.line(20, 20, 60, 20)
  51. comparePdf(doc.output(), 'line.pdf', 'shapes')
  52. })
  53. it('should draw lines', () => {
  54. const doc = jsPDF()
  55. // horizontal line
  56. doc.line(20, 20, 60, 20)
  57. doc.setLineWidth(0.5)
  58. doc.line(20, 25, 60, 25)
  59. doc.setLineWidth(1)
  60. doc.line(20, 30, 60, 30)
  61. doc.setLineWidth(1.5)
  62. doc.line(20, 35, 60, 35)
  63. // draw red lines
  64. doc.setDrawColor(255, 0, 0)
  65. doc.setLineWidth(0.1)
  66. // vertical line
  67. doc.line(100, 20, 100, 60)
  68. doc.setLineWidth(0.5)
  69. doc.line(105, 20, 105, 60)
  70. doc.setLineWidth(1)
  71. doc.line(110, 20, 110, 60)
  72. doc.setLineWidth(1.5)
  73. doc.line(115, 20, 115, 60)
  74. comparePdf(doc.output(), 'lines.pdf', 'shapes')
  75. })
  76. it('should use grey color mode', () => {
  77. const doc = jsPDF()
  78. doc.setFillColor(22)
  79. doc.rect(20, 20, 10, 10, 'F')
  80. comparePdf(doc.output(), 'fill-color.pdf', 'shapes')
  81. })
  82. })