Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit aef8aa9

Browse files
wardbellnaomiblack
authored andcommitted
docs(ngmodule): add chapter
1 parent fe35bc6 commit aef8aa9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+3355
-6
lines changed
Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
/// <reference path='../_protractor/e2e.d.ts' />
2+
'use strict';
3+
describe('NgModule', function () {
4+
5+
// helpers
6+
const gold = 'rgba(255, 215, 0, 1)';
7+
const powderblue = 'rgba(176, 224, 230, 1)';
8+
const lightgray = 'rgba(211, 211, 211, 1)';
9+
10+
function getCommonsSectionStruct() {
11+
const buttons = element.all(by.css('nav a'));
12+
13+
return {
14+
title: element.all(by.tagName('h1')).get(0),
15+
subtitle: element.all(by.css('app-title p i')).get(0),
16+
contactButton: buttons.get(0),
17+
crisisButton: buttons.get(1),
18+
heroesButton: buttons.get(2)
19+
};
20+
}
21+
22+
function getContactSectionStruct() {
23+
const buttons = element.all(by.css('app-contact form button'));
24+
25+
return {
26+
header: element.all(by.css('app-contact h2')).get(0),
27+
popupMessage: element.all(by.css('app-contact div')).get(0),
28+
contactNameHeader: element.all(by.css('app-contact form h3')).get(0),
29+
input: element.all(by.css('app-contact form input')).get(0),
30+
validationError: element.all(by.css('app-contact form .alert')).get(0),
31+
saveButton: buttons.get(0), // can't be tested
32+
nextContactButton: buttons.get(1),
33+
newContactButton: buttons.get(2)
34+
};
35+
}
36+
37+
function getCrisisSectionStruct() {
38+
return {
39+
title: element.all(by.css('ng-component h3')).get(0),
40+
items: element.all(by.css('ng-component a')),
41+
itemId: element.all(by.css('ng-component div')).get(0),
42+
listLink: element.all(by.css('ng-component a')).get(0),
43+
};
44+
}
45+
46+
function getHeroesSectionStruct() {
47+
return {
48+
header: element.all(by.css('ng-component h2')).get(0),
49+
title: element.all(by.css('ng-component h3')).get(0),
50+
items: element.all(by.css('ng-component a')),
51+
itemId: element.all(by.css('ng-component ng-component div div')).get(0),
52+
itemInput: element.all(by.css('ng-component ng-component input')).get(0),
53+
listLink: element.all(by.css('ng-component ng-component a')).get(0),
54+
};
55+
}
56+
57+
// tests
58+
function appTitleTests(color: string) {
59+
return function() {
60+
it('should have a gray header', function() {
61+
const commons = getCommonsSectionStruct();
62+
expect(commons.title.getCssValue('backgroundColor')).toBe(color);
63+
});
64+
65+
it('should welcome us', function () {
66+
const commons = getCommonsSectionStruct();
67+
expect(commons.subtitle.getText()).toBe('Welcome, Sam Spade');
68+
});
69+
};
70+
}
71+
72+
function contactTests(color: string) {
73+
return function() {
74+
it('shows the contact\'s owner', function() {
75+
const contacts = getContactSectionStruct();
76+
expect(contacts.header.getText()).toBe('Contact of Sam Spade');
77+
});
78+
79+
it('can cycle between contacts', function () {
80+
const contacts = getContactSectionStruct();
81+
const nextButton = contacts.nextContactButton;
82+
expect(contacts.contactNameHeader.getText()).toBe('Awesome Sam Spade');
83+
expect(contacts.contactNameHeader.getCssValue('backgroundColor')).toBe(color);
84+
nextButton.click().then(function () {
85+
expect(contacts.contactNameHeader.getText()).toBe('Awesome Nick Danger');
86+
return nextButton.click();
87+
}).then(function () {
88+
expect(contacts.contactNameHeader.getText()).toBe('Awesome Nancy Drew');
89+
});
90+
});
91+
92+
it('can change an existing contact', function () {
93+
const contacts = getContactSectionStruct();
94+
contacts.input.sendKeys('a');
95+
expect(contacts.input.getCssValue('backgroundColor')).toBe(color);
96+
expect(contacts.contactNameHeader.getText()).toBe('Awesome Sam Spadea');
97+
});
98+
99+
it('can create a new contact', function () {
100+
const contacts = getContactSectionStruct();
101+
const newContactButton = contacts.newContactButton;
102+
newContactButton.click().then(function () {
103+
expect(contacts.validationError.getText()).toBe('Name is required');
104+
contacts.input.sendKeys('John Doe');
105+
expect(contacts.contactNameHeader.getText()).toBe('Awesome John Doe');
106+
expect(contacts.validationError.getText()).toBe('');
107+
});
108+
});
109+
};
110+
}
111+
112+
describe('index.html', function () {
113+
beforeEach(function () {
114+
browser.get('');
115+
});
116+
117+
describe('app-title', appTitleTests(lightgray));
118+
119+
describe('contact', contactTests(lightgray));
120+
121+
describe('crisis center', function () {
122+
beforeEach(function () {
123+
getCommonsSectionStruct().crisisButton.click();
124+
});
125+
126+
it('shows a list of crisis', function () {
127+
const crisis = getCrisisSectionStruct();
128+
expect(crisis.title.getText()).toBe('Crisis List');
129+
expect(crisis.items.count()).toBe(4);
130+
expect(crisis.items.get(0).getText()).toBe('1 - Dragon Burning Cities');
131+
});
132+
133+
it('can navigate to one crisis details', function () {
134+
const crisis = getCrisisSectionStruct();
135+
crisis.items.get(0).click().then(function() {
136+
expect(crisis.itemId.getText()).toBe('Crisis id: 1');
137+
return crisis.listLink.click();
138+
}).then(function () {
139+
// We are back to the list
140+
expect(crisis.items.count()).toBe(4);
141+
});
142+
});
143+
});
144+
145+
describe('heroes', function () {
146+
beforeEach(function () {
147+
getCommonsSectionStruct().heroesButton.click();
148+
});
149+
150+
it('shows a list of heroes', function() {
151+
const heroes = getHeroesSectionStruct();
152+
expect(heroes.header.getText()).toBe('Heroes of Sam Spade');
153+
expect(heroes.title.getText()).toBe('Hero List');
154+
expect(heroes.items.count()).toBe(6);
155+
expect(heroes.items.get(0).getText()).toBe('11 - Mr. Nice');
156+
});
157+
158+
it('can navigate and edit one hero details', function () {
159+
const heroes = getHeroesSectionStruct();
160+
heroes.items.get(0).click().then(function () {
161+
expect(heroes.itemId.getText()).toBe('Id: 11');
162+
heroes.itemInput.sendKeys(' try');
163+
return heroes.listLink.click();
164+
}).then(function () {
165+
// We are back to the list
166+
expect(heroes.items.count()).toBe(6);
167+
expect(heroes.items.get(0).getText()).toBe('11 - Mr. Nice try');
168+
});
169+
});
170+
});
171+
});
172+
173+
describe('index.0.html', function() {
174+
beforeEach(function () {
175+
browser.get('index.0.html');
176+
});
177+
178+
it('has a title', function () {
179+
const title = element.all(by.tagName('h1')).get(0);
180+
expect(title.getText()).toBe('Minimal NgModule');
181+
});
182+
});
183+
184+
describe('index.1.html', function () {
185+
beforeEach(function () {
186+
browser.get('index.1.html');
187+
});
188+
189+
describe('app-title', appTitleTests(powderblue));
190+
});
191+
192+
describe('index.1b.html', function () {
193+
beforeEach(function () {
194+
browser.get('index.1b.html');
195+
});
196+
197+
describe('app-title', appTitleTests(powderblue));
198+
199+
describe('contact', contactTests(powderblue));
200+
});
201+
202+
describe('index.2.html', function () {
203+
beforeEach(function () {
204+
browser.get('index.2.html');
205+
});
206+
207+
describe('app-title', appTitleTests(gold));
208+
209+
describe('contact', contactTests(powderblue));
210+
});
211+
212+
describe('index.3.html', function () {
213+
beforeEach(function () {
214+
browser.get('index.3.html');
215+
});
216+
217+
describe('app-title', appTitleTests(gold));
218+
});
219+
220+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// #docregion
2+
import { Component } from '@angular/core';
3+
4+
@Component({
5+
selector: 'my-app',
6+
template: '<h1>{{title}}</h1>',
7+
})
8+
export class AppComponent {
9+
title = 'Minimal NgModule';
10+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// #docplaster
2+
// #docregion
3+
import { Component } from '@angular/core';
4+
5+
@Component({
6+
selector: 'my-app',
7+
// #enddocregion
8+
/*
9+
// #docregion template
10+
template: '<h1 highlight>{{title}}</h1>'
11+
// #enddocregion template
12+
*/
13+
// #docregion
14+
template: '<app-title [subtitle]="subtitle"></app-title>'
15+
})
16+
export class AppComponent {
17+
subtitle = '(v1)';
18+
}
19+
// #enddocregion
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// #docregion
2+
import { Component } from '@angular/core';
3+
4+
@Component({
5+
selector: 'my-app',
6+
// #docregion template
7+
template: `
8+
<app-title [subtitle]="subtitle"></app-title>
9+
<app-contact></app-contact>
10+
`
11+
// #enddocregion template
12+
})
13+
export class AppComponent {
14+
subtitle = '(v1)';
15+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Component } from '@angular/core';
2+
3+
@Component({
4+
selector: 'my-app',
5+
template: `
6+
<app-title [subtitle]="subtitle"></app-title>
7+
<app-contact></app-contact>
8+
`
9+
})
10+
export class AppComponent {
11+
subtitle = '(v2)';
12+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Component } from '@angular/core';
2+
3+
@Component({
4+
selector: 'my-app',
5+
// #docregion template
6+
template: `
7+
<app-title [subtitle]="subtitle"></app-title>
8+
<nav>
9+
<a routerLink="contact" routerLinkActive="active">Contact</a>
10+
<a routerLink="crisis" routerLinkActive="active">Crisis Center</a>
11+
<a routerLink="heroes" routerLinkActive="active">Heroes</a>
12+
</nav>
13+
<router-outlet></router-outlet>
14+
`
15+
// #enddocregion template
16+
})
17+
export class AppComponent {
18+
subtitle = '(v3)';
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// #docplaster
2+
// #docregion
3+
import { Component } from '@angular/core';
4+
5+
@Component({
6+
selector: 'my-app',
7+
template: `
8+
<app-title [subtitle]="subtitle"></app-title>
9+
<nav>
10+
<a routerLink="contact" routerLinkActive="active">Contact</a>
11+
<a routerLink="crisis" routerLinkActive="active">Crisis Center</a>
12+
<a routerLink="heroes" routerLinkActive="active">Heroes</a>
13+
</nav>
14+
<router-outlet></router-outlet>
15+
`
16+
})
17+
export class AppComponent {
18+
subtitle = '(Final)';
19+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// #docplaster
2+
// #docregion
3+
import { NgModule } from '@angular/core';
4+
import { BrowserModule } from '@angular/platform-browser';
5+
6+
import
7+
// #enddocregion
8+
{ AppComponent } from './app.component.0';
9+
/*
10+
// #docregion
11+
{ AppComponent } from './app.component';
12+
// #enddocregion
13+
*/
14+
// #docregion
15+
16+
@NgModule({
17+
// #docregion imports
18+
imports: [ BrowserModule ],
19+
// #enddocregion imports
20+
declarations: [ AppComponent ],
21+
bootstrap: [ AppComponent ]
22+
})
23+
export class AppModule { }
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// #docplaster
2+
// #docregion
3+
import { NgModule } from '@angular/core';
4+
import { BrowserModule } from '@angular/platform-browser';
5+
6+
import
7+
// #enddocregion
8+
{ AppComponent } from './app.component.1';
9+
/*
10+
// #docregion
11+
{ AppComponent } from './app.component';
12+
// #enddocregion
13+
*/
14+
// #docregion
15+
import { HighlightDirective } from './highlight.directive';
16+
import { TitleComponent } from './title.component';
17+
import { UserService } from './user.service';
18+
19+
/* Contact Related Imports */
20+
import { FormsModule } from '@angular/forms';
21+
22+
import { AwesomePipe } from './contact/awesome.pipe';
23+
import { ContactComponent } from './contact/contact.component.3';
24+
25+
// #docregion import-contact-directive
26+
import {
27+
HighlightDirective as ContactHighlightDirective
28+
} from './contact/highlight.directive';
29+
// #enddocregion import-contact-directive
30+
31+
@NgModule({
32+
// #docregion imports
33+
imports: [ BrowserModule, FormsModule ],
34+
// #enddocregion imports
35+
// #docregion declarations, directive, component
36+
declarations: [
37+
AppComponent,
38+
HighlightDirective,
39+
// #enddocregion directive
40+
TitleComponent,
41+
// #enddocregion component
42+
43+
AwesomePipe,
44+
ContactComponent,
45+
ContactHighlightDirective
46+
// #docregion declarations, directive, component
47+
],
48+
// #enddocregion declarations, directive, component
49+
// #docregion providers
50+
providers: [ UserService ],
51+
// #enddocregion providers
52+
bootstrap: [ AppComponent ]
53+
})
54+
export class AppModule { }

0 commit comments

Comments
 (0)