aboutsummaryrefslogtreecommitdiffstats
path: root/docs/spec/domSpec.js
diff options
context:
space:
mode:
authorVojta Jina2013-10-17 14:16:32 -0700
committerIgor Minar2013-10-18 15:35:41 -0700
commite8cc85f733a49ca53e8cda5a96bbaacc9a20ac7e (patch)
treef145db33b29ee9cce531492a8332adc537033b70 /docs/spec/domSpec.js
parentc22adbf160f32c1839fbb35382b7a8c6bcec2927 (diff)
downloadangular.js-e8cc85f733a49ca53e8cda5a96bbaacc9a20ac7e.tar.bz2
chore(docs): generate header ids for better linking
- generate ids for all headers - collect defined anchors - check broken links (even if the page exists, but the anchor/id does not)
Diffstat (limited to 'docs/spec/domSpec.js')
-rw-r--r--docs/spec/domSpec.js65
1 files changed, 62 insertions, 3 deletions
diff --git a/docs/spec/domSpec.js b/docs/spec/domSpec.js
index 7bc6a7f4..d10db9dc 100644
--- a/docs/spec/domSpec.js
+++ b/docs/spec/domSpec.js
@@ -1,4 +1,5 @@
var DOM = require('../src/dom.js').DOM;
+var normalizeHeaderToId = require('../src/dom.js').normalizeHeaderToId;
describe('dom', function() {
var dom;
@@ -7,6 +8,31 @@ describe('dom', function() {
dom = new DOM();
});
+ describe('html', function() {
+ it('should add ids to all h tags', function() {
+ dom.html('<h1>Some Header</h1>');
+ expect(dom.toString()).toContain('<h1 id="some-header">Some Header</h1>');
+ });
+
+ it('should collect <a name> anchors too', function() {
+ dom.html('<h2>Xxx <a name="foo"></a> and bar <a name="bar"></a>');
+ expect(dom.anchors).toContain('foo');
+ expect(dom.anchors).toContain('bar');
+ })
+ });
+
+ it('should collect h tag ids', function() {
+ dom.h('Page Title', function() {
+ dom.html('<h1>Second</h1>xxx <h2>Third</h2>');
+ dom.h('Another Header', function() {});
+ });
+
+ expect(dom.anchors).toContain('page-title');
+ expect(dom.anchors).toContain('second');
+ expect(dom.anchors).toContain('second_third');
+ expect(dom.anchors).toContain('another-header');
+ });
+
describe('h', function() {
it('should render using function', function() {
@@ -25,7 +51,7 @@ describe('dom', function() {
this.html('<h1>sub-heading</h1>');
});
expect(dom.toString()).toContain('<h1 id="heading">heading</h1>');
- expect(dom.toString()).toContain('<h2>sub-heading</h2>');
+ expect(dom.toString()).toContain('<h2 id="sub-heading">sub-heading</h2>');
});
it('should properly number nested headings', function() {
@@ -40,12 +66,45 @@ describe('dom', function() {
expect(dom.toString()).toContain('<h1 id="heading">heading</h1>');
expect(dom.toString()).toContain('<h2 id="heading2">heading2</h2>');
- expect(dom.toString()).toContain('<h3>heading3</h3>');
+ expect(dom.toString()).toContain('<h3 id="heading2_heading3">heading3</h3>');
expect(dom.toString()).toContain('<h1 id="other1">other1</h1>');
- expect(dom.toString()).toContain('<h2>other2</h2>');
+ expect(dom.toString()).toContain('<h2 id="other2">other2</h2>');
+ });
+
+
+ it('should add nested ids to all h tags', function() {
+ dom.h('Page Title', function() {
+ dom.h('Second', function() {
+ dom.html('some <h1>Third</h1>');
+ });
+ });
+
+ var resultingHtml = dom.toString();
+ expect(resultingHtml).toContain('<h1 id="page-title">Page Title</h1>');
+ expect(resultingHtml).toContain('<h2 id="second">Second</h2>');
+ expect(resultingHtml).toContain('<h3 id="second_third">Third</h3>');
+ });
+
+ });
+
+
+ describe('normalizeHeaderToId', function() {
+ it('should ignore content in the parenthesis', function() {
+ expect(normalizeHeaderToId('One (more)')).toBe('one');
+ });
+
+ it('should ignore html content', function() {
+ expect(normalizeHeaderToId('Section <a name="section"></a>')).toBe('section');
});
+ it('should ignore special characters', function() {
+ expect(normalizeHeaderToId('Section \'!?')).toBe('section');
+ });
+
+ it('should ignore html entities', function() {
+ expect(normalizeHeaderToId('angular&#39;s-jqlite')).toBe('angulars-jqlite');
+ });
});
});