Skip to content

Commit f9b4c9d

Browse files
Di PengIgorMinar
authored andcommitted
refactor(docs): run e2e tests with and without jquery
- e2e tests will run index.html (without jquery) and with index-jq.html(with jquery). - many small changes to make e2e tests work withough JQuery as we discover problems that were previously hidden by using real JQuery.
1 parent 83ac119 commit f9b4c9d

File tree

6 files changed

+45
-31
lines changed

6 files changed

+45
-31
lines changed

docs/src/gen-docs.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ var writes = callback.chain(function(){
2727
writer.copyDir('img', writes.waitFor());
2828
writer.copyDir('examples', writes.waitFor());
2929
writer.copyTpl('index.html', writes.waitFor());
30+
writer.copy('docs/src/templates/index.html', 'build/docs/index-jq.html', writes.waitFor(),
31+
'<-- jquery place holder -->', '<script src=\"jquery.min.js\"><\/script>');
3032
writer.copyTpl('offline.html', writes.waitFor());
3133
writer.output('app-cache.manifest',
3234
appCacheTemplate().replace(/%TIMESTAMP%/, (new Date()).toISOString()),
@@ -71,7 +73,6 @@ function appCacheTemplate() {
7173
"",
7274
"# cache all of these",
7375
"CACHE:",
74-
"jquery.min.js",
7576
"syntaxhighlighter/syntaxhighlighter-combined.js",
7677
"../angular.min.js",
7778
"docs-combined.js",

docs/src/ngdoc.js

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -546,22 +546,35 @@ Doc.prototype = {
546546
//////////////////////////////////////////////////////////
547547
function scenarios(docs){
548548
var specs = [];
549-
docs.forEach(function(doc){
550-
specs.push('describe("' + doc.section + '/' + doc.id + '", function(){');
551-
specs.push(' beforeEach(function(){');
552-
specs.push(' browser().navigateTo("index.html#!/' + doc.section + '/' + doc.id + '");');
553-
specs.push(' });');
554-
specs.push('');
555-
doc.scenarios.forEach(function(scenario){
556-
specs.push(indent(trim(scenario), 2));
549+
550+
specs.push('describe("angular without jquery", function() {');
551+
appendSpecs('index.html');
552+
specs.push('});');
553+
554+
specs.push('');
555+
specs.push('');
556+
557+
specs.push('describe("angular with jquery", function() {');
558+
appendSpecs('index-jq.html');
559+
specs.push('});');
560+
561+
return specs.join('\n');
562+
563+
function appendSpecs(htmlFile) {
564+
docs.forEach(function(doc){
565+
specs.push(' describe("' + doc.section + '/' + doc.id + '", function(){');
566+
specs.push(' beforeEach(function(){');
567+
specs.push(' browser().navigateTo("' + htmlFile + '#!/' + doc.section + '/' + doc.id + '");');
568+
specs.push(' });');
569+
specs.push(' ');
570+
doc.scenarios.forEach(function(scenario){
571+
specs.push(indent(trim(scenario), 4));
572+
specs.push('');
573+
});
574+
specs.push('});');
557575
specs.push('');
558576
});
559-
specs.push('});');
560-
specs.push('');
561-
if (doc.scenario) {
562-
}
563-
});
564-
return specs.join('\n');
577+
}
565578
}
566579

567580

docs/src/templates/doc_widgets.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@
2525
this.descend(true); //compile the example code
2626
element.hide();
2727

28-
var example = element.find('pre.doc-source').eq(0),
28+
//jQuery find() methods in this widget contain primitive selectors on purpose so that we can use
29+
//jqlite instead. jqlite's find() method currently supports onlt getElementsByTagName!
30+
var example = element.find('pre').eq(0), //doc-source
2931
exampleSrc = example.text(),
30-
scenario = element.find('pre.doc-scenario').eq(0);
32+
scenario = element.find('pre').eq(1); //doc-scenario
3133

3234
var code = indent(exampleSrc);
3335
var tabHtml =
@@ -47,15 +49,15 @@
4749
'</ul>';
4850
var tabs = angular.element(tabHtml);
4951

50-
tabs.find('li.doc-example-source > pre').text(HTML_TEMPLATE.replace('_HTML_SOURCE_', code.html));
52+
tabs.find('li').eq(1).find('pre').text(HTML_TEMPLATE.replace('_HTML_SOURCE_', code.html));
5153

5254
element.html('');
5355
element.append(tabs);
5456
element.show();
5557

5658
var script = (exampleSrc.match(/<script[^\>]*>([\s\S]*)<\/script>/) || [])[1] || '';
5759
try {
58-
eval(script);
60+
window.eval(script);
5961
} catch (e) {
6062
alert(e);
6163
}

docs/src/templates/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ <h2 ng:bind="partialTitle"></h2>
7575
<div id="footer">© 2010-2011 AngularJS</div>
7676
</div>
7777

78-
<script src="jquery.min.js"></script>
7978
<script src="syntaxhighlighter/syntaxhighlighter-combined.js"></script>
79+
<-- jquery place holder -->
8080
<script src="../angular.min.js" ng:autobind></script>
8181
<script src="docs-combined.js"></script>
8282
<script src="docs-keywords.js"></script>

docs/src/writer.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,19 @@ exports.makeDir = function (path, callback) {
5959
};
6060

6161
exports.copyTpl = function(filename, callback) {
62-
copy('docs/src/templates/' + filename, OUTPUT_DIR + filename, callback);
62+
exports.copy('docs/src/templates/' + filename, OUTPUT_DIR + filename, callback);
6363
};
6464

65-
function copy(from, to, callback) {
65+
exports.copy = function(from, to, callback, replacementKey, replacement) {
6666
//console.log('writing', to, '...');
6767
fs.readFile(from, function(err, content){
6868
if (err) return callback.error(err);
69+
if(replacementKey && replacement) {
70+
content = content.toString().replace(replacementKey, replacement);
71+
}
6972
fs.writeFile(to, content, callback);
7073
});
71-
}
74+
};
7275

7376
exports.copyDir = function copyDir(dir, callback) {
7477
exports.makeDir(OUTPUT_DIR + '/' + dir, callback.waitFor(function(){
@@ -81,7 +84,7 @@ exports.copyDir = function copyDir(dir, callback) {
8184
if (stat.isDirectory()) {
8285
copyDir(dir + '/' + file, callback.waitFor());
8386
} else {
84-
copy(path, OUTPUT_DIR + '/' + dir + '/' + file, callback.waitFor());
87+
exports.copy(path, OUTPUT_DIR + '/' + dir + '/' + file, callback.waitFor());
8588
}
8689
}));
8790
});

src/directives.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -539,19 +539,14 @@ angularDirective("ng:click", function(expression, element){
539539
<form ng:submit="list.push(text);text='';" ng:init="list=[]">
540540
Enter text and hit enter:
541541
<input type="text" name="text" value="hello"/>
542+
<input type="submit" id="submit" value="Submit" />
542543
</form>
543544
<pre>list={{list}}</pre>
544545
</doc:source>
545546
<doc:scenario>
546547
it('should check ng:submit', function(){
547548
expect(binding('list')).toBe('list=[]');
548-
element('.doc-example-live form input').click();
549-
this.addFutureAction('submit from', function($window, $document, done) {
550-
$window.angular.element(
551-
$document.elements('.doc-example-live form')).
552-
trigger('submit');
553-
done();
554-
});
549+
element('.doc-example-live #submit').click();
555550
expect(binding('list')).toBe('list=["hello"]');
556551
});
557552
</doc:scenario>

0 commit comments

Comments
 (0)