diff options
| author | Vojta Jina | 2010-11-15 01:10:16 +0000 |
|---|---|---|
| committer | Misko Hevery | 2010-11-15 21:55:37 -0800 |
| commit | cc749760fd59418433de5a055d1ca401f7500444 (patch) | |
| tree | a6bc273b68b10515b9e00bc0b166c46d88748033 /docs/spec/collectSpec.js | |
| parent | b467a50bc75b7f4c0d9bcee521387eda460337bf (diff) | |
| download | angular.js-cc749760fd59418433de5a055d1ca401f7500444.tar.bz2 | |
Added basic Services, which support @memberOf and @methodOf
Diffstat (limited to 'docs/spec/collectSpec.js')
| -rw-r--r-- | docs/spec/collectSpec.js | 141 |
1 files changed, 141 insertions, 0 deletions
diff --git a/docs/spec/collectSpec.js b/docs/spec/collectSpec.js index f20342b1..9de08dc8 100644 --- a/docs/spec/collectSpec.js +++ b/docs/spec/collectSpec.js @@ -11,6 +11,63 @@ describe('collect', function(){ expect(collect.markdown('<angular/>')). toEqual('<p><tt><angular/></tt></p>'); }); + + it('should not replace anything in <pre>', function(){ + expect(collect.markdown('angular.x\n<pre>\nangular.k\n</pre>\nangular.x')). + toEqual( + '<p><a href="#!angular.x">angular.x</a></p>' + + '<pre>\nangular.k\n</pre>' + + '<p><a href="#!angular.x">angular.x</a></p>'); + }); + }); + + describe('processNgDoc', function() { + var processNgDoc = collect.processNgDoc, + documentation; + + beforeEach(function() { + documentation = { + pages: [], + byName: {} + }; + }); + + it('should store references to docs by name', function() { + var doc = {ngdoc: 'section', name: 'fake', raw: {text:''}}; + processNgDoc(documentation, doc); + expect(documentation.byName.fake).toBe(doc); + }); + + it('should connect doc to owner (specified by @methodOf)', function() { + var parentDoc = {ngdoc: 'section', name: 'parent', raw: {text:''}}; + var doc = {ngdoc: 'section', name: 'child', methodOf: 'parent', raw: {text:''}}; + processNgDoc(documentation, parentDoc); + processNgDoc(documentation, doc); + expect(documentation.byName.parent.method).toBeDefined(); + expect(documentation.byName.parent.method[0]).toBe(doc); + }); + + it('should not add doc to sections if @memberOf specified', function() { + var parentDoc = {ngdoc: 'parent', name: 'parent', raw: {text:''}}; + var doc = {ngdoc: 'child', name: 'child', methodOf: 'parent', raw: {text:''}}; + processNgDoc(documentation, parentDoc); + processNgDoc(documentation, doc); + expect(documentation.pages.child).not.toBeDefined(); + }); + + it('should throw exception if owner does not exist', function() { + expect(function() { + processNgDoc(documentation, {ngdoc: 'section', methodOf: 'not.exist', raw: {text:''}}); + }).toThrow('Owner "not.exist" is not defined.'); + }); + + it('should ignore non-ng docs', function() { + var doc = {name: 'anything'}; + expect(function() { + processNgDoc(documentation, doc); + }).not.toThrow(); + expect(documentation.pages).not.toContain(doc); + }); }); describe('TAG', function(){ @@ -41,6 +98,90 @@ describe('collect', function(){ }); }); + describe('@requires', function() { + it('should parse more @requires tag into array', function() { + TAG.requires(doc, 'requires', '$service'); + TAG.requires(doc, 'requires', '$another'); + + expect(doc.requires).toEqual([ + {name: '$service'}, + {name: '$another'} + ]); + }); + }); + + describe('@property', function() { + it('should parse @property tags into array', function() { + TAG.property(doc, 'property', '{type} name1 desc'); + TAG.property(doc, 'property', '{type} name2 desc'); + expect(doc.property.length).toEqual(2); + }); + + it('should parse @property with only name', function() { + TAG.property(doc, 'property', 'fake'); + expect(doc.property[0].name).toEqual('fake'); + }); + + it('should parse @property with optional type', function() { + TAG.property(doc, 'property', '{string} name'); + expect(doc.property[0].name).toEqual('name'); + expect(doc.property[0].type).toEqual('string'); + }); + + it('should parse @property with optional description', function() { + TAG.property(doc, 'property', 'name desc rip tion'); + expect(doc.property[0].name).toEqual('name'); + expect(doc.property[0].description).toEqual('desc rip tion'); + }); + + it('should parse @property with type and description both', function() { + TAG.property(doc, 'property', '{bool} name desc rip tion'); + expect(doc.property[0].name).toEqual('name'); + expect(doc.property[0].type).toEqual('bool'); + expect(doc.property[0].description).toEqual('desc rip tion'); + }); + + /** + * If property description is undefined, this variable is not set in the template, + * so the whole @description tag is used instead + */ + it('should set undefined description to "false"', function() { + TAG.property(doc, 'property', 'name'); + expect(doc.property[0].description).toBe(false); + }); + }); + + describe('@methodOf', function() { + it('should parse @methodOf tag', function() { + expect(function() { + TAG.methodOf(doc, 'methodOf', 'parentName'); + }).not.toThrow(); + expect(doc.methodOf).toEqual('parentName'); + }); + }); + + describe('@returns', function() { + it('should parse @returns', function() { + expect(function() {TAG.returns(doc, 'returns', '');}) + .not.toThrow(); + }); + + it('should parse @returns with type', function() { + TAG.returns(doc, 'returns', '{string}'); + expect(doc.returns.type).toEqual('string'); + }); + + it('should parse @returns with description', function() { + TAG.returns(doc, 'returns', 'descrip tion'); + expect(doc.returns.description).toEqual('descrip tion'); + }); + + it('should parse @returns with type and description', function() { + TAG.returns(doc, 'returns', '{string} description'); + expect(doc.returns).toEqual({type: 'string', description: 'description'}); + }); + }); + describe('@describe', function(){ it('should support pre blocks', function(){ TAG.description(doc, 'description', '<pre>abc</pre>'); |
