// 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 { creditCheckResponse, packagesData, cartData, customerSearchResponse, deleteRatePlanResponse } from '../../../shared/mock-data'; 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 { GSMRateplansComponent } from './gsm-rateplans.component'; import { IRateplan } from '../../../shared/modal/common'; import { packageMockData, userMockData, packagePlanData, packageData, sortByResponse } from '../../../shared/mock-data'; import { TradeinService } from '../../../services/tradein.service'; import { LoggingService } from '../../../services/logging.service'; import { CheckoutService } from '../../../services/checkout.service'; import { HttpClient, HttpHandler } from '@angular/common/http'; import { MoreDetailsService } from '../../../shared/more-details-modal.service'; describe('GSM Rateplan Component', () => { let gsmRatePlansObject: GSMRateplansComponent; let fixture: ComponentFixture; let dataStub: CartServiceStub; let cartUtils: CartUtils; let ratePlanItem: IRateplan; let catalogService: CatalogService; beforeEach(async(() => { TestBed.configureTestingModule({ providers: [ SharedService, CatalogService, LookupService, CheckoutService, UserService, CartService, CustomerService, TradeinService, LoggingService, HttpClient, HttpHandler, MoreDetailsService ], imports: [ FormsModule, RouterTestingModule ], declarations: [GSMRateplansComponent, PopupComponent, EspotComponent, CompareComponent, MoreDetailsComponent] }); fixture = TestBed.createComponent(GSMRateplansComponent); gsmRatePlansObject = fixture.componentInstance; gsmRatePlansObject.catalogService.gsmRateplans = [{ productId: 1234, productType: 'string', categoryId: 1234, categoryName: 'string', name: 'string', description: 'string', rateplanSOC: 'string', isNCFPlan: false, isTaxInclusivePlan: false, isVirtualDigit: false, isDuplicateDigit: false, isPooledPlan: false, contractType: 'string', contractLength: 1234, minimumLines: 1234, maximumLines: 1234, aalFee: 1234, autoPayCreditLines: 1234, autoPayCreditAmount: 1234, monthlyPrice: 1234, selectedLines: 1234 }, { productId: 1234, productType: 'string', categoryId: 1234, categoryName: 'string', name: 'string', description: 'string', rateplanSOC: 'string', isNCFPlan: false, isTaxInclusivePlan: false, isPooledPlan: false, isVirtualDigit: false, isDuplicateDigit: false, contractType: 'string', contractLength: 1234, minimumLines: 1234, maximumLines: 1234, aalFee: 1234, autoPayCreditLines: 1234, autoPayCreditAmount: 1234, monthlyPrice: 1234, selectedLines: 1234 }] gsmRatePlansObject.cartService.cart = cartData; gsmRatePlansObject['cart'] = cartData; // gsmRatePlansObject['package'] = packageMockData[0]; gsmRatePlansObject.customer = customerSearchResponse; gsmRatePlansObject.catalogService.gsmDevices = [{ productId: 1, productType: 'string', categoryId: 1, categoryName: 'string', name: 'string', manufacturer: 'Apple', description: 'string', descriptions: [], // soc: 'string', startDate: '04/12/2017', endDate: '04/12/2017', items: [], itemList: [], newPHPSOC: 'string', itemIndex: 1, canCompare: false } ]; gsmRatePlansObject['filters'] = [{ type: 'Individual', items: [{ name: 'Credit Individual', productIds: [1234], // for local isChecked: true, }] }, { type: 'features', items: [{ name: 'No Credit Individual', productIds: [123957], // for local isChecked: true, }] }]; ratePlanItem = { productId: 1234, productType: 'string', categoryId: 1234, categoryName: 'string', name: 'string', description: 'string', rateplanSOC: 'string', isNCFPlan: false, isTaxInclusivePlan: false, isPooledPlan: false, isVirtualDigit: false, isDuplicateDigit: false, contractType: 'string', contractLength: 1234, minimumLines: 1234, maximumLines: 1234, aalFee: 1234, autoPayCreditLines: 1234, autoPayCreditAmount: 1234, monthlyPrice: 1234, selectedLines: 1234, } gsmRatePlansObject.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(gsmRatePlansObject).toBeTruthy(); }); it('All methods are defined', async(() => { expect(gsmRatePlansObject.applyCustomSorting).toBeDefined(); expect(gsmRatePlansObject.setPage).toBeDefined(); expect(gsmRatePlansObject.expandDetails).toBeDefined(); })); it('should Change the state of the button if there is no Rateplan', fakeAsync(() => { gsmRatePlansObject.package = packagesData[0]; expect(gsmRatePlansObject.buttonState('string123')).toEqual('ADD'); })); it('should Change the state of the button for selected Rate Plan', fakeAsync(() => { gsmRatePlansObject.package = packagesData[1]; expect(gsmRatePlansObject.buttonState('string')).toEqual('REM'); })); it('should Change the state of the button for other than selected Rate Plan', fakeAsync(() => { gsmRatePlansObject.package = packagesData[1]; expect(gsmRatePlansObject.buttonState('string123')).toEqual('UPD'); })); it('should expand Details if it is not opened yet', fakeAsync(() => { gsmRatePlansObject.expandedProductId = null; gsmRatePlansObject.expandDetails(12345); expect(gsmRatePlansObject.expandedProductId).toEqual(12345); })); it('should expand Details if it is opened', fakeAsync(() => { gsmRatePlansObject.expandedProductId = 12345; gsmRatePlansObject.expandDetails(12345); expect(gsmRatePlansObject.expandedProductId).toEqual(null); })); it('should resolve add rateplan test data', fakeAsync(() => { const spy = spyOn(dataStub, 'createRateplan').and.returnValue( Observable.of(deleteRatePlanResponse) ); gsmRatePlansObject.package = packagesData[1]; gsmRatePlansObject.addRateplan(ratePlanItem); fixture.detectChanges(); expect(gsmRatePlansObject.KarmaTestResult).toEqual(deleteRatePlanResponse); })); it('should resolve delete rateplan test data', fakeAsync(() => { const spy = spyOn(dataStub, 'deleteRateplan').and.returnValue( Observable.of(deleteRatePlanResponse) ); gsmRatePlansObject.package = packagesData[1]; gsmRatePlansObject.removeRateplan(ratePlanItem); fixture.detectChanges(); expect(gsmRatePlansObject.KarmaTestResult).toEqual(deleteRatePlanResponse); })); it('should resolve update rateplan test data', fakeAsync(() => { const spy = spyOn(dataStub, 'updateRateplan').and.returnValue( Observable.of(cartData) ); gsmRatePlansObject.package = packagesData[1]; gsmRatePlansObject.updateRateplan(ratePlanItem); fixture.detectChanges(); expect(gsmRatePlansObject.KarmaTestResult).toEqual(cartData); })); it('Clearing all filters functionality is working fine', async(() => { gsmRatePlansObject.clearAllFilters(); expect(gsmRatePlansObject.searchText).toEqual(''); expect(gsmRatePlansObject.rangeLineCount).toEqual(1); })); it('Checking if atleast one feature is checked for comparison ', async(() => { expect(gsmRatePlansObject.atleastOneChecked()).toBeTruthy(); })); it('Should do custom sorting', () => { let simOnlyDevice = { productId: 1234, productType: 'string', categoryId: 1234, categoryName: 'string', name: 'string', description: 'string', rateplanSOC: 'string', isNCFPlan: false, isTaxInclusivePlan: false, isDuplicateDigit: false, isPooledPlan: false, isVirtualDigit: false, contractType: 'string', contractLength: 1234, minimumLines: 1234, maximumLines: 1234, aalFee: 1234, autoPayCreditLines: 1234, autoPayCreditAmount: 1234, monthlyPrice: 1234, // added for local use selectedLines: 1234 }; let smartPhoneDevice = { productId: 1234, productType: 'string', categoryId: 1234, categoryName: 'string', name: 'string', description: 'string', rateplanSOC: 'string', isNCFPlan: false, isTaxInclusivePlan: false, isPooledPlan: false, contractType: 'string', contractLength: 1234, minimumLines: 1234, maximumLines: 1234, isVirtualDigit: false, isDuplicateDigit: false, aalFee: 1234, autoPayCreditLines: 1234, autoPayCreditAmount: 1234, monthlyPrice: 1234, // added for local use selectedLines: 1234 }; gsmRatePlansObject['rateplans'] = [simOnlyDevice, smartPhoneDevice]; gsmRatePlansObject.applyCustomSorting(); expect(gsmRatePlansObject.allItems[0].productId).toEqual(simOnlyDevice.productId); }); it('total number of pages are set correctly', fakeAsync(() => { gsmRatePlansObject.pager = { 'totalPages': 10, 'startIndex': 1, 'endIndex': 2 } gsmRatePlansObject.allItems = ['orderItems', 'orderStatus'] gsmRatePlansObject.setPage(2); expect(gsmRatePlansObject.pagedItems.length).toEqual(0); })); it('setting minimum and maximum lines is working as expected', fakeAsync(() => { let ratePlanItem = { productId: 1234, productType: 'string', categoryId: 1234, categoryName: 'string', name: 'string', description: 'string', rateplanSOC: 'string', isNCFPlan: false, isTaxInclusivePlan: false, isPooledPlan: true, isVirtualDigit: false, isDuplicateDigit: false, contractType: 'string', contractLength: 1234, minimumLines: 1, maximumLines: 2, aalFee: 1234, autoPayCreditLines: 1234, autoPayCreditAmount: 1234, monthlyPrice: 1234, selectedLines: 1234, } const minmaxlinesArray = gsmRatePlansObject.minMaxLineNumbers(ratePlanItem); expect(minmaxlinesArray.length).toEqual(2); })); it('Monthly price calculation is workind fine', fakeAsync(() => { gsmRatePlansObject.rangeLineCount = 2; let ratePlanItem = { productId: 1234, productType: 'string', categoryId: 1234, categoryName: 'string', name: 'string', description: 'string', rateplanSOC: 'string', isNCFPlan: false, isTaxInclusivePlan: false, isPooledPlan: false, isVirtualDigit: false, isDuplicateDigit: false, contractType: 'string', contractLength: 1234, minimumLines: 3, maximumLines: 4, aalFee: 1234, autoPayCreditLines: 10, autoPayCreditAmount: 25, monthlyPrice: 225, selectedLines: 3, } const monthlyPrice = gsmRatePlansObject.calculateMonthlyPrice(ratePlanItem); expect(monthlyPrice).toEqual(ratePlanItem.monthlyPrice); })); it('Discount price calculation is workind fine', fakeAsync(() => { gsmRatePlansObject.rangeLineCount = 2; const ratePlan = { productId: 1234, productType: 'string', categoryId: 1234, categoryName: 'string', name: 'string', description: 'string', rateplanSOC: 'string', isNCFPlan: false, isTaxInclusivePlan: false, isPooledPlan: false, isVirtualDigit: false, isDuplicateDigit: false, contractType: 'string', contractLength: 1234, minimumLines: 4, maximumLines: 6, aalFee: 10, autoPayCreditLines: 2, autoPayCreditAmount: 5, monthlyPrice: 225, selectedLines: 5, } const dicountedMonthlyPrice = gsmRatePlansObject.discountedMonthlyPrice(ratePlan); expect(dicountedMonthlyPrice).toEqual(225); })); it('setting maximum line limit for a rate plan is done correctly', fakeAsync(() => { gsmRatePlansObject['rateplans'] = [{ productId: 1234, productType: 'string', categoryId: 1234, categoryName: 'string', name: 'string', description: 'string', rateplanSOC: 'string', isNCFPlan: false, isTaxInclusivePlan: false, isPooledPlan: false, isVirtualDigit: false, isDuplicateDigit: false, contractType: 'string', contractLength: 1234, minimumLines: 4, maximumLines: 6, aalFee: 10, autoPayCreditLines: 2, autoPayCreditAmount: 5, monthlyPrice: 225, selectedLines: 5, }, ] expect(gsmRatePlansObject.maximumLineLimit).toEqual(6); })); it('should resolve get Rateplans By ZipCode test data', fakeAsync(() => { const catalogDataStub = fixture.debugElement.injector.get(CatalogService); const spy = spyOn(catalogDataStub, 'getRateplansByZipCode').and.returnValue( Observable.of(sortByResponse) ); gsmRatePlansObject.filterByCustomer(); fixture.detectChanges(); expect(gsmRatePlansObject.KarmaTestResult).toEqual(sortByResponse); })); it('reset rateplans Filters', () => { gsmRatePlansObject.individualPlanFilters = []; const previousLength = gsmRatePlansObject.individualPlanFilters.length; gsmRatePlansObject.resetRateplanFilters(); expect(gsmRatePlansObject.individualPlanFilters.length).toBeGreaterThan(previousLength); }); it('should resolve Sync cart test data', fakeAsync(() => { const spy = spyOn(gsmRatePlansObject.sharedService, 'showSpinner').and.returnValue( Observable.of(cartData) ); gsmRatePlansObject.syncCartUpdates(20045); fixture.detectChanges(); expect(gsmRatePlansObject.cart).toEqual(cartData); expect(gsmRatePlansObject.sharedService.showSpinner).toBeTruthy(); })); it('Should update active package', () => { gsmRatePlansObject.customer = customerSearchResponse; spyOn(gsmRatePlansObject.sharedService, 'showErrorMessage'); spyOn(gsmRatePlansObject, 'applyCustomSorting'); gsmRatePlansObject.updateActivePackage(); expect(gsmRatePlansObject.sharedService.showErrorMessage).toHaveBeenCalledWith('_ERR_MAX_LINE_LIMIT_EXCEEDED_ACCOUNT', false); expect(gsmRatePlansObject.applyCustomSorting).toHaveBeenCalled(); }); it('should resolve addItemPreprocess test data', fakeAsync(() => { const spy = spyOn(dataStub, 'createCartDetails').and.returnValue( Observable.of(cartData) ); gsmRatePlansObject.addItemPreprocess(ratePlanItem); fixture.detectChanges(); expect(gsmRatePlansObject.cart).toEqual(cartData); })); });