// 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, ComponentFixture } from '@angular/core/testing'; import * as Constants from '../../../../shared/constants'; import { RouterTestingModule } from '@angular/router/testing'; import { SharedService } from '../../../../shared/shared.service'; import { UserService } from '../../../../services/user.service'; import { CheckoutService } from '../../../../services/checkout.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 { LoggingService } from '../../../../services/logging.service'; import { TradeinService } from '../../../../services/tradein.service'; import { userMockData, TradeinResponseBySerialNumber, cartData, customerSearchResponse, serviceAgreementData } from '../../../../shared/mock-data'; import { TradeinServiceStub } from '../../../../services/tradein.service.stub'; import { OrderPaymentComponent } from './order-payment.component'; import { CustomerSearchStub } from '../../../../services/customer.service.stub'; import { HttpClient, HttpHandler } from '@angular/common/http'; describe('Order Payment Component', () => { let orderPaymentObject: OrderPaymentComponent; let fixture: ComponentFixture; let dataStub: CustomerSearchStub; beforeEach(async(() => { TestBed.configureTestingModule({ providers: [ SharedService, UserService, CheckoutService, CartService, CustomerService, LookupService, CatalogService, LoggingService, TradeinService, HttpClient, HttpHandler ], imports: [ FormsModule, RouterTestingModule ], declarations: [OrderPaymentComponent] }); fixture = TestBed.createComponent(OrderPaymentComponent); orderPaymentObject = fixture.componentInstance; TestBed.compileComponents(); TestBed.get(SharedService); TestBed.get(CartService); TestBed.get(UserService); dataStub = fixture.debugElement.injector.get(CustomerService); orderPaymentObject.lookupService.order = cartData; orderPaymentObject['cart'] = orderPaymentObject.lookupService.order; orderPaymentObject.storeId = 10553; orderPaymentObject['user'] = userMockData; })); // tests here it('should be created', () => { expect(orderPaymentObject).toBeTruthy(); }); it('All methods are defined', async(() => { expect(orderPaymentObject.sendAgreement).toBeDefined(); expect(orderPaymentObject.sendDisclosureAgreement).toBeDefined(); expect(orderPaymentObject.getStatus).toBeDefined(); })); it('should reolve sendDisclosureAgreement test data', async(() => { const spy = spyOn(dataStub, 'resendDiscloserEmail').and.returnValue( Observable.of(customerSearchResponse) ); orderPaymentObject.sendDisclosureAgreement(); fixture.detectChanges(); expect(orderPaymentObject.karmaTestResult).toEqual(customerSearchResponse); })); it('status is received correctly', async(() => { orderPaymentObject.cart = null; orderPaymentObject.cart = { financeInfo: { financeInfo: { eSignStatus: 'C' } } } const status = orderPaymentObject.getStatus(); expect(status).toEqual('Completed'); })); it('should resolve sendAgreement test data', async(() => { const spy = spyOn(dataStub, 'resendSAEmail').and.returnValue( Observable.of(serviceAgreementData) ); orderPaymentObject.sendAgreement(); fixture.detectChanges(); expect(orderPaymentObject.karmaTestResult).toEqual(serviceAgreementData); })); });