import { OTPAuthComponent } from './otp-auth.component'; // import { Component, OnInit, OnDestroy, Pipe } from '@angular/core'; // import { Router, ActivatedRoute } from '@angular/router'; // import { DebugElement } from '@angular/core'; import { FormsModule } 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 { CartService } from '../../../services/cart.service'; import { UserService } from '../../../services/user.service'; import { CustomerService } from '../../../services/customer.service'; import { CatalogService } from '../../../services/catalog.service'; import { cartData, customerSearchResponse, packagesData, CheckoutResponse } from '../../../shared/mock-data'; import { CheckoutService } from '../../../services/checkout.service'; import { LookupService } from '../../../services/lookup.service'; import { TradeinService } from '../../../services/tradein.service'; import { LoggingService } from '../../../services/logging.service'; import { CustomerSearchStub } from '../../../services/customer.service.stub'; import { PopupComponent } from '../../../shared/popup/popup.component'; import { HttpClient, HttpHandler } from '@angular/common/http'; describe('OTPAuth Component', () => { let otpAuthObject: OTPAuthComponent; let fixture: ComponentFixture; let dataStub: CustomerSearchStub; beforeEach((() => { TestBed.configureTestingModule({ providers: [ SharedService, UserService, CartService, CustomerService, LookupService, CatalogService, TradeinService, LoggingService, CheckoutService, HttpClient, HttpHandler ], imports: [ FormsModule, RouterTestingModule ], declarations: [OTPAuthComponent, PopupComponent] }); fixture = TestBed.createComponent(OTPAuthComponent); TestBed.get(SharedService); TestBed.get(UserService); TestBed.get(CartService); otpAuthObject = fixture.componentInstance; otpAuthObject.cart = cartData; dataStub = fixture.debugElement.injector.get(CustomerService); })); it('should be created', () => { expect(otpAuthObject).toBeTruthy(); }); it('All methods are defined', async(() => { expect(otpAuthObject.updateCartDetails).toBeDefined(); expect(otpAuthObject.findCustomerProfile).toBeDefined(); expect(otpAuthObject.validateOTPToken).toBeDefined(); })); it('resend OTP Token is working fine', async(() => { otpAuthObject.resendOTPToken(); expect(otpAuthObject.otpTokenSend).toEqual(false); })); it('should resolve customer profile test data', fakeAsync(() => { const customerStub = fixture.debugElement.injector.get(CustomerService); const spy = spyOn(customerStub, 'profileByBAN').and.returnValue( Observable.of(customerSearchResponse) ); otpAuthObject.findCustomerProfile(123456789); fixture.detectChanges(); expect(otpAuthObject.customerProfile).toEqual(customerSearchResponse); })); it('should resolve update Cart Details test data', fakeAsync(() => { const cartStub = fixture.debugElement.injector.get(CartService); const spy = spyOn(cartStub, 'updateCartDetails').and.returnValue( Observable.of(customerSearchResponse) ); otpAuthObject.updateCartDetails(); fixture.detectChanges(); expect(otpAuthObject.onTokenVerified.emit).toBeTruthy(); })); it('should resolve validateOTPToken test data', fakeAsync(() => { otpAuthObject.customer = customerSearchResponse; otpAuthObject.selectedOption = { type: 'sms' }; const customerStub = fixture.debugElement.injector.get(CustomerService); const spy = spyOn(customerStub, 'otpValidate').and.returnValue( Observable.of(customerSearchResponse) ); otpAuthObject.validateOTPToken(); fixture.detectChanges(); expect(otpAuthObject.otpTokenSend).toBeFalsy(); })); it('should resolve sendOTPToken test data', fakeAsync(() => { otpAuthObject.customer = customerSearchResponse; otpAuthObject.selectedOption = { type: 'sms' }; const customerStub = fixture.debugElement.injector.get(CustomerService); const spy = spyOn(customerStub, 'otpGenerate').and.returnValue( Observable.of(customerSearchResponse) ); otpAuthObject.sendOTPToken(); fixture.detectChanges(); expect(otpAuthObject.otpTokenSend).toBeFalsy(); })); });