import { Component, Input, ViewChild, OnInit, OnDestroy } from '@angular/core'; import { Router } from '@angular/router'; import * as Constants from '../../shared/constants' import { SharedService } from '../../shared/shared.service'; import { CartService } from '../../services/cart.service'; import { CustomerService } from '../../services/customer.service'; import { CheckoutService } from '../../services/checkout.service'; import { DebugElement } from '@angular/core'; import { FormsModule } from '@angular/forms'; import { Observable } from 'rxjs/Rx'; import { inject,tick,TestBed,getTestBed,async,fakeAsync,ComponentFixture } from '@angular/core/testing'; import { RouterTestingModule } from '@angular/router/testing'; import { UserService } from '../../services/user.service'; import { LookupService } from '../../services/lookup.service'; import { CatalogService } from '../../services/catalog.service'; import { cartData } from '../../shared/mock-data'; import { ProductsComponent } from './products.component'; import { TradeinService } from '../../services/tradein.service'; import { LoggingService } from '../../services/logging.service'; import CartUtils from '../cart.utils'; import { HttpClient, HttpHandler } from '@angular/common/http'; describe('Products component', () => { let obj: ProductsComponent; let fixture: ComponentFixture; beforeEach(async(() => { TestBed.configureTestingModule({ providers: [ SharedService, CartService, CustomerService, UserService, LookupService, CheckoutService, TradeinService, LoggingService, CatalogService, HttpClient, HttpHandler ], imports: [ FormsModule, RouterTestingModule ], declarations: [ProductsComponent] }); fixture = TestBed.createComponent(ProductsComponent); obj = fixture.componentInstance; obj['cart'] = cartData; TestBed.compileComponents(); })); it('should be created', () => { expect(obj).toBeTruthy(); }); it('All methods are defined', () => { expect(obj.getLineName).toBeDefined(); }); it('should return matching package', async(() => { obj['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: null, device: null, features: [], accessories: [], ppuAddress: null, e911Address: null, numberPorting: null, // added for local use deleteOption: true }], paymentInfo: null, shippingInfo: null, financeInfo: [], promotionInfo: [], // local use activePackageId: 12345, activeLineId: 12345, miniCartUpdated: true, checkedCoverage: false }; expect(obj.getPackages('voice')).toEqual(obj.cart.packages); })); it('fee name is retrieved correctly', async(() => { const feeName = obj.getFeeName(); expect(feeName).toEqual('Additional Line Fee'); })); it('fee type is retrieved correctly', async(() => { const feeType = obj.getFeeType(); expect(feeType).toEqual('Fees'); })); it('line name is retrieved correctly', async(() => { const pckge = obj.getLineName(obj.cart.packages[0]); expect(pckge['type']).toEqual('Voice'); })); it('deposit name is retrieved correctly', async(() => { const depositName = obj.getDepositName(); expect(depositName).toEqual('Deposit'); })); it('primary line details are retrieved correctly', async(() => { const item = { 'depositLineId': 1234 } spyOn(CartUtils, 'getPrimaryLine'); obj.getPrimaryLineDetails(item); expect(CartUtils.getPrimaryLine).toHaveBeenCalledWith(obj.cart, item); })); it('formatting phone number is working fine', async(() => { expect(obj.mobileNumber('1234567890')).toEqual('123-456-7890'); })); });