2016-05-28 17:17:21 +03:00
|
|
|
|
// #docregion
|
|
|
|
|
|
import { HTTP_PROVIDERS } from '@angular/http';
|
2015-12-15 08:02:20 +02:00
|
|
|
|
// #docregion routeparams
|
2016-05-11 16:28:58 +03:00
|
|
|
|
import { RouteParams } from '@angular/router-deprecated';
|
2016-05-28 17:17:21 +03:00
|
|
|
|
|
2015-12-15 08:02:20 +02:00
|
|
|
|
// #enddocregion routeparams
|
2016-05-03 14:06:32 +02:00
|
|
|
|
import { Observable } from 'rxjs/Rx';
|
2016-05-28 17:17:21 +03:00
|
|
|
|
|
2015-12-15 08:02:20 +02:00
|
|
|
|
import {
|
|
|
|
|
|
describe,
|
|
|
|
|
|
beforeEachProviders,
|
2016-04-27 11:28:22 -07:00
|
|
|
|
inject,
|
2015-12-15 08:02:20 +02:00
|
|
|
|
it,
|
2016-04-27 11:28:22 -07:00
|
|
|
|
expect
|
|
|
|
|
|
} from '@angular/core/testing';
|
2016-05-28 17:17:21 +03:00
|
|
|
|
import {
|
|
|
|
|
|
TestComponentBuilder,
|
|
|
|
|
|
ComponentFixture
|
|
|
|
|
|
} from '@angular/compiler/testing';
|
2016-04-27 11:28:22 -07:00
|
|
|
|
|
2016-05-28 17:17:21 +03:00
|
|
|
|
import { PhoneDetailComponent } from './phone-detail.component';
|
|
|
|
|
|
import { Phone, PhoneData } from '../core/phone/phone.service';
|
2015-12-15 08:02:20 +02:00
|
|
|
|
|
2016-06-08 01:06:25 +02:00
|
|
|
|
function xyzPhoneData(): PhoneData {
|
2015-12-15 08:02:20 +02:00
|
|
|
|
return {
|
|
|
|
|
|
name: 'phone xyz',
|
|
|
|
|
|
snippet: '',
|
|
|
|
|
|
images: ['image/url1.png', 'image/url2.png']
|
2016-06-08 01:06:25 +02:00
|
|
|
|
};
|
2015-12-15 08:02:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-05-28 17:17:21 +03:00
|
|
|
|
class MockPhone extends Phone {
|
2016-06-08 01:06:25 +02:00
|
|
|
|
get(id: string): Observable<PhoneData> {
|
2016-04-27 11:28:22 -07:00
|
|
|
|
return Observable.of(xyzPhoneData());
|
2015-12-15 08:02:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-05-28 17:17:21 +03:00
|
|
|
|
describe('PhoneDetailComponent', () => {
|
|
|
|
|
|
|
|
|
|
|
|
// #docregion routeparams
|
2015-12-15 08:02:20 +02:00
|
|
|
|
|
|
|
|
|
|
beforeEachProviders(() => [
|
2016-06-03 18:00:53 +02:00
|
|
|
|
{ provide: Phone, useClass: MockPhone },
|
|
|
|
|
|
{ provide: RouteParams, useValue: new RouteParams({phoneId: 'xyz'})},
|
2015-12-15 08:02:20 +02:00
|
|
|
|
HTTP_PROVIDERS
|
|
|
|
|
|
]);
|
|
|
|
|
|
// #enddocregion routeparams
|
|
|
|
|
|
|
2016-05-28 17:17:21 +03:00
|
|
|
|
it('should fetch phone detail',
|
|
|
|
|
|
inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
|
|
|
|
|
return tcb.createAsync(PhoneDetailComponent)
|
|
|
|
|
|
.then((fixture: ComponentFixture<PhoneDetailComponent>) => {
|
2015-12-15 08:02:20 +02:00
|
|
|
|
fixture.detectChanges();
|
|
|
|
|
|
let compiled = fixture.debugElement.nativeElement;
|
2016-02-04 18:30:36 +02:00
|
|
|
|
expect(compiled.querySelector('h1')).toHaveText(xyzPhoneData().name);
|
2015-12-15 08:02:20 +02:00
|
|
|
|
});
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
});
|