Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// #docregion
import {
beforeEachProviders,
addProviders,
inject
} from '@angular/core/testing';
import { CheckmarkPipe } from './checkmark.pipe';

describe('CheckmarkPipe', function() {

beforeEachProviders(() => [CheckmarkPipe]);
beforeEach(() => {
addProviders([CheckmarkPipe]);
});

it('should convert boolean values to unicode checkmark or cross',
inject([CheckmarkPipe], function(checkmarkPipe: CheckmarkPipe) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// #docregion
import {
describe,
addProviders,
beforeEach,
beforeEachProviders,
it,
inject
} from '@angular/core/testing';
import {
Expand All @@ -24,29 +22,26 @@ describe('Phone', function() {
];
let mockBackend: MockBackend;

beforeEachProviders(() => [
Phone,
MockBackend,
BaseRequestOptions,
{ provide: Http,
useFactory: (backend: MockBackend, options: BaseRequestOptions) =>
new Http(backend, options),
deps: [MockBackend, BaseRequestOptions]
}
]);
beforeEach(() => {
addProviders([
Phone,
MockBackend,
BaseRequestOptions,
{ provide: Http,
useFactory: (backend: MockBackend, options: BaseRequestOptions) => new Http(backend, options),
deps: [MockBackend, BaseRequestOptions]
}
]);
});

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

it('should fetch the phones data from `/phones/phones.json`',
(done: () => void) => {
it('should fetch the phones data from `/phones/phones.json`', (done: () => void) => {
mockBackend.connections.subscribe((conn: MockConnection) => {
conn.mockRespond(new Response(new ResponseOptions({
body: JSON.stringify(phonesData)
})));
conn.mockRespond(new Response(new ResponseOptions({ body: JSON.stringify(phonesData) })));
});
phone.query().subscribe(result => {
expect(result).toEqual(phonesData);
Expand All @@ -55,3 +50,4 @@ describe('Phone', function() {
});

});

Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ import { HTTP_PROVIDERS } from '@angular/http';
import { Observable } from 'rxjs/Rx';

import {
describe,
beforeEachProviders,
addProviders,
inject,
it,
expect
} from '@angular/core/testing';
import {
TestComponentBuilder,
Expand All @@ -33,19 +30,21 @@ class MockPhone extends Phone {

describe('PhoneDetailComponent', () => {

beforeEachProviders(() => [
{ provide: Phone, useClass: MockPhone },
{ provide: '$routeParams', useValue: {phoneId: 'xyz'}},
HTTP_PROVIDERS
]);
beforeEach(() => {
addProviders([
{ provide: Phone, useClass: MockPhone },
{ provide: '$routeParams', useValue: {phoneId: 'xyz'} },
HTTP_PROVIDERS
]);
});

it('should fetch phone detail',
inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb.createAsync(PhoneDetailComponent)
.then((fixture: ComponentFixture<PhoneDetailComponent>) => {
fixture.detectChanges();
let compiled = fixture.debugElement.nativeElement;
expect(compiled.querySelector('h1')).toHaveText(xyzPhoneData().name);
expect(compiled.querySelector('h1').textContent).toContain(xyzPhoneData().name);
});
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
import { HTTP_PROVIDERS } from '@angular/http';
import { Observable } from 'rxjs/Rx';
import {
describe,
beforeEachProviders,
addProviders,
inject,
it,
expect
} from '@angular/core/testing';
import {
TestComponentBuilder,
Expand All @@ -18,7 +15,6 @@ import { Phone, PhoneData } from '../core/phone/phone.service';

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

describe('PhoneList', () => {

beforeEachProviders(() => [
{ provide: Phone, useClass: MockPhone },
HTTP_PROVIDERS
]);
beforeEach(() => {
addProviders([
{ provide: Phone, useClass: MockPhone },
HTTP_PROVIDERS
]);
});

it('should create "phones" model with 2 phones fetched from xhr',
inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
// #docregion
import { Component } from '@angular/core';
import { RouteConfig, ROUTER_DIRECTIVES } from '@angular/router-deprecated';
import { PhoneListComponent } from './phone-list/phone-list.component';
import { PhoneDetailComponent } from './phone-detail/phone-detail.component';
import { ROUTER_DIRECTIVES } from '@angular/router';

@RouteConfig([
{path: '/phones', name: 'Phones', component: PhoneListComponent},
{path: '/phones/:phoneId', name: 'Phone', component: PhoneDetailComponent},
{path: '/', redirectTo: ['Phones']}
])
@Component({
selector: 'phonecat-app',
template: '<router-outlet></router-outlet>',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// #docregion
import { provideRouter, RouterConfig } from '@angular/router';

import { PhoneListComponent } from './phone-list/phone-list.component';
import { PhoneDetailComponent } from './phone-detail/phone-detail.component';

const routes: RouterConfig = [
{ path: '', redirectTo: 'phones', pathMatch: 'full' },
{ path: 'phones', component: PhoneListComponent },
{ path: 'phones/:phoneId', component: PhoneDetailComponent }
];

export const appRouterProviders = [
provideRouter(routes)
];
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import {
describe,
beforeEachProviders,
it,
addProviders,
inject,
expect
} from '@angular/core/testing';
import { CheckmarkPipe } from './checkmark.pipe';

describe('CheckmarkPipe', function() {

beforeEachProviders(() => [CheckmarkPipe]);
beforeEach(() => {
addProviders([CheckmarkPipe]);
});

it('should convert boolean values to unicode checkmark or cross',
inject([CheckmarkPipe], function(checkmarkPipe: CheckmarkPipe) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import {
describe,
addProviders,
beforeEach,
beforeEachProviders,
it,
inject
} from '@angular/core/testing';
import {
Expand All @@ -23,15 +21,17 @@ describe('Phone', function() {
];
let mockBackend: MockBackend;

beforeEachProviders(() => [
Phone,
MockBackend,
BaseRequestOptions,
{ provide: Http,
useFactory: (backend: MockBackend, options: BaseRequestOptions) => new Http(backend, options),
deps: [MockBackend, BaseRequestOptions]
}
]);
beforeEach(() => {
addProviders([
Phone,
MockBackend,
BaseRequestOptions,
{ provide: Http,
useFactory: (backend: MockBackend, options: BaseRequestOptions) => new Http(backend, options),
deps: [MockBackend, BaseRequestOptions]
}
]);
});

beforeEach(inject([MockBackend, Phone], (_mockBackend_: MockBackend, _phone_: Phone) => {
mockBackend = _mockBackend_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import {
import { bootstrap } from '@angular/platform-browser-dynamic';
import { FormsModule } from '@angular/forms';
import { HTTP_PROVIDERS } from '@angular/http';
import { ROUTER_PROVIDERS } from '@angular/router-deprecated';
import { Phone } from './core/phone/phone.service';
import { AppComponent } from './app.component';

import { appRouterProviders } from './app.routes';
// #enddocregion imports

// #docregion bootstrap
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
// #docregion
import { HTTP_PROVIDERS } from '@angular/http';
// #docregion routeparams
import { RouteParams } from '@angular/router-deprecated';
// #docregion activatedroute
import { ActivatedRoute } from '@angular/router';

// #enddocregion routeparams
// #enddocregion activatedroute
import { Observable } from 'rxjs/Rx';

import {
describe,
beforeEachProviders,
addProviders,
inject,
it,
expect
} from '@angular/core/testing';
import {
TestComponentBuilder,
Expand All @@ -35,24 +32,34 @@ class MockPhone extends Phone {
}
}

// #docregion activatedroute

class ActivatedRouteMock {
constructor(public snapshot: any) {}
}

// #enddocregion activatedroute

describe('PhoneDetailComponent', () => {

// #docregion routeparams
// #docregion activatedroute

beforeEachProviders(() => [
{ provide: Phone, useClass: MockPhone },
{ provide: RouteParams, useValue: new RouteParams({phoneId: 'xyz'})},
HTTP_PROVIDERS
]);
// #enddocregion routeparams
beforeEach(() => {
addProviders([
{ provide: Phone, useClass: MockPhone },
{ provide: ActivatedRoute, useValue: new ActivatedRouteMock({ params: { 'phoneId': 1 } }) },
HTTP_PROVIDERS
]);
});
// #enddocregion activatedroute

it('should fetch phone detail',
inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb.createAsync(PhoneDetailComponent)
.then((fixture: ComponentFixture<PhoneDetailComponent>) => {
fixture.detectChanges();
let compiled = fixture.debugElement.nativeElement;
expect(compiled.querySelector('h1')).toHaveText(xyzPhoneData().name);
expect(compiled.querySelector('h1').textContent).toContain(xyzPhoneData().name);
});
}));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// #docplaster
// #docregion
import { Component } from '@angular/core';
import { RouteParams } from '@angular/router-deprecated';
import { ActivatedRoute } from '@angular/router';

import { Phone, PhoneData } from '../core/phone/phone.service';
import { CheckmarkPipe } from '../core/checkmark/checkmark.pipe';

Expand All @@ -14,8 +15,8 @@ export class PhoneDetailComponent {
phone: PhoneData;
mainImageUrl: string;

constructor(routeParams: RouteParams, phone: Phone) {
phone.get(routeParams.get('phoneId')).subscribe(phone => {
constructor(activatedRoute: ActivatedRoute, phone: Phone) {
phone.get(activatedRoute.snapshot.params['phoneId']).subscribe(phone => {
this.phone = phone;
this.setImage(phone.images[0]);
});
Expand Down
Loading