From bd33f60276a0fa37acffbad7a0cdcff92db594c8 Mon Sep 17 00:00:00 2001
From: Misko Hevery
Date: Tue, 25 Jan 2011 21:55:11 -0800
Subject: Added part of guide documentation and supporting changes to doc
generator
---
docs/spec/domSpec.js | 32 +++++++++++--
docs/spec/ngdocSpec.js | 119 ++++++++++++++++++++++++++++++++++++++++++-------
2 files changed, 132 insertions(+), 19 deletions(-)
(limited to 'docs/spec')
diff --git a/docs/spec/domSpec.js b/docs/spec/domSpec.js
index 58063789..f9308ed6 100644
--- a/docs/spec/domSpec.js
+++ b/docs/spec/domSpec.js
@@ -1,9 +1,14 @@
var DOM = require('dom.js').DOM;
describe('dom', function(){
+ var dom;
+
+ beforeEach(function(){
+ dom = new DOM();
+ });
+
describe('example', function(){
it('should render code, live, test', function(){
- var dom = new DOM();
dom.example('desc', 'src', 'scenario');
expect(dom.toString()).toEqual(
'
' +
@@ -26,10 +30,32 @@ describe('dom', function(){
});
it('should render non-live, test', function(){
- var dom = new DOM();
dom.example('desc', 'src', false);
expect(dom.toString()).toContain('
src
');
});
+ });
+
+ describe('h', function(){
+
+ it('should render using function', function(){
+ var cbThis;
+ var cdValue;
+ dom.h('heading', 'content', function(value){
+ cbThis = this;
+ cbValue = value;
+ });
+ expect(cbThis).toEqual(dom);
+ expect(cbValue).toEqual('content');
+ });
+
+ it('should update heading numbers', function(){
+ dom.h('heading', function(){
+ this.html('
sub-heading
');
+ });
+ expect(dom.toString()).toContain('
heading
');
+ expect(dom.toString()).toContain('
sub-heading
');
+ });
});
+
});
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
element', function(){
+ var doc = new Doc('@description before ' +
+ '\n<>\n after');
+ doc.parse();
+ expect(doc.description).toContain('before
' +
+ '\n<>\nafter
');
+ });
+
+ it('should escape element', function(){
+ var doc = new Doc('@description before ' +
+ '\n<>\n after');
+ doc.parse();
+ expect(doc.description).toContain('before
' +
+ '\n<>\nafter
');
+ });
+
+ 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 ', function(){
+ var doc = new Doc(
+ '@id id\n' +
+ '@description scenario0' +
+ '@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 tags', function() {
expect(markdown('x
# Oneb
')).
- toMatch('One
foo ' +
'
' +
- '
bah
\n\n' +
+ '
bah
\n\n' +
'
foo
' +
'
');
@@ -243,18 +322,15 @@ describe('ngdoc', function(){
'{@link angular.directive.ng:foo ng:foo}');
doc.parse();
expect(doc.description).
- toBe('
foo angular.foo
\n\n' +
- '
da bar foo bar
\n\n' +
- '
dadangular.foo
\n\n' +
- '
ng:foo
');
- });
-
- it('should increment all headings by two', function() {
- var doc = new Doc('@description # foo\nabc\n## bar \n xyz');
- doc.parse();
+ toContain('foo
angular.foo');
+ expect(doc.description).
+ toContain('da
bar foo bar');
expect(doc.description).
- toBe('
foo
\n\n
abc
\n\n
bar
\n\n
xyz
');
+ toContain('dad
angular.foo');
+ expect(doc.description).
+ toContain('
ng:foo');
});
+
});
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('
heading
');
+ expect(doc.html()).not.toContain('Description');
+ });
+ });
+
+
describe('filter', function(){
it('should format', function(){
var doc = new Doc({
--
cgit v1.2.3