// import { Component, OnInit, OnDestroy } from '@angular/core'; // import { Router, ActivatedRoute } from '@angular/router'; import { SharedService } from '../../../shared/shared.service'; import { CartService } from '../../../services/cart.service'; import { CustomerService } from '../../../services/customer.service'; import { DebugElement } from '@angular/core'; import { FormsModule } from '@angular/forms'; import { Observable } from 'rxjs/Rx'; import CartUtils from '../../../shared/cart.utils'; import { TestBed, async, fakeAsync, ComponentFixture } from '@angular/core/testing'; import { RouterTestingModule } from '@angular/router/testing'; import { packagesData, customerSearchResponse, removeDeviceResponse, creditCheckResponse } from '../../../shared/spec.constants'; import { PopupComponent } from '../../../shared/popup/popup.component'; import { UserService } from '../../../services/user.service'; import { LookupService } from '../../../services/lookup.service'; import { CatalogService } from '../../../services/catalog.service'; import { Customer } from '../../../shared/modal/customer'; import { Cart } from '../../../shared/modal/cart'; import { CartServiceStub } from '../../../services/cart.service.stub'; import { EspotComponent } from '../../espot/espot.component'; import { MoreDetailsComponent } from '../../moredetails/more-details.component'; import { CompareComponent } from '../../compare/compare.component'; import { IDevice, IAccessory } from '../../../shared/modal/common'; import { packageMockData, packageData, userMockData, cartData } from '../../../shared/mock-data'; import { TradeinService } from '../../../services/tradein.service'; import { LoggingService } from '../../../services/logging.service'; import { CheckoutService } from '../../../services/checkout.service'; import { MarketingService } from '../../../services/marketing.service'; import { RelatedAccComponent } from './related-acc.component'; import { HttpClient, HttpHandler } from '@angular/common/http'; describe('Related Account component', () => { let relatedAccObject: RelatedAccComponent; let fixture: ComponentFixture; let dataStub: CartServiceStub; let accessoryItem: IAccessory; beforeEach(async(() => { TestBed.configureTestingModule({ providers: [ SharedService, CatalogService, LookupService, UserService, CartService, CustomerService, TradeinService, LoggingService, CheckoutService, MarketingService, HttpClient, HttpHandler ], imports: [ FormsModule, RouterTestingModule ], declarations: [RelatedAccComponent, PopupComponent, EspotComponent, CompareComponent, RelatedAccComponent, MoreDetailsComponent] }); fixture = TestBed.createComponent(RelatedAccComponent); relatedAccObject = fixture.componentInstance; relatedAccObject.cartService.cart = cartData; accessoryItem = { productId: 1234, productType: 'string', categoryId: 1234, categoryName: 'string', name: 'string', description: 'string', manufacturer: 'Apple', startDate: '04/10/2017', endDate: '08/10/2017', items: [{ itemId: 12345, name: 'string', description: 'string', accessorySKU: 'string', thumbNail: 'string', fullImage: 'string', colorName: 'string', colorImageUrl: 'string', isRefurbished: false, status: 'string', shipDateFrom: 'string', shipDateTo: 'string', suggestedPrice: 12345, instantDiscount: 12345, openBoxDiscount: 12345, promotionDiscount: 12345, mailInRebate: 12345, finalPrice: 12345, loan: [], lease: [], promotions: [] }], itemList: [], // local veriable for angualr2 itemIndex: 0, canCompare: false } relatedAccObject['cart'] = cartData; relatedAccObject.package = cartData.packages[0]; relatedAccObject.sharedService.userService['user'] = userMockData; dataStub = fixture.debugElement.injector.get(CartService); TestBed.compileComponents(); TestBed.get(SharedService); TestBed.get(CartService); TestBed.get(UserService); })); // tests here it('should be created', () => { expect(relatedAccObject).toBeTruthy(); }); it('All methods are defined', async(() => { expect(relatedAccObject.updateActivePackage).toBeDefined(); expect(relatedAccObject.getInventoryStatus).toBeDefined(); expect(relatedAccObject.buttonState).toBeDefined(); })); it('Inventory Status is retrieved correctly', async(() => { const status = relatedAccObject.getInventoryStatus('INS'); expect(status).toEqual('In Stock'); })); it('should Change the state of the button if there is no Accessories', fakeAsync(() => { const accessoriesItem = { itemId: 12345, name: 'string', description: 'string', accessorySKU: 'string', thumbNail: 'string', startDate: '04/10/2017', endDate: '08/10/2017', fullImage: 'string', colorName: 'string', colorImageUrl: 'string', isRefurbished: true, status: 'string', shipDateFrom: 'string', shipDateTo: 'string', suggestedPrice: 12345, instantDiscount: 12345, openBoxDiscount: 12345, promotionDiscount: 12345, mailInRebate: 12345, finalPrice: 12345, loan: [], lease: [] } expect(relatedAccObject.buttonState(accessoriesItem)).toEqual('ADD'); })); it('should Add Accessory', fakeAsync(() => { const spy = spyOn(dataStub, 'createAccessory').and.returnValue( Observable.of(cartData) ); relatedAccObject.addAccessory(accessoryItem); fixture.detectChanges(); expect(relatedAccObject.cart).toEqual(cartData); })); it('Should update active package', () => { relatedAccObject['cart'] = cartData; relatedAccObject.package = cartData.packages[0]; relatedAccObject.updateActivePackage(); expect(relatedAccObject.cart.activePackageId).toEqual(12345); }); });