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

Commit 4211628

Browse files
committed
docs(upgrade): update to new router
1 parent cece720 commit 4211628

File tree

15 files changed

+128
-136
lines changed

15 files changed

+128
-136
lines changed

public/docs/_examples/upgrade-phonecat-2-hybrid/ts/app/core/checkmark/checkmark.pipe.spec.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
// #docregion
22
import {
3-
describe,
4-
beforeEachProviders,
5-
it,
3+
addProviders,
64
inject,
7-
expect
85
} from '@angular/core/testing';
96
import { CheckmarkPipe } from './checkmark.pipe';
107

118
describe('CheckmarkPipe', function() {
129

13-
beforeEachProviders(() => [CheckmarkPipe]);
10+
beforeEach(() => {
11+
addProviders([CheckmarkPipe]);
12+
});
1413

1514
it('should convert boolean values to unicode checkmark or cross',
1615
inject([CheckmarkPipe], function(checkmarkPipe: CheckmarkPipe) {
Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
// #docregion
22
import {
3-
describe,
3+
addProviders,
44
beforeEach,
5-
beforeEachProviders,
6-
it,
75
inject
86
} from '@angular/core/testing';
97
import {
@@ -24,29 +22,26 @@ describe('Phone', function() {
2422
];
2523
let mockBackend: MockBackend;
2624

27-
beforeEachProviders(() => [
28-
Phone,
29-
MockBackend,
30-
BaseRequestOptions,
31-
{ provide: Http,
32-
useFactory: (backend: MockBackend, options: BaseRequestOptions) =>
33-
new Http(backend, options),
34-
deps: [MockBackend, BaseRequestOptions]
35-
}
36-
]);
25+
beforeEach(() => {
26+
addProviders([
27+
Phone,
28+
MockBackend,
29+
BaseRequestOptions,
30+
{ provide: Http,
31+
useFactory: (backend: MockBackend, options: BaseRequestOptions) => new Http(backend, options),
32+
deps: [MockBackend, BaseRequestOptions]
33+
}
34+
]);
35+
});
3736

38-
beforeEach(inject([MockBackend, Phone],
39-
(_mockBackend_: MockBackend, _phone_: Phone) => {
37+
beforeEach(inject([MockBackend, Phone], (_mockBackend_: MockBackend, _phone_: Phone) => {
4038
mockBackend = _mockBackend_;
4139
phone = _phone_;
4240
}));
4341

44-
it('should fetch the phones data from `/phones/phones.json`',
45-
(done: () => void) => {
42+
it('should fetch the phones data from `/phones/phones.json`', (done: () => void) => {
4643
mockBackend.connections.subscribe((conn: MockConnection) => {
47-
conn.mockRespond(new Response(new ResponseOptions({
48-
body: JSON.stringify(phonesData)
49-
})));
44+
conn.mockRespond(new Response(new ResponseOptions({body: JSON.stringify(phonesData)})));
5045
});
5146
phone.query().subscribe(result => {
5247
expect(result).toEqual(phonesData);
@@ -55,3 +50,4 @@ describe('Phone', function() {
5550
});
5651

5752
});
53+

public/docs/_examples/upgrade-phonecat-2-hybrid/ts/app/phone-detail/phone-detail.component.spec.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@ import { HTTP_PROVIDERS } from '@angular/http';
33
import { Observable } from 'rxjs/Rx';
44

55
import {
6-
describe,
7-
beforeEachProviders,
6+
addProviders,
87
inject,
9-
it,
10-
expect
118
} from '@angular/core/testing';
129
import {
1310
TestComponentBuilder,
@@ -33,19 +30,21 @@ class MockPhone extends Phone {
3330

3431
describe('PhoneDetailComponent', () => {
3532

36-
beforeEachProviders(() => [
37-
{ provide: Phone, useClass: MockPhone },
38-
{ provide: '$routeParams', useValue: {phoneId: 'xyz'}},
39-
HTTP_PROVIDERS
40-
]);
33+
beforeEach(() => {
34+
addProviders([
35+
{ provide: Phone, useClass: MockPhone },
36+
{ provide: '$routeParams', useValue: {phoneId: 'xyz'}},
37+
HTTP_PROVIDERS
38+
]);
39+
});
4140

4241
it('should fetch phone detail',
4342
inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
4443
return tcb.createAsync(PhoneDetailComponent)
4544
.then((fixture: ComponentFixture<PhoneDetailComponent>) => {
4645
fixture.detectChanges();
4746
let compiled = fixture.debugElement.nativeElement;
48-
expect(compiled.querySelector('h1')).toHaveText(xyzPhoneData().name);
47+
expect(compiled.querySelector('h1').textContent).toContain(xyzPhoneData().name);
4948
});
5049
}));
5150

public/docs/_examples/upgrade-phonecat-2-hybrid/ts/app/phone-list/phone-list.component.spec.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22
import { HTTP_PROVIDERS } from '@angular/http';
33
import { Observable } from 'rxjs/Rx';
44
import {
5-
describe,
6-
beforeEachProviders,
5+
addProviders,
76
inject,
8-
it,
9-
expect
107
} from '@angular/core/testing';
118
import {
129
TestComponentBuilder,
@@ -18,7 +15,6 @@ import { Phone, PhoneData } from '../core/phone/phone.service';
1815

1916
class MockPhone extends Phone {
2017
query(): Observable<PhoneData[]> {
21-
console.log('mocking here');
2218
return Observable.of(
2319
[
2420
{name: 'Nexus S', snippet: '', images: []},
@@ -30,10 +26,12 @@ class MockPhone extends Phone {
3026

3127
describe('PhoneList', () => {
3228

33-
beforeEachProviders(() => [
34-
{ provide: Phone, useClass: MockPhone },
35-
HTTP_PROVIDERS
36-
]);
29+
beforeEach(() => {
30+
addProviders([
31+
{ provide: Phone, useClass: MockPhone },
32+
HTTP_PROVIDERS
33+
])
34+
});
3735

3836
it('should create "phones" model with 2 phones fetched from xhr',
3937
inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {

public/docs/_examples/upgrade-phonecat-3-final/ts/app/app.component.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
// #docregion
22
import { Component } from '@angular/core';
3-
import { RouteConfig, ROUTER_DIRECTIVES } from '@angular/router-deprecated';
4-
import { PhoneListComponent } from './phone-list/phone-list.component';
5-
import { PhoneDetailComponent } from './phone-detail/phone-detail.component';
3+
import { ROUTER_DIRECTIVES } from '@angular/router';
64

7-
@RouteConfig([
8-
{path: '/phones', name: 'Phones', component: PhoneListComponent},
9-
{path: '/phones/:phoneId', name: 'Phone', component: PhoneDetailComponent},
10-
{path: '/', redirectTo: ['Phones']}
11-
])
125
@Component({
136
selector: 'phonecat-app',
147
template: '<router-outlet></router-outlet>',
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// #docregion
2+
import { provideRouter, RouterConfig } from '@angular/router';
3+
4+
import { PhoneListComponent } from './phone-list/phone-list.component';
5+
import { PhoneDetailComponent } from './phone-detail/phone-detail.component';
6+
7+
const routes: RouterConfig = [
8+
{ path: '', redirectTo: 'phones', pathMatch: 'full'},
9+
{ path: 'phones', component: PhoneListComponent },
10+
{ path: 'phones/:phoneId', component: PhoneDetailComponent }
11+
];
12+
13+
export const appRouterProviders = [
14+
provideRouter(routes)
15+
];

public/docs/_examples/upgrade-phonecat-3-final/ts/app/core/checkmark/checkmark.pipe.spec.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import {
2-
describe,
3-
beforeEachProviders,
4-
it,
2+
addProviders,
53
inject,
6-
expect
74
} from '@angular/core/testing';
85
import { CheckmarkPipe } from './checkmark.pipe';
96

107
describe('CheckmarkPipe', function() {
118

12-
beforeEachProviders(() => [CheckmarkPipe]);
9+
beforeEach(() => {
10+
addProviders([CheckmarkPipe]);
11+
});
1312

1413
it('should convert boolean values to unicode checkmark or cross',
1514
inject([CheckmarkPipe], function(checkmarkPipe: CheckmarkPipe) {

public/docs/_examples/upgrade-phonecat-3-final/ts/app/core/phone/phone.service.spec.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import {
2-
describe,
2+
addProviders,
33
beforeEach,
4-
beforeEachProviders,
5-
it,
64
inject
75
} from '@angular/core/testing';
86
import {
@@ -23,15 +21,17 @@ describe('Phone', function() {
2321
];
2422
let mockBackend: MockBackend;
2523

26-
beforeEachProviders(() => [
27-
Phone,
28-
MockBackend,
29-
BaseRequestOptions,
30-
{ provide: Http,
31-
useFactory: (backend: MockBackend, options: BaseRequestOptions) => new Http(backend, options),
32-
deps: [MockBackend, BaseRequestOptions]
33-
}
34-
]);
24+
beforeEach(() => {
25+
addProviders([
26+
Phone,
27+
MockBackend,
28+
BaseRequestOptions,
29+
{ provide: Http,
30+
useFactory: (backend: MockBackend, options: BaseRequestOptions) => new Http(backend, options),
31+
deps: [MockBackend, BaseRequestOptions]
32+
}
33+
]);
34+
});
3535

3636
beforeEach(inject([MockBackend, Phone], (_mockBackend_: MockBackend, _phone_: Phone) => {
3737
mockBackend = _mockBackend_;

public/docs/_examples/upgrade-phonecat-3-final/ts/app/main.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@ import {
77
} from '@angular/common';
88
import { bootstrap } from '@angular/platform-browser-dynamic';
99
import { HTTP_PROVIDERS } from '@angular/http';
10-
import { ROUTER_PROVIDERS } from '@angular/router-deprecated';
1110
import { Phone } from './core/phone/phone.service';
1211
import { AppComponent } from './app.component';
12+
13+
import { appRouterProviders } from './app.routes';
1314
// #enddocregion imports
1415

1516
// #docregion bootstrap
1617
bootstrap(AppComponent, [
1718
HTTP_PROVIDERS,
18-
ROUTER_PROVIDERS,
19+
appRouterProviders,
1920
{ provide: APP_BASE_HREF, useValue: '!' },
2021
{ provide: LocationStrategy, useClass: HashLocationStrategy },
2122
Phone

public/docs/_examples/upgrade-phonecat-3-final/ts/app/phone-detail/phone-detail.component.spec.ts

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
// #docregion
22
import { HTTP_PROVIDERS } from '@angular/http';
3-
// #docregion routeparams
4-
import { RouteParams } from '@angular/router-deprecated';
3+
// #docregion activatedroute
4+
import { ActivatedRoute } from '@angular/router';
55

6-
// #enddocregion routeparams
6+
// #enddocregion activatedroute
77
import { Observable } from 'rxjs/Rx';
88

99
import {
10-
describe,
11-
beforeEachProviders,
10+
addProviders,
1211
inject,
13-
it,
14-
expect
1512
} from '@angular/core/testing';
1613
import {
1714
TestComponentBuilder,
@@ -35,24 +32,34 @@ class MockPhone extends Phone {
3532
}
3633
}
3734

35+
// #docregion activatedroute
36+
37+
class ActivatedRouteMock {
38+
constructor(public snapshot: any) {}
39+
}
40+
41+
// #enddocregion activatedroute
42+
3843
describe('PhoneDetailComponent', () => {
3944

40-
// #docregion routeparams
45+
// #docregion activatedroute
4146

42-
beforeEachProviders(() => [
43-
{ provide: Phone, useClass: MockPhone },
44-
{ provide: RouteParams, useValue: new RouteParams({phoneId: 'xyz'})},
45-
HTTP_PROVIDERS
46-
]);
47-
// #enddocregion routeparams
47+
beforeEach(() => {
48+
addProviders([
49+
{ provide: Phone, useClass: MockPhone },
50+
{ provide: ActivatedRoute, useValue: new ActivatedRouteMock({ params: { 'phoneId': 1 } })},
51+
HTTP_PROVIDERS
52+
])
53+
});
54+
// #enddocregion activatedroute
4855

4956
it('should fetch phone detail',
5057
inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
5158
return tcb.createAsync(PhoneDetailComponent)
5259
.then((fixture: ComponentFixture<PhoneDetailComponent>) => {
5360
fixture.detectChanges();
5461
let compiled = fixture.debugElement.nativeElement;
55-
expect(compiled.querySelector('h1')).toHaveText(xyzPhoneData().name);
62+
expect(compiled.querySelector('h1').textContent).toContain(xyzPhoneData().name);
5663
});
5764
}));
5865

public/docs/_examples/upgrade-phonecat-3-final/ts/app/phone-detail/phone-detail.component.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// #docplaster
22
// #docregion
33
import { Component } from '@angular/core';
4-
import { RouteParams } from '@angular/router-deprecated';
4+
import { ActivatedRoute } from '@angular/router';
5+
56
import { Phone, PhoneData } from '../core/phone/phone.service';
67
import { CheckmarkPipe } from '../core/checkmark/checkmark.pipe';
78

@@ -14,8 +15,8 @@ export class PhoneDetailComponent {
1415
phone: PhoneData;
1516
mainImageUrl: string;
1617

17-
constructor(routeParams: RouteParams, phone: Phone) {
18-
phone.get(routeParams.get('phoneId')).subscribe(phone => {
18+
constructor(activatedRoute: ActivatedRoute, phone: Phone) {
19+
phone.get(activatedRoute.snapshot.params['phoneId']).subscribe(phone => {
1920
this.phone = phone;
2021
this.setImage(phone.images[0]);
2122
});

0 commit comments

Comments
 (0)