Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
feat(dgeni): Add test file for tag fixer unit test.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andres Dominguez authored and juliemr committed Oct 1, 2014
1 parent 1a0d26e commit 84bbbba
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 51 deletions.
2 changes: 2 additions & 0 deletions website/docgen/processors/add-toc.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ module.exports = function addToc() {
// Replace all the docs with the table of contents.
docs.length = 0;
docs.push({
id: 'x',
docType: 'js',
outputPath: 'toc.json',
template: 'toc',
toc: toc,
Expand Down
2 changes: 1 addition & 1 deletion website/docgen/processors/tag-fixer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var findName = function(doc) {
}

try {
var node = doc.codeNode.node;
var node = doc.codeNode;

// Is this a simple declaration? "var element = function() {".
if (node.declarations && node.declarations.length) {
Expand Down
27 changes: 27 additions & 0 deletions website/docgen/spec/element-array-finder-all.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"codeNode": {
"type": "ExpressionStatement",
"expression": {
"type": "AssignmentExpression",
"operator": "=",
"left": {
"type": "MemberExpression",
"object": {
"type": "MemberExpression",
"object": {
"type": "Identifier",
"name": "ElementArrayFinder"
},
"property": {
"type": "Identifier",
"name": "prototype"
}
},
"property": {
"type": "Identifier",
"name": "all"
}
}
}
}
}
14 changes: 14 additions & 0 deletions website/docgen/spec/element-array-finder.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"codeNode": {
"type": "VariableDeclaration",
"declarations": [
{
"type": "VariableDeclarator",
"id": {
"type": "Identifier",
"name": "ElementArrayFinder"
}
}
]
}
}
61 changes: 15 additions & 46 deletions website/docgen/spec/tag-fixer-spec.js
Original file line number Diff line number Diff line change
@@ -1,79 +1,48 @@
var tagFixerFn = require('../processors/tag-fixer');
var elementArrayFinder = require('./element-array-finder.json');
var elementAll = require('./element-array-finder-all.json');
var _ = require('lodash');

describe('tag fixer', function() {
var expressionDoc, declarationDoc, docs, tagFixer;
var classMethodStatement, constructorStatement, docs, tagFixer;

beforeEach(function() {
tagFixer = tagFixerFn();
});

beforeEach(function() {
expressionDoc = {
codeNode: {
node: {
expression: {
left: {
object: {
name: 'element'
},
property: {
name: 'all'
}
}
}
}
},
tags: {
description: 'element description'
}
};
constructorStatement = _.cloneDeep(elementArrayFinder);
classMethodStatement = _.cloneDeep(elementAll);

declarationDoc = {
codeNode: {
node: {
declarations: [
{
id: {
name: 'element'
}
}
]
}
},
tags: {
description: 'element description'
}
};

docs = [expressionDoc, declarationDoc];
docs = [constructorStatement, classMethodStatement];
});

it('should find name in code expression', function() {
it('should find name for method declaration', function() {
// When you process the docs.
tagFixer.$process(docs);

// Then ensure the name was parsed.
expect(expressionDoc.name).toBe('element.all');
expect(classMethodStatement.name).toBe('ElementArrayFinder.prototype.all');
});

it('should find name in code declaration', function() {
it('should find name for constructor declaration', function() {
// When you process the docs.
tagFixer.$process(docs);

// Then ensure the name was parsed.
expect(declarationDoc.name).toBe('element');
expect(constructorStatement.name).toBe('ElementArrayFinder');
});

it('should not override name', function() {
// Given that the doc has a @name.
expressionDoc.name = 'name1';
declarationDoc.name = 'name2';
classMethodStatement.name = 'name1';
constructorStatement.name = 'name2';

// When you process the docs.
tagFixer.$process(docs);

// Then ensure the name was not changed.
expect(expressionDoc.name).toBe('name1');
expect(declarationDoc.name).toBe('name2');
expect(classMethodStatement.name).toBe('name1');
expect(constructorStatement.name).toBe('name2');
});
});
8 changes: 4 additions & 4 deletions website/test/e2e/api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ describe('Api', function() {
expect(browser.getCurrentUrl()).toMatch(/api\?view=ElementArrayFinder/);
});

it('should view item in param link', function() {
// Given that you are viewing element.all.
apiPage.clickOnMenuItem('element.all(locator)');
it('should view item in param type link', function() {
// Given that you are viewing element.all.filter.
apiPage.clickOnMenuItem('filter');

// When you click on the ElementFinder link of the params table.
// When you click on the ElementFinder type link of the params table.
apiPage.clickOnParamType('ElementFinder');

// Then ensure the type is shown.
Expand Down

0 comments on commit 84bbbba

Please sign in to comment.