// import { Component, OnInit, OnDestroy } from '@angular/core'; // import { Router, ActivatedRoute } from '@angular/router'; import { Observable } from 'rxjs/Rx'; // import { DebugElement } from '@angular/core'; import { FormsModule } from '@angular/forms'; import { TestBed, async, fakeAsync, ComponentFixture } from '@angular/core/testing'; import { RouterTestingModule } from '@angular/router/testing'; import { CustomerDetailComponent } from './customer-detail.component'; 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 { DepositInfoComponent } from './deposit-info/deposit-info.component'; import { AccountInfoComponent } from './account-info/account-info.component'; import { LineInfoComponent } from './line-info/line-info.component'; import { OrderHistoryComponent } from './order-history/order-history.component'; import { CustomerSearchStub } from '../../../services/customer.service.stub'; import { creditDetails, orderDetails, subscribersDetails, customerSearchResponse, pricingData, orderSearchResponse, cartData } from '../../../shared/mock-data'; import { IS_FINANCE_ORDER } from '../../../shared/service.constants'; import { TradeinService } from '../../../services/tradein.service'; import { LoggingService } from '../../../services/logging.service'; import { PopupComponent } from '../../../shared/popup/popup.component'; import { CheckoutService } from '../../../services/checkout.service'; import { Customer } from '../../../shared/modal/customer'; import { HttpClient, HttpHandler } from '@angular/common/http'; describe('Customer detail Component', () => { let customerDetailObject: CustomerDetailComponent; let fixture: ComponentFixture; let customerStub: CustomerSearchStub; beforeEach(async(() => { TestBed.configureTestingModule({ providers: [ SharedService, CartService, UserService, CustomerService, CheckoutService, LookupService, CatalogService, TradeinService, LoggingService, HttpClient, HttpHandler ], imports: [ FormsModule, RouterTestingModule ], declarations: [CustomerDetailComponent, DepositInfoComponent, AccountInfoComponent, LineInfoComponent, OrderHistoryComponent, PopupComponent] }); fixture = TestBed.createComponent(CustomerDetailComponent); customerDetailObject = fixture.componentInstance; TestBed.compileComponents(); TestBed.get(SharedService); TestBed.get(CartService); TestBed.get(UserService); customerStub = fixture.debugElement.injector.get(CustomerService); customerDetailObject.customer = customerSearchResponse; customerDetailObject.customerService.customer = customerSearchResponse; customerDetailObject.cartService.cart = cartData; })); // tests here it('should be created', () => { expect(customerDetailObject).toBeTruthy(); }); it('all methods are defined', () => { expect(customerDetailObject.getCreditLineDeatils).toBeDefined(); expect(customerDetailObject.getOrderHistory).toBeDefined(); expect(customerDetailObject.getSubscribers).toBeDefined(); }); it('should resolve get credit line test data', fakeAsync(() => { const spy = spyOn(customerStub, 'getCreditLine').and.returnValue( Observable.of(creditDetails) ); customerDetailObject.getCreditLineDeatils(); fixture.detectChanges(); expect(customerDetailObject.KarmaTestResult).toEqual(creditDetails); })); it('should resolve get order history test data', fakeAsync(() => { const spy = spyOn(customerStub, 'getOrderList').and.returnValue( Observable.of(orderDetails) ); customerDetailObject.getOrderHistory(12345); fixture.detectChanges(); expect(customerDetailObject.KarmaTestResult).toEqual(orderDetails); })); it('should resolve get subscribers test data', fakeAsync(() => { const spy = spyOn(customerStub, 'getSubscriberList').and.returnValue( Observable.of(subscribersDetails) ); customerDetailObject.getSubscribers(12345); fixture.detectChanges(); expect(customerDetailObject.KarmaTestResult).toEqual(subscribersDetails); })); it('should resolve get Preferred Price test data', fakeAsync(() => { const spy = spyOn(customerStub, 'getPreferredPrice').and.returnValue( Observable.of(pricingData) ); customerDetailObject.getPreferredPrice(123454564, 'CC'); fixture.detectChanges(); expect(customerDetailObject.KarmaTestResult).toEqual(pricingData); })); it('Associated orders are retrieved', fakeAsync(() => { customerDetailObject.customer.orders = orderDetails; spyOn(customerDetailObject, 'showAssociatedOrders'); spyOn(customerDetailObject, 'showBlindAssociatedOrders'); customerDetailObject.getAssociatedOrder(); expect(customerDetailObject.showAssociatedOrders).toHaveBeenCalled(); expect(customerDetailObject.showBlindAssociatedOrders).toHaveBeenCalled(); })); it('Associated orders are showed correctly', fakeAsync(() => { const cartStub = fixture.debugElement.injector.get(CartService); const spy = spyOn(cartStub, 'getAssociatedOrders').and.returnValue( Observable.of(cartData) ); customerDetailObject.showAssociatedOrders(12345); expect(customerDetailObject.cartService.getAssociatedOrders).toHaveBeenCalled(); })); it('Customer data is updated', fakeAsync(() => { let cart = customerDetailObject.cartService.cart; let cust = customerSearchResponse; customerDetailObject.updateCustomer(cust); expect(cart.customer).toEqual(cust); })); it('showBlindAssociated Orders are showed correctly', fakeAsync(() => { const cartStub = fixture.debugElement.injector.get(CartService); const spy = spyOn(cartStub, 'getSapOrderList').and.returnValue( Observable.of(cartData) ); customerDetailObject.showBlindAssociatedOrders(12345); expect(customerDetailObject.cartService.getSapOrderList).toHaveBeenCalled(); })); });