Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 635a212

Browse files
jtrabandnaomiblack
authored andcommitted
Ward/Josh's testing pages and assoc images.
1 parent 3139348 commit 635a212

19 files changed

+938
-70
lines changed

public/docs/ts/latest/guide/_data.json

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,21 @@
2626

2727
"unit-testing-01": {
2828
"title": "Unit Testing Overview"
29+
},
30+
31+
"jasmine-testing-101": {
32+
"title": "Jasmine Testing 101"
33+
},
34+
35+
"application-under-test": {
36+
"title": "The Application Under Test"
37+
},
38+
39+
"first-app-tests": {
40+
"title": "First App Tests"
41+
},
42+
43+
"testing-an-angular-pipe": {
44+
"title": "Testing an Angular Pipe"
2945
}
30-
}
46+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
include ../../../../_includes/_util-fns
2+
3+
:markdown
4+
We’ll need an Angular application to test, one as simple as possible while having all the angular features we want to test.
5+
6+
We have such an app that you can download [here](./#). It’s a one-screen variation on the “Tour of Heroes” that should be familiar to you as a reader of this Developers Guide.
7+
8+
Our test app displays a list of heroes - all favorites of the user named “Bongo”. It looks like this:
9+
10+
figure.image-display
11+
img(src='/resources/images/devguide/application-under-test/bongos-heroes.png' style="width:400px;" alt="Bong's Heroes")
12+
13+
:markdown
14+
At the top is a master list of heroes; at the bottom the detail for the current hero. Click a hero in the list to change the current hero. Change the name in the textbox and that name updates everywhere. The *Update* button modifies the `Hero.name` in an arbitrary way and that change also propagates everywhere on screen. The *Delete* button deletes the hero from the list and a new hero becomes current. *Refresh* clears both the list and detail, then restores the original list of heroes.
15+
16+
You can see a short video of the app in action [here](./#)
17+
18+
This simple app illustrates a number of Angular features that we’d like to test.
19+
20+
- A simple service that presents the `username` (“Bongo”)
21+
- A dataservice that fetches and caches the list of heroes.
22+
- The dataservice depends in turn on another “backend” service that handles the interaction with a remote web api
23+
- A master `HeroesComponent` presents the list
24+
- The master communicates with a detail component `HeroDetailComponent` about the current hero both through an attribute and an event.
25+
- The detail’s template is nested within the master component’s template.
26+
- The `name` textbox illustrates two-way databinding
27+
- The update button demonstrates that a programmatic change to the databound model propagates to both component views
28+
- The delete button triggers an event that is caught by the parent component
29+
- [TBD: need to add a filter and a directive to this sample]
30+
- [TBD: need to shoehorn the router in somehow]
31+
32+
We’ll examine the implementation details as we evolve our tests.
33+
34+
## What’s Next?
35+
Now that we’re familiar with how the test app works, we’re ready to poke at it with our first application tests written in Jasmine.
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
var path = require('canonical-path');
2+
var fs = require("fs");
3+
var FRAGMENT_DIR = "./public/docs/_fragments";
4+
5+
/**
6+
* @dgService exampleInlineTagDef
7+
* @description
8+
* Process inline example tags (of the form {@example relativePath region -title='some title' -stylePattern='{some style pattern}' }),
9+
* replacing them with a jade makeExample mixin call.
10+
* @kind function
11+
* @param {Object} path The relative path to example
12+
* @param {Function} docs error message
13+
* @return {String} The jade makeExample mixin call
14+
*
15+
* @property {boolean} relativeLinks Whether we expect the links to be relative to the originating doc
16+
*/
17+
module.exports = function exampleInlineTagDef(getLinkInfo, createDocMessage, log) {
18+
return {
19+
name: 'example',
20+
description: 'Process inline example tags (of the form {@example some/uri Some Title}), replacing them with HTML anchors',
21+
handler: function(doc, tagName, tagDescription) {
22+
23+
var tagArgs = parseArgs(tagDescription);
24+
var unnamedArgs = tagArgs._;
25+
var relativePath = unnamedArgs[0];
26+
var region = unnamedArgs.length > 1 && unnamedArgs[1];
27+
var title = tagArgs.title;
28+
// TODO: not yet implemented here
29+
var stylePattern = tagArgs.stylePattern;
30+
31+
var dir = path.join("_api", path.dirname(relativePath));
32+
var extn = path.extname(relativePath);
33+
var baseNameNoExtn = path.basename(relativePath, extn);
34+
var fileName = region ? baseNameNoExtn + "-" + region + extn : baseNameNoExtn + extn;
35+
var fullFileName = path.join(FRAGMENT_DIR, dir, fileName);
36+
if ( !fs.existsSync(fileName)) {
37+
log.warn(createDocMessage('Invalid example (unable to locate fragment file: ' + quote(fullFileName), doc));
38+
}
39+
40+
var comma = ', '
41+
var res = [ "+makeExample(", quote(dir), comma, quote(fileName), comma, title ? quote(title) : 'null', ")" ].join('');
42+
return res;
43+
}
44+
45+
};
46+
};
47+
48+
function quote(str) {
49+
if (str == null || str.length === 0) return str;
50+
str = str.replace("'","'\'");
51+
return "'" + str + "'";
52+
}
53+
54+
55+
// processes an arg string in 'almost' the same fashion that the command processor does
56+
// and returns an args object in yargs format.
57+
function parseArgs(str) {
58+
// regex from npm string-argv
59+
//[^\s'"] Match if not a space ' or "
60+
61+
//+|['] or Match '
62+
//([^']*) Match anything that is not '
63+
//['] Close match if '
64+
65+
//+|["] or Match "
66+
//([^"]*) Match anything that is not "
67+
//["] Close match if "
68+
var rx = /[^\s'"]+|[']([^']*?)[']|["]([^"]*?)["]/gi;
69+
var value = str;
70+
var unnammedArgs = [];
71+
var args = { _: unnammedArgs };
72+
var match, key;
73+
do {
74+
//Each call to exec returns the next regex match as an array
75+
match = rx.exec(value);
76+
if (match !== null) {
77+
//Index 1 in the array is the captured group if it exists
78+
//Index 0 is the matched text, which we use if no captured group exists
79+
var arg = match[2] ? match[2] : (match[1]?match[1]:match[0]);
80+
if (key) {
81+
args[key] = arg;
82+
key = null;
83+
} else {
84+
if (arg.substr(arg.length-1) === '=') {
85+
key = arg.substr(0, arg.length-1);
86+
// remove leading '-' if it exists.
87+
if (key.substr(0,1)=='-') {
88+
key = key.substr(1);
89+
}
90+
} else {
91+
unnammedArgs.push(arg)
92+
key = null;
93+
}
94+
}
95+
}
96+
} while (match !== null);
97+
return args;
98+
}

0 commit comments

Comments
 (0)