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