2020-07-31 15:43:18 -04:00
|
|
|
|
import { TestBed, waitForAsync } from '@angular/core/testing';
|
2017-02-22 13:13:21 -05:00
|
|
|
|
import { ActivatedRoute } from '@angular/router';
|
2018-06-20 07:01:23 -04:00
|
|
|
|
import { Observable, of } from 'rxjs';
|
2017-02-22 13:13:21 -05:00
|
|
|
|
|
|
|
|
|
import { PhoneDetailComponent } from './phone-detail.component';
|
|
|
|
|
import { Phone, PhoneData } from '../core/phone/phone.service';
|
|
|
|
|
import { CheckmarkPipe } from '../core/checkmark/checkmark.pipe';
|
|
|
|
|
|
|
|
|
|
function xyzPhoneData(): PhoneData {
|
2020-07-31 15:43:18 -04:00
|
|
|
|
return {name: 'phone xyz', snippet: '', images: ['image/url1.png', 'image/url2.png']};
|
2017-02-22 13:13:21 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class MockPhone {
|
|
|
|
|
get(id: string): Observable<PhoneData> {
|
2018-06-20 07:01:23 -04:00
|
|
|
|
return of(xyzPhoneData());
|
2017-02-22 13:13:21 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ActivatedRouteMock {
|
|
|
|
|
constructor(public snapshot: any) {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
describe('PhoneDetailComponent', () => {
|
|
|
|
|
|
2020-07-31 15:43:18 -04:00
|
|
|
|
beforeEach(waitForAsync(() => {
|
2017-02-22 13:13:21 -05:00
|
|
|
|
TestBed.configureTestingModule({
|
|
|
|
|
declarations: [ CheckmarkPipe, PhoneDetailComponent ],
|
|
|
|
|
providers: [
|
|
|
|
|
{ provide: Phone, useClass: MockPhone },
|
2020-07-30 06:03:14 -04:00
|
|
|
|
{ provide: ActivatedRoute, useValue: new ActivatedRouteMock({ params: { phoneId: 1 } }) }
|
2017-02-22 13:13:21 -05:00
|
|
|
|
]
|
|
|
|
|
})
|
|
|
|
|
.compileComponents();
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
it('should fetch phone detail', () => {
|
|
|
|
|
const fixture = TestBed.createComponent(PhoneDetailComponent);
|
|
|
|
|
fixture.detectChanges();
|
2020-07-30 06:03:19 -04:00
|
|
|
|
const compiled = fixture.debugElement.nativeElement;
|
2017-02-22 13:13:21 -05:00
|
|
|
|
expect(compiled.querySelector('h1').textContent).toContain(xyzPhoneData().name);
|
|
|
|
|
});
|
|
|
|
|
});
|