import { Component, OnInit, OnDestroy, Pipe } from '@angular/core'; import { Router, ActivatedRoute } from '@angular/router'; import { DebugElement } from '@angular/core'; import { FormsModule, FormBuilder } from '@angular/forms'; import { Observable } from 'rxjs/Rx'; import { TestBed, async, fakeAsync, ComponentFixture } from '@angular/core/testing'; import { RouterTestingModule } from '@angular/router/testing'; import { SharedService } from '../../../shared/shared.service'; import { UserService } from '../../../services/user.service'; import { CartService } from '../../../services/cart.service'; import { CustomerService } from '../../../services/customer.service'; import { LookupService } from '../../../services/lookup.service'; import { CatalogService } from '../../../services/catalog.service'; import { TradeinService } from '../../../services/tradein.service'; import { LoggingService } from '../../../services/logging.service'; import { CheckoutService } from '../../../services/checkout.service'; import { cartData, customerSearchResponse, packageData, packagesData } from '../../../shared/mock-data'; import { HardGoodsComponent } from './hard-goods.component'; import { ORDER_STATUS } from '../../../shared/form.constants'; import { CartServiceStub } from '../../../services/cart.service.stub'; import { shippingData } from '../../../shared/spec.constants'; import { HttpClient, HttpHandler } from '@angular/common/http'; describe('Hard goods Component', () => { let hardGoodsObject: HardGoodsComponent; let fixture: ComponentFixture; let dataStub: CartServiceStub; beforeEach(async(() => { TestBed.configureTestingModule({ providers: [ SharedService, UserService, CartService, CustomerService, LookupService, CatalogService, TradeinService, LoggingService, CheckoutService, FormBuilder, HttpClient, HttpHandler ], imports: [ FormsModule, RouterTestingModule ], declarations: [HardGoodsComponent] }); fixture = TestBed.createComponent(HardGoodsComponent); TestBed.get(SharedService); TestBed.get(UserService); TestBed.get(CartService); hardGoodsObject = fixture.componentInstance; hardGoodsObject.cart = cartData hardGoodsObject.customer = customerSearchResponse; hardGoodsObject.realTimeInventory = { quoteESDFromDate: '02/02/2017', quoteESDToDate: '04/04/2017', status: 'P10', products: [] } dataStub = fixture.debugElement.injector.get(CartService); })); it('should be created', () => { expect(hardGoodsObject).toBeTruthy(); }); it('All methods are defined', async(() => { expect(hardGoodsObject.getShippingAddress).toBeDefined(); expect(hardGoodsObject.getStatusLabel).toBeDefined(); expect(hardGoodsObject.hasShipDate).toBeDefined(); expect(hardGoodsObject.getCustomerEmail).toBeDefined(); })); it('should return matching status', async(() => { hardGoodsObject.orderStatusItems = ORDER_STATUS; expect(hardGoodsObject.getStatusLabel('P')).toEqual('Work in Progress'); })); it('should resolve get shipping address test data', fakeAsync(() => { const spy = spyOn(dataStub, 'getCartShipping').and.returnValue( Observable.of(shippingData) ); hardGoodsObject.getShippingAddress(12345); fixture.detectChanges(); expect(hardGoodsObject.shippingInfo).toEqual(shippingData); })); it('should retrieve customer email', fakeAsync(() => { const email = hardGoodsObject.getCustomerEmail(); expect(email).toEqual('test@t-mobile.com'); })); });