import { PayExtraComponent } from './payextra/pay-extra.component'; // 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 { SharedService } from '../../../shared/shared.service'; import { UserService } from '../../../services/user.service'; import { deletePackageResponse, deleteRatePlanResponse, packageData, cartDataResponse, packagesData, promotionData, applypromotionData, featureItemData } from '../../../shared/mock-data'; import { CustomerService } from '../../../services/customer.service'; import { LookupService } from '../../../services/lookup.service'; import { CatalogService } from '../../../services/catalog.service'; import { CartService } from '../../../services/cart.service'; import { CartServiceStub } from '../../../services/cart.service.stub'; import { IPackage } from '../../../shared/modal/common'; import { RoomyComponent } from './roomy.component'; import { RateplanComponent } from './rateplan/rateplan.component'; import { DeviceComponent } from './device/device.component'; import { FeatureComponent } from './feature/feature.component'; import { AccessoriesComponent } from '../../accessories/accessories.component'; import { AccessoryComponent } from './accessory/accessory.component'; import { FeeComponent } from './fee/fee.component'; import { PopupComponent } from '../../../shared/popup/popup.component'; import { ReturnComponent } from './return/return.component'; // import { TradeInComponent } from './device/tradein/tradein.component'; import { userMockData, cartResponse, customerSearchResponse, cartData } from '../../../shared/mock-data'; import { AdjustPriceComponent } from './adjust-price/adjust-price.component'; import { TradeinComponent } from './tradein/tradein.component'; import { TradeinService } from '../../../services/tradein.service'; import { LoggingService } from '../../../services/logging.service'; import CartUtils from '../../../shared/cart.utils'; import { MarketingService } from '../../../services/marketing.service'; import { CheckoutService } from '../../../services/checkout.service'; import { HttpClient, HttpHandler } from '@angular/common/http'; import { AdjustMonthlyComponent } from './adjust-montly/adjust-montly.component'; describe('Roomy Component', () => { let roomyObject: RoomyComponent; let fixture: ComponentFixture; let dataStub: CartServiceStub; let spyNavigate: any; beforeEach(async(() => { TestBed.configureTestingModule({ providers: [ SharedService, UserService, CartService, CustomerService, LookupService, CatalogService, CheckoutService, TradeinService, LoggingService, MarketingService, HttpClient, HttpHandler ], imports: [ FormsModule, RouterTestingModule ], declarations: [RateplanComponent, DeviceComponent, FeatureComponent, AccessoryComponent, FeeComponent, PopupComponent, ReturnComponent, RoomyComponent, AdjustPriceComponent, AdjustMonthlyComponent, TradeinComponent, PayExtraComponent, ] }); fixture = TestBed.createComponent(RoomyComponent); roomyObject = fixture.componentInstance; dataStub = fixture.debugElement.injector.get(CartService); TestBed.compileComponents(); TestBed.get(SharedService); TestBed.get(CartService); TestBed.get(UserService); roomyObject['user'] = userMockData roomyObject['cart'] = { orderId: 12345, prefix: 12345, status: 'string', refType: 'string', fullOrderId: 'string', sapOrderId: 12345, webOrderId: 12345, dealerCode: 'string', storeId: 'string', createdBy: 'string', createdByDate: 'string', submittedBy: 'string', submittedByDate: 'string', lastModifiedBy: 'string', lastModifiedByDate: 'string', // totals totalDueToday: 12345, totalDueMonthly: 12345, totalDevicesDueToday: 12345, totalAccessoriesDueToday: 12345, totalSSKDueToday: 12345, totalRateplansDueMonthly: 12345, totalFeaturesDueMonthly: 12345, totalFinanceDueToday: 12345, totalFinanceDueMonthly: 12345, totalShippingDueToday: 12345, totalDiscountDueToday: 12345, totalAutopayDiscountDueMonthly: 12345, totalHybridBandDiscountDueMonthly: 12345, totalDiscountDueMonthly: 12345, totalPromotionDueToday: 12345, totalPromotionDueMonthly: 12345, totalDepositDueToday: 12345, totalTaxDueToday: 12345, totalShippingTaxDueToday: 12345, isFinancedOrder: true, // customer customer: null, // products packages: [{ packageId: 1234, lineId: 1234, packageType: 'voice', plan: { orderItemId: 123, parentOrderItemId: 1234, productId: 1100, itemId: 10100, name: 'string', type: 'string', rateplanSOC: 'TMO', isNCFPlan: true, isTaxInclusivePlan: true, isPooledPlan: true, isVirtualDigit: true, isDuplicateDigit: true, isVirtualPlan: true, isLineLinkPlan: true, minimumLines: 1, maximumLines: 10, autoPayCreditAmount: 150, hybridBanCreditAmount: 250, monthlyPrice: 180 }, device: null, features: [], accessories: [], ppuAddress: null, e911Address: null, numberPorting: null, showPackage: false, // added for local use deleteOption: true }], paymentInfo: null, shippingInfo: null, financeInfo: [], promotionInfo: [], // local use activePackageId: 12345, activeLineId: 12345, miniCartUpdated: true, checkedCoverage: false }; roomyObject.userService.user = roomyObject['user']; roomyObject.cartService.cart = roomyObject['cart']; spyNavigate = spyOn(roomyObject.router, 'navigate'); })); // tests here it('should be created', () => { expect(roomyObject).toBeTruthy(); }); it('All methods are defined', async(() => { expect(roomyObject.checkoutNow).toBeDefined(); })); it('should resolve checkout test data', fakeAsync(() => { const spy = spyOn(dataStub, 'convertFullPrice').and.returnValue( Observable.of(cartDataResponse) ); roomyObject.checkoutNow(); fixture.detectChanges(); expect(roomyObject.karmaTestResult).toEqual(cartData); })); it('should resolve apply promotion test data', fakeAsync(() => { const spy = spyOn(dataStub, 'applyPromotion').and.returnValue( Observable.of(applypromotionData) ); roomyObject.applyPromotion(); fixture.detectChanges(); expect(roomyObject.karmaTestResult).toEqual(applypromotionData); })); it('should resolve delete promotion test data', fakeAsync(() => { const spy = spyOn(dataStub, 'deletePromotion').and.returnValue( Observable.of(applypromotionData) ); roomyObject.deletePromotion('offer50'); fixture.detectChanges(); expect(roomyObject.karmaTestResult).toEqual(applypromotionData); })); it('should resolve applied promo test data', fakeAsync(() => { const spy = spyOn(dataStub, 'getCartPromo').and.returnValue( Observable.of(promotionData) ); roomyObject.getAppliedPromos(roomyObject.cart.orderId) fixture.detectChanges(); expect(roomyObject.promotions).toEqual(promotionData); })); it('should return matching package', async(() => { expect(roomyObject.getPackages('voice')).toEqual(roomyObject.cart.packages); })); it('line name is retrieved correctly', async(() => { const pckge = roomyObject.getLineName(roomyObject.cart.packages[0]); expect(pckge['type']).toEqual('Voice'); })); it('should resolve doubleEIPEcl test data', fakeAsync(() => { const customerStub = fixture.debugElement.injector.get(CustomerService); const spy = spyOn(customerStub, 'doubleEIPEcl').and.returnValue( Observable.of(customerSearchResponse) ); roomyObject.doubleEIPEcl(); fixture.detectChanges(); expect(roomyObject.karmaTestResult).toEqual(customerSearchResponse); })); it('should resolve getcartSummary test data', fakeAsync(() => { const spy = spyOn(roomyObject.sharedService, 'showSpinner').and.returnValue( Observable.of(cartData) ); roomyObject.getCartSummary(); fixture.detectChanges(); expect(roomyObject.sharedService.showSpinner).toBeTruthy(); })); it('should resolve refreshCartSummary test data', fakeAsync(() => { const spy = spyOn(dataStub, 'calculate').and.returnValue( Observable.of(featureItemData) ); roomyObject.isFinanceOrder = true; roomyObject.isValidCart = true; roomyObject.storeId = 10553; roomyObject.refreshCartSummary(); fixture.detectChanges(); expect(roomyObject.karmaTestResult).toEqual(featureItemData); })); it('should resolve calculate Discounts test data', fakeAsync(() => { const dataStub = fixture.debugElement.injector.get(CartService); const spy = spyOn(dataStub, 'validateCart').and.returnValue( Observable.of(cartDataResponse) ); roomyObject.calculateDiscounts(); fixture.detectChanges(); expect(roomyObject.karmaTestResult).toEqual(cartDataResponse); })); it('should resolve sendQuoteToCustomer test data', fakeAsync(() => { roomyObject.user = userMockData; const cartStub = fixture.debugElement.injector.get(CartService); const spy = spyOn(roomyObject.marketingService, 'sendQuote').and.returnValue( Observable.of(cartData) ); roomyObject.sendQuoteToCustomer(); expect(roomyObject.sharedService.showSpinner).toBeTruthy(); })); });