diff options
| author | Misko Hevery | 2011-01-25 21:55:11 -0800 |
|---|---|---|
| committer | Igor Minar | 2011-01-26 23:31:15 -0800 |
| commit | bd33f60276a0fa37acffbad7a0cdcff92db594c8 (patch) | |
| tree | 7cd957c19182ddc430a6320b77b2f03cb1bd223d /docs/spec/ngdocSpec.js | |
| parent | 8682befc7284a3c0b35cd5d85d4f42b1484ec71a (diff) | |
| download | angular.js-bd33f60276a0fa37acffbad7a0cdcff92db594c8.tar.bz2 | |
Added part of guide documentation and supporting changes to doc generator
Diffstat (limited to 'docs/spec/ngdocSpec.js')
| -rw-r--r-- | docs/spec/ngdocSpec.js | 119 |
1 files changed, 103 insertions, 16 deletions
diff --git a/docs/spec/ngdocSpec.js b/docs/spec/ngdocSpec.js index 8f57e329..9d84ee7e 100644 --- a/docs/spec/ngdocSpec.js +++ b/docs/spec/ngdocSpec.js @@ -19,9 +19,28 @@ describe('ngdoc', function(){ describe('metadata', function(){ it('should find keywords', function(){ - expect(new Doc('\nHello: World! @ignore.').keywords()).toEqual('hello world'); + expect(new Doc('\nHello: World! @ignore. $abc').keywords()).toEqual('$abc hello world'); expect(new Doc('The `ng:class-odd` and').keywords()).toEqual('and ng:class-odd the'); }); + + it('should have shortName', function(){ + var d1 = new Doc('@name a.b.c').parse(); + var d2 = new Doc('@name a.b.ng:c').parse(); + var d3 = new Doc('@name some text: more text').parse(); + expect(ngdoc.metadata([d1])[0].shortName).toEqual('c'); + expect(ngdoc.metadata([d2])[0].shortName).toEqual('ng:c'); + expect(ngdoc.metadata([d3])[0].shortName).toEqual('more text'); + }); + + it('should have depth information', function(){ + var d1 = new Doc('@name a.b.c').parse(); + var d2 = new Doc('@name a.b.ng:c').parse(); + var d3 = new Doc('@name some text: more text').parse(); + expect(ngdoc.metadata([d1])[0].depth).toEqual(2); + expect(ngdoc.metadata([d2])[0].depth).toEqual(2); + expect(ngdoc.metadata([d3])[0].depth).toEqual(1); + }); + }); describe('parse', function(){ @@ -61,9 +80,68 @@ describe('ngdoc', function(){ expect(doc.example).toEqual('A\n\nB'); }); - }); + it('should parse filename', function(){ + var doc = new Doc('@name friendly name', 'docs/a.b.ngdoc', 1); + doc.parse(0); + expect(doc.id).toEqual('a.b'); + expect(doc.name).toEqual('friendly name'); + }); + it('should escape <doc:source> element', function(){ + var doc = new Doc('@description before <doc:example>' + + '<doc:source>\n<>\n</doc:source></doc:example> after'); + doc.parse(); + expect(doc.description).toContain('<p>before </p><doc:example>' + + '<doc:source>\n<>\n</doc:source></doc:example><p>after</p>'); + }); + + it('should escape <doc:scenario> element', function(){ + var doc = new Doc('@description before <doc:example>' + + '<doc:scenario>\n<>\n</doc:scenario></doc:example> after'); + doc.parse(); + expect(doc.description).toContain('<p>before </p><doc:example>' + + '<doc:scenario>\n<>\n</doc:scenario></doc:example><p>after</p>'); + }); + + describe('sorting', function(){ + function property(name) { + return function(obj) {return obj[name];}; + } + function noop(){} + function doc(type, name){ + return { + id: name, + ngdoc: type, + keywords: noop + }; + } + + var angular_widget = doc('overview', 'angular.widget'); + var angular_x = doc('function', 'angular.x'); + var angular_y = doc('property', 'angular.y'); + + it('should put angular.fn() in front of angular.widget, etc', function(){ + expect(ngdoc.metadata([angular_widget, angular_y, angular_x]).map(property('id'))) + .toEqual(['angular.x', 'angular.y', 'angular.widget' ]); + }); + }); + }); + }); + describe('scenario', function(){ + it('should render from @example/@scenario and <doc:example>', function(){ + var doc = new Doc( + '@id id\n' + + '@description <doc:example><doc:scenario>scenario0</doc:scenario></doc:example>' + + '@example exempleText\n' + + '@scenario scenario1\n' + + '@scenario scenario2').parse(); + expect(ngdoc.scenarios([doc])).toContain('describe("id"'); + expect(ngdoc.scenarios([doc])).toContain('navigateTo("index.html#!id")'); + expect(ngdoc.scenarios([doc])).toContain('\n scenario0\n'); + expect(ngdoc.scenarios([doc])).toContain('\n scenario1\n'); + expect(ngdoc.scenarios([doc])).toContain('\n scenario2\n'); + }); }); describe('markdown', function(){ @@ -86,8 +164,9 @@ describe('ngdoc', function(){ it('should replace text between two <pre></pre> tags', function() { expect(markdown('<pre>x</pre># One<pre>b</pre>')). - toMatch('</div><h3>One</h3><div'); + toMatch('</div><h1>One</h1><div'); }); + }); describe('trim', function(){ @@ -230,7 +309,7 @@ describe('ngdoc', function(){ expect(doc.description). toBe('<p>foo </p>' + '<div ng:non-bindable><pre class="brush: js; html-script: true;">abc</pre></div>' + - '<h3>bah</h3>\n\n' + + '<h1>bah</h1>\n\n' + '<p>foo </p>' + '<div ng:non-bindable><pre class="brush: js; html-script: true;">cba</pre></div>'); @@ -243,18 +322,15 @@ describe('ngdoc', function(){ '{@link angular.directive.ng:foo ng:foo}'); doc.parse(); expect(doc.description). - toBe('<p>foo <a href="#!angular.foo"><code>angular.foo</code></a></p>\n\n' + - '<p>da <a href="#!angular.foo"><code>bar foo bar</code></a> </p>\n\n' + - '<p>dad<a href="#!angular.foo"><code>angular.foo</code></a></p>\n\n' + - '<p><a href="#!angular.directive.ng:foo"><code>ng:foo</code></a></p>'); - }); - - it('should increment all headings by two', function() { - var doc = new Doc('@description # foo\nabc\n## bar \n xyz'); - doc.parse(); + toContain('foo <a href="#!angular.foo"><code>angular.foo</code></a>'); + expect(doc.description). + toContain('da <a href="#!angular.foo"><code>bar foo bar</code></a>'); expect(doc.description). - toBe('<h3>foo</h3>\n\n<p>abc</p>\n\n<h4>bar</h4>\n\n<p>xyz</p>'); + toContain('dad<a href="#!angular.foo"><code>angular.foo</code></a>'); + expect(doc.description). + toContain('<a href="#!angular.directive.ng:foo"><code>ng:foo</code></a>'); }); + }); describe('@example', function(){ @@ -291,8 +367,8 @@ describe('ngdoc', function(){ }); - describe('@deprecated', function() { - it('should parse @deprecated', function() { + describe('@depricated', function() { + it('should parse @depricated', function() { var doc = new Doc('@deprecated Replaced with foo.'); doc.parse(); expect(doc.deprecated).toBe('Replaced with foo.'); @@ -315,6 +391,17 @@ describe('ngdoc', function(){ }); describe('usage', function(){ + describe('overview', function(){ + it('should supress description heading', function(){ + var doc = new Doc('@ngdoc overview\n@name angular\n@description\n#heading\ntext'); + doc.parse(); + expect(doc.html()).toContain('text'); + expect(doc.html()).toContain('<h2>heading</h2>'); + expect(doc.html()).not.toContain('Description'); + }); + }); + + describe('filter', function(){ it('should format', function(){ var doc = new Doc({ |
