Skip to content
This repository has been archived by the owner on Jan 23, 2022. It is now read-only.

Commit

Permalink
feat(ngdocs): import unit tests from angularjs 1.2.7
Browse files Browse the repository at this point in the history
  • Loading branch information
m7r committed Jan 8, 2014
1 parent c7c340b commit fdeaddc
Show file tree
Hide file tree
Showing 4 changed files with 726 additions and 2 deletions.
16 changes: 15 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,24 @@
module.exports = function (grunt) {

grunt.loadNpmTasks('grunt-conventional-changelog');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-jasmine-node');

grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
changelog: { options: { dest: 'CHANGELOG.md' } }
changelog: { options: { dest: 'CHANGELOG.md' } },
jasmine_node: {
forceexit: true,
captureExceptions: true
},
watch: {
parser: {
files: ['src/*.js', 'spec/*Spec.js'],
tasks: ['jasmine_node']
}
}
});

grunt.registerTask('test', 'Run tests for parser code', ['jasmine_node']);

};
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
},
"devDependencies": {
"grunt": "~0.4.1",
"grunt-conventional-changelog": "~0.1.0"
"grunt-conventional-changelog": "~0.1.0",
"grunt-contrib-watch": "~0.5.0",
"grunt-jasmine-node": "~0.1.0",
"jasmine-node": "~1.12.0"
}
}
110 changes: 110 additions & 0 deletions spec/domSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
var DOM = require('../src/dom.js').DOM;
var normalizeHeaderToId = require('../src/dom.js').normalizeHeaderToId;

describe('dom', function() {
var dom;

beforeEach(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() {
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('<h1>sub-heading</h1>');
});
expect(dom.toString()).toContain('<h1 id="heading">heading</h1>');
expect(dom.toString()).toContain('<h2 id="sub-heading">sub-heading</h2>');
});

it('should properly number nested headings', function() {
dom.h('heading', function() {
dom.h('heading2', function() {
this.html('<h1>heading3</h1>');
});
});
dom.h('other1', function() {
this.html('<h1>other2</h1>');
});

expect(dom.toString()).toContain('<h1 id="heading">heading</h1>');
expect(dom.toString()).toContain('<h2 id="heading2">heading2</h2>');
expect(dom.toString()).toContain('<h3 id="heading2_heading3">heading3</h3>');

expect(dom.toString()).toContain('<h1 id="other1">other1</h1>');
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');
});
});

});
Loading

0 comments on commit fdeaddc

Please sign in to comment.