summarize.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*global describe, expect, it */
  2. 'use strict';
  3. var summarize = require('../../summarize');
  4. describe('summarize', function() {
  5. it('should export handlers', function() {
  6. expect(summarize.handlers).toBeDefined();
  7. expect(typeof summarize.handlers).toBe('object');
  8. });
  9. it('should export a newDoclet handler', function() {
  10. expect(summarize.handlers.newDoclet).toBeDefined();
  11. expect(typeof summarize.handlers.newDoclet).toBe('function');
  12. });
  13. describe('newDoclet handler', function() {
  14. var handler = summarize.handlers.newDoclet;
  15. it('should not blow up if the doclet is missing', function() {
  16. function noDoclet() {
  17. return handler({});
  18. }
  19. expect(noDoclet).not.toThrow();
  20. });
  21. it('should not change the summary if it is already defined', function() {
  22. var doclet = {
  23. summary: 'This is a summary.',
  24. description: 'Descriptions are good.'
  25. };
  26. handler({ doclet: doclet });
  27. expect(doclet.summary).not.toBe(doclet.description);
  28. });
  29. it('should not do anything if the description is missing', function() {
  30. var doclet = {};
  31. handler({ doclet: doclet });
  32. expect(doclet.summary).not.toBeDefined();
  33. });
  34. it('should use the first sentence as the summary', function() {
  35. var doclet = {
  36. description: 'This sentence is the summary. This sentence is not.'
  37. };
  38. handler({ doclet: doclet });
  39. expect(doclet.summary).toBe('This sentence is the summary.');
  40. });
  41. it('should not add an extra period if there is only one sentence in the description',
  42. function() {
  43. var doclet = {
  44. description: 'This description has only one sentence.'
  45. };
  46. handler({ doclet: doclet });
  47. expect(doclet.summary).toBe('This description has only one sentence.');
  48. });
  49. it('should use the entire description, plus a period, as the summary if the description ' +
  50. 'does not contain a period', function() {
  51. var doclet = {
  52. description: 'This is a description'
  53. };
  54. handler({ doclet: doclet });
  55. expect(doclet.summary).toBe('This is a description.');
  56. });
  57. it('should use the entire description as the summary if the description contains only ' +
  58. 'one sentence', function() {
  59. var doclet = {
  60. description: 'This is a description.'
  61. };
  62. handler({ doclet: doclet });
  63. expect(doclet.description).toBe('This is a description.');
  64. });
  65. it('should work when an HTML tag immediately follows the first sentence', function() {
  66. var doclet = {
  67. description: 'This sentence is the summary.<small>This sentence is small.</small>'
  68. };
  69. handler({ doclet: doclet });
  70. expect(doclet.summary).toBe('This sentence is the summary.');
  71. });
  72. it('should generate valid HTML if a tag is opened, but not closed, in the summary',
  73. function() {
  74. var doclet = {
  75. description: 'This description has <em>a tag. The tag straddles</em> sentences.'
  76. };
  77. handler({ doclet: doclet });
  78. expect(doclet.summary).toBe('This description has <em>a tag.</em>');
  79. });
  80. it('should not include a <p> tag in the summary', function() {
  81. var doclet = {
  82. description: '<p>This description contains HTML.</p><p>And plenty of it!</p>'
  83. };
  84. handler({ doclet: doclet });
  85. expect(doclet.summary).toBe('This description contains HTML.');
  86. });
  87. });
  88. });