// import { Component, OnInit, OnDestroy } from '@angular/core'; // import { Router, ActivatedRoute, Route } from '@angular/router'; import { Observable } from 'rxjs/Rx'; import { DebugElement } from '@angular/core'; import { FormsModule } from '@angular/forms'; import { By } from '@angular/platform-browser'; import { TestBed, async, ComponentFixture } from '@angular/core/testing'; import { RouterTestingModule } from '@angular/router/testing'; import { CartService } from '../../services/cart.service'; import { UserService } from '../../services/user.service'; import { CustomerService } from '../../services/customer.service'; import { LookupService } from '../../services/lookup.service'; import { CatalogService } from '../../services/catalog.service'; import { UserServiceStub } from '../../services/user.service.stub'; import { CompareComponent } from './compare.component'; import { SharedService } from '../../shared/shared.service'; import { CatalogServiceStub } from '../../services/catalog.service.stub'; 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 { CompareService } from '../../shared/compare-modal.service'; import { moreInfoResponse } from '../../shared/spec.constants'; // import {Conne} describe('Compare Component', () => { let compareObject: CompareComponent; let fixture: ComponentFixture; let sharedService: SharedService; let catalogServiceStub: CatalogServiceStub; let debugElement: DebugElement; let el: HTMLElement; beforeEach(async(() => { TestBed.configureTestingModule({ providers: [ SharedService, UserService, CartService, CustomerService, LookupService, CatalogService, CheckoutService, TradeinService, LoggingService, HttpClient, HttpHandler, CompareService ], imports: [ FormsModule, RouterTestingModule ], declarations: [CompareComponent] }); fixture = TestBed.createComponent(CompareComponent); compareObject = fixture.componentInstance; compareObject.products = []; compareObject.compareProducts = []; compareObject['product'] = { 'productType': 'GSM', 'categoryName': 'Device', 'categoryId': 2, 'productId': 123456, 'name': 'Stylo™ 3 PLUS', 'description': '•5.7 FHD IPS Display
•Premium Stylus Pen
•13MP Rear-Facing Camera
•Fast Charging Capability
•5MP Front-Facing Camera
•Fingerprint Sensor
•Video Recording and Playback', 'items': [ { 'isRefurbished': false, 'openBoxDiscount': 0, 'instantDiscount': 0, 'promotionDiscount': 0, 'shipDateTo': null, 'isByos': false, 'suggestedPrice': 225, 'name': 'Stylo™ 3 PLUS', 'thumbNail': '/images/png/products/phones/LG-Stylo-3-PLUS/110x110.png', 'fullImage': '/images/png/products/phones/LG-Stylo-3-PLUS/170x250.png', 'colorName': null, 'itemId': 150945, 'loan': null, 'lease': null, 'status': 'OOS', 'finalPrice': 225, 'shipDateFrom': null, 'colorImageUrl': null, 'mailInRebate': 0, 'description': null, 'deviceSKU': '610214652492', 'state': 'ADD' } ], 'manufacturer': 'LG', 'itemIndex': 0, 'canCompare': true } catalogServiceStub = fixture.debugElement.injector.get(CatalogService); // dataStub = fixture.debugElement.injector.get(UserService); TestBed.compileComponents(); // spyNavigate = spyOn(compareObject.router, 'navigate'); })); // tests here it('should be created', () => { expect(compareObject).toBeTruthy(); }); it('All methods are defined', async(() => { expect(compareObject.hide).toBeDefined(); expect(compareObject.onContainerClicked).toBeDefined(); expect(compareObject.getMoreDetails).toBeDefined(); expect(compareObject.updateOverviewKeys).toBeDefined(); expect(compareObject.getCompareValue).toBeDefined(); expect(compareObject.isFeatureExisted).toBeDefined(); })); it('Should get the more details', async(() => { const spy = spyOn(catalogServiceStub, 'getProductMoreInfo').and.returnValue( Observable.of(moreInfoResponse) ); compareObject.moreInfoList = []; compareObject.getMoreDetails(compareObject['product']); fixture.detectChanges(); expect(compareObject.karmaTestResult).toEqual(moreInfoResponse); })); it('should update the overview keys', () => { let moreInfoList = [ { 'itemList': [ { 'value': 'Up to 20 hours', 'name': 'Talk Time' }, { 'value': 'Up to 20 days', 'name': 'Stand by Time' }, { 'value': '2600 mAh', 'name': 'Battery' } ], 'group': 'overview', 'productId': 123456, 'name': 'string', 'items': [] } ]; compareObject.moreInfoList = []; compareObject.updateOverviewKeys(moreInfoList); fixture.detectChanges(); expect(compareObject.overviewKeys).toEqual(['Talk Time', 'Stand by Time', 'Battery']); }); it('should get the compare value', () => { let moreInfoList = [ { 'itemList': [ { 'value': 'Up to 20 hours', 'name': 'Talk Time' }, { 'value': 'Up to 20 days', 'name': 'Stand by Time' }, { 'value': '2600 mAh', 'name': 'Battery' } ], 'group': 'overview', 'productId': 123456, 'name': 'string', 'items': [] } ]; compareObject.moreInfoList = []; let group = 'overview', key = 'Battery'; // compareObject.getCompareValue(moreInfoList, group, key); // fixture.detectChanges(); expect(compareObject.getCompareValue(moreInfoList, group, key)).toEqual('2600 mAh'); }); it('should check whether the feature is existed or not', () => { let moreInfoList = [{ 'itemList': [ { 'value': '4G LTE data speed capability for the best video calling, streaming, and entertainment on the go.', 'name': '4G LTE Capable' }, { 'value': '2MP front-facing camera for amazing selfies.', 'name': '2MP Front-Facing Camera' }, { 'value': 'Latest Android OS with loaded adventures.', 'name': 'Android 7.0 Nougat' }, { 'value': 'Powerful performance with a quad-core 1.35 GHz processor.', 'name': '1.35 GHz Quad-Core Processor' } ], 'group': 'features', 'productId': 123456, 'name': 'string', 'items': [] } ]; compareObject.features = [{ name: 'Android 7.0 Nougat', productIds: [123456], // for local isChecked: true }]; compareObject.moreInfoList = []; let featureName = 'Android 7.0 Nougat'; let group = 'overview', key = 'Battery'; // compareObject.getCompareValue(moreInfoList, group, key); // fixture.detectChanges(); expect(compareObject.isFeatureExisted(compareObject['product'], featureName)).toBeTruthy(); }); it('should hide the compare modal', () => { compareObject.visibleAnimate = true; compareObject.hide(); expect(compareObject.visibleAnimate).toBeFalsy(); }); it('Should open the modal if it is opened and viceverse', async(() => { debugElement = fixture.debugElement.query(By.css('.modal-container')); el = debugElement.nativeElement; compareObject.show(); el.click(); expect(compareObject.visible).toEqual(true); })); it('should show the compare modal', () => { compareObject.visibleAnimate = false; compareObject.show(); expect(compareObject.visible).toBeTruthy(); }); });