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

Commit 899bae6

Browse files
Foxandxsswardbell
authored andcommitted
docs(style-guide): add testing harness
1 parent 10b0cde commit 899bae6

File tree

58 files changed

+565
-13
lines changed

Some content is hidden

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

58 files changed

+565
-13
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
*.js
2+
!systemjs.custom.js

public/docs/_examples/style-guide/ts/01-01/app/app.component.css

Whitespace-only changes.

public/docs/_examples/style-guide/ts/01-01/app/app.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import { HeroesComponent } from './heroes/heroes.component';
77
import { HeroService } from './heroes/shared/hero.service';
88

99
@Component({
10+
moduleId: module.id,
1011
selector: 'toh-app',
1112
template: `
1213
<toh-heroes></toh-heroes>
1314
`,
14-
styleUrls: ['app/app.component.css'],
15+
styleUrls: ['app.component.css'],
1516
directives: [HeroesComponent],
1617
providers: [HeroService]
1718
})
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Component } from '@angular/core';
2+
3+
import { HeroComponent } from './heroes/hero.component';
4+
import { UsersComponent } from './users/users.component';
5+
6+
@Component({
7+
selector: 'sg-app',
8+
template: `
9+
<toh-hero></toh-hero>
10+
<admin-users></admin-users>
11+
`,
12+
directives: [HeroComponent, UsersComponent]
13+
})
14+
export class AppComponent { }

public/docs/_examples/style-guide/ts/02-07/app/heroes/hero.component.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
// #docplaster
12
// #docregion
23
import { Component } from '@angular/core';
34

45
// #docregion example
56
@Component({
7+
// #enddocregion example
8+
template: '<div>hero component</div>',
9+
// #docregion example
610
selector: 'toh-hero'
711
})
812
export class HeroComponent {}

public/docs/_examples/style-guide/ts/02-07/app/users/users.component.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
// #docplaster
12
// #docregion
23
import { Component } from '@angular/core';
34

45
// #docregion example
56
@Component({
7+
// #enddocregion example
8+
template: '<div>users component</div>',
9+
// #docregion example
610
selector: 'admin-users'
711
})
812
export class UsersComponent {}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Component } from '@angular/core';
2+
3+
import { ValidateDirective } from './shared/validate.directive';
4+
5+
@Component({
6+
selector: 'sg-app',
7+
template: '<input type="text" tohValidate>',
8+
directives: [ValidateDirective]
9+
})
10+
export class AppComponent { }
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Component, OnInit } from '@angular/core';
2+
3+
import { ExceptionService } from './shared/exception.service';
4+
5+
@Component({
6+
selector: 'sg-app',
7+
template: '<div>The expected error is {{errorCode}}</div>',
8+
providers: [ExceptionService]
9+
})
10+
export class AppComponent implements OnInit {
11+
errorCode: number;
12+
13+
constructor(private exceptionService: ExceptionService) { }
14+
15+
ngOnInit() {
16+
this.errorCode = this.exceptionService.getException();
17+
}
18+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
// #docplaster
12
// #docregion
23
import { Injectable } from '@angular/core';
34

45
@Injectable()
56
// #docregion example
67
export class ExceptionService {
78
constructor() { }
9+
// #enddocregion example
10+
// testing harness
11+
getException() { return 42; }
12+
// #docregion example
813
}
914
// #enddocregion example
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Component } from '@angular/core';
2+
3+
import { HEROES_URL, VILLAIN_URL } from './shared/data.service';
4+
5+
@Component({
6+
selector: 'sg-app',
7+
template: `
8+
<div>Heroes url: {{heroesUrl}}</div>
9+
<div>Villains url: {{villainsUrl}}</div>
10+
`,
11+
})
12+
export class AppComponent {
13+
heroesUrl = HEROES_URL;
14+
villainsUrl = VILLAIN_URL;
15+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Component, OnInit } from '@angular/core';
2+
3+
import { HeroCollectorService } from './shared/hero-collector.service';
4+
import { Hero } from './shared/hero.model';
5+
6+
@Component({
7+
selector: 'sg-app',
8+
template: '<div>Our hero is {{hero.name}} and {{hero.power}}</div>',
9+
providers: [HeroCollectorService]
10+
})
11+
export class AppComponent implements OnInit {
12+
hero: Hero;
13+
14+
constructor(private heroCollectorService: HeroCollectorService) { }
15+
16+
ngOnInit() {
17+
this.hero = this.heroCollectorService.getHero();
18+
}
19+
}

public/docs/_examples/style-guide/ts/03-03/app/shared/hero-collector.service.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// #docplaster
12
// #docregion
23
// #docregion example
34
import { Injectable } from '@angular/core';
@@ -9,5 +10,16 @@ export class HeroCollectorService {
910
hero: Hero;
1011

1112
constructor() { }
13+
// #enddocregion example
14+
// testing harness
15+
getHero() {
16+
this.hero = {
17+
name: 'RubberMan',
18+
power: 'He is so elastic'
19+
};
20+
21+
return this.hero;
22+
}
23+
// #docregion example
1224
}
1325
// #enddocregion example
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { Component, OnInit } from '@angular/core';
2+
3+
import { ToastService } from './shared/toast/toast.service';
4+
5+
@Component({
6+
selector: 'sg-app',
7+
template: `
8+
<button (click)="show()">Show toast</button>
9+
<button (click)="hide()">Hide toast</button>
10+
`,
11+
providers: [ToastService]
12+
})
13+
export class AppComponent implements OnInit {
14+
constructor(private toastService: ToastService) { }
15+
16+
hide() {
17+
this.toastService.hide();
18+
}
19+
20+
show() {
21+
this.toastService.show();
22+
}
23+
24+
ngOnInit() {
25+
this.toastService.activate('Hello style-guide!');
26+
}
27+
}

public/docs/_examples/style-guide/ts/03-04/app/shared/toast/toast.service.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// #docplaster
12
// #docregion
23
// #docregion example
34
import { Injectable } from '@angular/core';
@@ -21,5 +22,11 @@ export class ToastService {
2122
private log() {
2223
console.log(this.message);
2324
}
25+
// #enddocregion example
26+
// testing harness
27+
activate(message: string) {
28+
this.message = message;
29+
}
30+
// #docregion example
2431
}
2532
// #enddocregion example

public/docs/_examples/style-guide/ts/03-05/app/+heroes/shared/hero.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class HeroService {
1919
) { }
2020

2121
getHero(id: number) {
22-
return this.http.get(`api/heroes/${id}`)
22+
return this.http.get(`app/heroes/${id}`)
2323
.map((res: Response) => res.json().data);
2424
}
2525

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<ul>
2+
<li *ngFor="let hero of heroes">
3+
{{hero.name}}
4+
</li>
5+
</ul>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Component, OnInit } from '@angular/core';
2+
3+
import { HeroService } from './+heroes/shared/hero.service';
4+
import { ExceptionService, SpinnerService, ToastService } from './shared';
5+
import { Hero } from './+heroes/shared/hero.model';
6+
7+
@Component({
8+
moduleId: module.id,
9+
selector: 'sg-app',
10+
templateUrl: 'app.component.html',
11+
providers: [HeroService, ExceptionService, SpinnerService, ToastService]
12+
})
13+
export class AppComponent implements OnInit {
14+
heroes: Hero[];
15+
16+
constructor(private heroService: HeroService) { }
17+
18+
ngOnInit() {
19+
this.heroService.getHeroes().subscribe(heroes => this.heroes = heroes);
20+
}
21+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<ul>
2+
<li *ngFor="let hero of heroes">
3+
{{hero.name}}
4+
</li>
5+
</ul>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Component, OnInit } from '@angular/core';
2+
3+
import { HeroService } from './+heroes/shared/hero.service';
4+
import { ExceptionService, SpinnerService, ToastService } from './shared';
5+
import { Hero } from './+heroes/shared/hero.model';
6+
7+
@Component({
8+
moduleId: module.id,
9+
selector: 'sg-app',
10+
templateUrl: 'app.component.html',
11+
providers: [HeroService, ExceptionService, SpinnerService, ToastService]
12+
})
13+
export class AppComponent implements OnInit {
14+
heroes: Hero[];
15+
16+
constructor(private heroService: HeroService) { }
17+
18+
ngOnInit() {
19+
this.heroService.getHeroes().subscribe(heroes => this.heroes = heroes);
20+
}
21+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div>This is heroes component</div>

public/docs/_examples/style-guide/ts/04-10/app/+heroes/heroes.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ import {
1515

1616
@Component({
1717
// #enddocregion example
18+
moduleId: module.id,
1819
providers: [EntityService, ExceptionService, SpinnerService, ToastService],
1920
directives: [FilterTextComponent],
2021
pipes: [InitCapsPipe],
2122
// #docregion example
2223
selector: 'toh-heroes',
23-
templateUrl: 'app/+heroes/heroes.component.html'
24+
templateUrl: 'heroes.component.html'
2425
})
2526
export class HeroesComponent implements OnInit {
2627
// #enddocregion example

public/docs/_examples/style-guide/ts/04-10/app/app.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { HeroesComponent } from './+heroes/index';
66
// #enddocregion example
77

88
@Component({
9-
selector: 'toh-app',
10-
template: '<div>app</div>',
9+
selector: 'sg-app',
10+
template: '<toh-heroes></toh-heroes>',
1111
directives: [HeroesComponent]
1212
})
1313
export class AppComponent { }
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Component } from '@angular/core';
2+
3+
import { HeroesComponent } from './heroes/heroes.component';
4+
5+
@Component({
6+
selector: 'sg-app',
7+
template: '<toh-heroes></toh-heroes>',
8+
directives: [HeroesComponent]
9+
})
10+
export class AppComponent { }

public/docs/_examples/style-guide/ts/04-14/app/heroes/heroes.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div>
33
<h2>My Heroes</h2>
44
<ul class="heroes">
5-
<li *ngFor="#hero of heroes">
5+
<li *ngFor="let hero of heroes">
66
<span class="badge">{{hero.id}}</span> {{hero.name}}
77
</li>
88
</ul>

public/docs/_examples/style-guide/ts/04-14/app/heroes/heroes.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Logger } from '../shared/logger.service';
77
// #enddocregion example
88

99
@Component({
10+
moduleId: module.id,
1011
selector: 'toh-heroes',
1112
templateUrl: 'heroes.component.html',
1213
styleUrls: ['heroes.component.css'],
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Component } from '@angular/core';
2+
3+
import { HeroButtonComponent } from './heroes/shared/hero-button/hero-button.component';
4+
5+
@Component({
6+
moduleId: module.id,
7+
selector: 'sg-app',
8+
templateUrl: 'app.component.html',
9+
directives: [HeroButtonComponent]
10+
})
11+
export class AppComponent { }
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
// #docplaster
12
// #docregion
23
import { Component } from '@angular/core';
34
// #docregion example
45
/* avoid */
56

67
@Component({
7-
selector: 'tohHeroButton'
8+
// #enddocregion example
9+
moduleId: module.id,
10+
// #docregion example
11+
selector: 'tohHeroButton',
12+
templateUrl: 'hero-button.component.html'
813
})
914
export class HeroButtonComponent {}
1015
// #enddocregion example
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<button class="hero-button">Hero button</button>
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
// #docplaster
12
// #docregion
23
import { Component } from '@angular/core';
34

45
// #docregion example
56
@Component({
6-
selector: 'toh-hero-button'
7+
// #enddocregion example
8+
moduleId: module.id,
9+
// #docregion example
10+
selector: 'toh-hero-button',
11+
templateUrl: 'hero-button.component.html'
712
})
813
export class HeroButtonComponent {}
914
// #enddocregion example
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Component } from '@angular/core';
2+
3+
import { HeroButtonComponent } from './heroes/shared/hero-button/hero-button.component';
4+
5+
@Component({
6+
moduleId: module.id,
7+
selector: 'sg-app',
8+
templateUrl: 'app.component.html',
9+
directives: [HeroButtonComponent]
10+
})
11+
export class AppComponent { }

0 commit comments

Comments
 (0)