// import { Component, OnInit, OnDestroy } 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 { CustomerService } from '../../services/customer.service'; 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 { EspotComponent } from '../espot/espot.component'; import { MoreDetailsComponent } from '../moredetails/more-details.component'; import { CompareComponent } from '../compare/compare.component'; import { FeaturesComponent } from './features.component'; import { CartService } from '../../services/cart.service'; import { CartServiceStub } from '../../services/cart.service.stub'; import { cartData, removeFeatureResponse, sortByResponse, packageMockData, userMockData, packagesData } from '../../shared/mock-data'; import { IFeature } from '../../shared/modal/common'; // import { CatalogServiceStub } from '../../services/catalog.service.stub'; import { TradeinService } from '../../services/tradein.service'; import { LoggingService } from '../../services/logging.service'; import CartUtils from '../../shared/cart.utils'; import { CheckoutService } from '../../services/checkout.service'; import { HttpClient, HttpHandler } from '@angular/common/http'; describe('Features Component', () => { let featuresObject: FeaturesComponent; let fixture: ComponentFixture; let dataStub: CartServiceStub; // let catalogStub: CatalogServiceStub; let cartFeatures: IFeature; beforeEach(async(() => { TestBed.configureTestingModule({ providers: [ SharedService, CatalogService, LookupService, CartService, CheckoutService, UserService, CustomerService, TradeinService, LoggingService, HttpClient, HttpHandler ], imports: [ FormsModule, RouterTestingModule ], declarations: [FeaturesComponent, PopupComponent, EspotComponent, CompareComponent, MoreDetailsComponent] }); fixture = TestBed.createComponent(FeaturesComponent); featuresObject = fixture.componentInstance; featuresObject['cart'] = cartData; featuresObject['package'] = packagesData[1]; featuresObject['filters'] = [{ type: 'feature', items: [{ name: 'string', productIds: [1234, 1002, 1003], // for local isChecked: true, }] }, { type: 'features', items: [{ name: 'strings', productIds: [2001, 2002, 2003], // for local isChecked: false, }] }]; cartFeatures = { productId: 12345, productType: 'string', categoryId: 12345, categoryName: 'string', name: 'string', description: 'string', groupName: 'SUB', socLevel: 'none', subGroupName: 'string', region: 'string', featureSOC: 'string', isPHP: true, isPHPWarranty: true, isMandatory: true, conflicts: [], monthlyPrice: 12345, altSOC: 'string', } featuresObject['features'] = [{ productId: 12345, productType: 'string', categoryId: 12345, socLevel: 'none', categoryName: 'string', name: 'string', description: 'string', groupName: 'Account Level Feature', subGroupName: 'acc1', region: 'string', featureSOC: 'string', isPHP: true, isPHPWarranty: true, isMandatory: true, conflicts: [], monthlyPrice: 12345, altSOC: 'string', }, { productId: 123456, productType: 'string', categoryId: 123456, categoryName: 'string', socLevel: 'none', name: 'string', description: 'string', groupName: 'Subscriber Level Feature', subGroupName: 'string', region: 'string', featureSOC: 'string', isPHP: true, isPHPWarranty: true, isMandatory: true, conflicts: [], monthlyPrice: 123456, altSOC: 'string', }] featuresObject.sharedService.userService['user'] = userMockData; featuresObject.catalogService.features = featuresObject['features']; featuresObject.cart = cartData; featuresObject.cartService.cart = cartData; dataStub = fixture.debugElement.injector.get(CartService); // catalogStub = fixture.debugElement.injector.get(CatalogService); TestBed.compileComponents(); TestBed.get(SharedService); TestBed.get(CartService); TestBed.get(UserService); })); // tests here it('should be created', () => { expect(featuresObject).toBeTruthy(); }); it('All methods are defined', async(() => { expect(featuresObject.clearAllFilters).toBeDefined(); })); it('Expanding more info section is working fine ', async(() => { featuresObject.expandedProductId = 4567; featuresObject.expandDetails(1234); expect(featuresObject.expandedProductId).toEqual(1234); })); it('Clearing all filters functionality is working fine', async(() => { featuresObject.clearAllFilters(); expect(featuresObject.searchText).toEqual(''); expect(featuresObject.groupName).toEqual('SUB'); })); it('Checking if atleast one feature is checked for comparison ', async(() => { const totalcheckedCount = featuresObject.atleastOneChecked(); expect(totalcheckedCount).toBeTruthy(); })); it('should resolve add feature test data ', async(() => { const spy = spyOn(featuresObject.sharedService, 'addLogging').and.returnValue( Observable.of(cartData) ); featuresObject.cartService.cart = cartData; featuresObject.addFeature(cartFeatures, 0); expect(featuresObject.sharedService.showSpinner).toBeTruthy(); })); it('should resolve update feature test data ', async(() => { const featureItem = { productId: 1234, productType: 'string', categoryId: 1234, categoryName: 'string', socLevel: 'none', name: 'string', description: 'string', groupName: 'SUB', subGroupName: 'string', featureSOC: 'string', isPHP: false, isPHPWarranty: false, isMandatory: false, conflicts: [], monthlyPrice: 1234, region: 'string', altSOC: 'string' } const spy = spyOn(dataStub, 'updateFeature').and.returnValue( Observable.of(cartData) ); featuresObject.groupName = 'SUB'; featuresObject.updateFeature(featureItem, 0); fixture.detectChanges(); expect(featuresObject.cart).toEqual(cartData); })); it('should resolve remove feature test data', fakeAsync(() => { const deleteFeatureStub = fixture.debugElement.injector.get(CartService); const featureItem = { productId: 12345, productType: 'string', categoryId: 12345, categoryName: 'string', name: 'string', description: 'string', groupName: 'SUB', subGroupName: 'string', socLevel: 'none', featureSOC: 'string', isPHP: true, isPHPWarranty: true, isMandatory: true, conflicts: [], monthlyPrice: 12345, region: 'string', altSOC: 'string' } const spy = spyOn(deleteFeatureStub, 'deleteFeature').and.returnValue( Observable.of(removeFeatureResponse) ); featuresObject.removeFeature(featureItem, 1012); fixture.detectChanges(); expect(featuresObject.cart).toEqual(removeFeatureResponse); })); it('total number of pages are set correctly', fakeAsync(() => { featuresObject.pager = { 'totalPages': 10, 'startIndex': 1, 'endIndex': 2 } featuresObject.allItems = ['orderItems', 'orderStatus'] featuresObject.setPage(2); expect(featuresObject.pagedItems.length).toEqual(0); })); it('button state is set correctly', fakeAsync(() => { const feature = { productId: 1234, productType: 'string', categoryId: 1234, categoryName: 'string', name: 'string', description: 'string', socLevel: 'none', groupName: 'string', subGroupName: 'string', featureSOC: 'string', isPHP: false, isPHPWarranty: false, isMandatory: false, conflicts: [], monthlyPrice: 1234, region: 'string', altSOC: 'string', } const buttonState = featuresObject.buttonState(feature); expect(buttonState).toEqual('REM'); })); ; it('Should do custom sorting', () => { const simOnlyDevice = { productId: 1234, productType: 'string', categoryId: 1234, categoryName: 'string', name: 'string', description: 'string', groupName: 'Subscriber Level Feature', subGroupName: 'string', region: 'string', socLevel: 'none', featureSOC: 'string', isPHP: false, isPHPWarranty: false, isMandatory: false, conflicts: [], monthlyPrice: 1234, altSOC: 'string', }; const smartPhoneDevice = { productId: 1234, productType: 'string', categoryId: 1234, categoryName: 'string', name: 'string', description: 'string', groupName: 'Subscriber Level Feature', subGroupName: 'string', region: 'string', featureSOC: 'string', socLevel: 'none', isPHP: false, isPHPWarranty: false, isMandatory: false, conflicts: [], monthlyPrice: 1234, altSOC: 'string', }; featuresObject['features'] = [simOnlyDevice, smartPhoneDevice]; featuresObject.applyCustomSorting(); expect(featuresObject.allItems[0].productId).toEqual(simOnlyDevice.productId); }); // it('Should update active package', () => { // spyOn(featuresObject, 'sortByRateplandevice'); // featuresObject.updateActivePackage(); // expect(featuresObject.sortByRateplandevice).toHaveBeenCalledWith('TMO', 'iPhone50', '98021', 'frp'); // }); it('getGroupProducts is working correctly', () => { featuresObject.groupName = 'ACC'; const product: IFeature[] = featuresObject.getGroupProducts(featuresObject.features[0]); expect(product).toBeTruthy(); }); it('Should return selected products of features', () => { const product = featuresObject.features; const orderItems = featuresObject.package.features expect(featuresObject.getSelectedProducts(product, orderItems)).toEqual(featuresObject.package.features); }); it('should return resetFeatureFilters', async(() => { const filterList = { type: 'string', items: 'Account Level Feature', } const featureGroup = { nameAcc: 'Account Level Feature', } featuresObject.resetFeatureFilters(); expect(filterList.items).toEqual(featureGroup.nameAcc); })); it('Should return selected product', () => { const product = featuresObject.features; const orderItems = featuresObject.package.features expect(featuresObject.getSelectedProduct(product, orderItems)).toEqual(featuresObject.package.features[0]); }); it('should resolve sort by rateplan test data', fakeAsync(() => { const sortRatePlanStub = fixture.debugElement.injector.get(CatalogService); const spy = spyOn(sortRatePlanStub, 'getFeaturesByRateplanDevice').and.returnValue( Observable.of(sortByResponse) ); featuresObject.sortByRateplandevice('NCFRT1UNL', '112dsvdv', '98021', 'frp'); fixture.detectChanges(); expect(featuresObject.KarmaTestResult).toEqual(sortByResponse); })); });