import { cartData } from './../mock-data'; 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 { LookupService } from '../../services/lookup.service'; import { UserService } from '../../services/user.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 { TitleComponent } from './title.component'; import { customerSearchResponse, OrderNotesResponse } from '../mock-data'; import { PopupComponent } from '../popup/popup.component'; import { CatalogService } from '../../services/catalog.service'; import { LookupServiceStub } from '../../services/lookup.service.stub'; import * as Constants from '../../shared/constants'; 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 { SIDEBAR_ROUTES } from '../form.constants'; describe('title component', () => { let titleObject: TitleComponent; let fixture: ComponentFixture; let dataStub: LookupServiceStub; let spyNavigate: any; beforeEach(async(() => { TestBed.configureTestingModule({ providers: [ SharedService, LookupService, UserService, CartService, CustomerService, CheckoutService, CatalogService, TradeinService, LoggingService, HttpClient, HttpHandler ], imports: [ FormsModule, RouterTestingModule ], declarations: [TitleComponent, PopupComponent] }); fixture = TestBed.createComponent(TitleComponent); titleObject = fixture.componentInstance; spyNavigate = spyOn(titleObject.router, 'navigate'); // titleObject.body = document.getElementsByTagName('body')[0]; titleObject.cartService.cart = cartData; titleObject['cart'] = cartData; titleObject.userService.user = { firstName: 'string', middleName: 'string', lastName: 'string', logonTime: '12:4:2017', address1: null, address2: null, isRetailSurveyEnabled: false, isCDSurveyEnabled: false, isBDSurveyEnabled: false, isCSSurveyEnabled: false, city: null, state: 'string', favorites: { cardsPerRow: 3, cardsPerPage: 3, ordersPerPage: 3, headerBackground: 'string', contentBackground: 'string', sidebarBackground: 'string', sidebarActiveColor: 'string', favoriteDevicesGsm: 'string', favoriteDevicesData: 'string', favoriteAccessories: 'string' }, zipCode: 'string', phone1: 'string', phone2: 'string', email1: 'string', email2: 'string', channels: [], permissions: null, salesStats: null, registerType: 'string', adjustPricingLimit: 123, creditIssueLimit: 123, dealerCode: 'string', notifications: [], logonId: 'string', password: 'string', userId: 1, WCToken: 'string', WCTrustedToken: 'string', personalizationID: 'string', envName: 'string', jobTitle: 'string', taxAreaId: 480335435, retailStoreId: 8934678, marketCode: 'string', marketName: 'string', regionName: 'string' }; titleObject.storeId = Constants.STORE_ID_CD; dataStub = fixture.debugElement.injector.get(LookupService); TestBed.compileComponents(); })); it('should be created', () => { expect(titleObject).toBeTruthy(); }); it('All methods are defined', async(() => { expect(titleObject.getTitle).toBeDefined(); expect(titleObject.displayMinicart).toBeDefined(); })); it('should show the minicart', async(() => { titleObject.displayMinicart(); expect(titleObject.sharedService.showMincartStatus).toBeTruthy(); })); it('Mini Cart is displayed on click of cart button', async(() => { titleObject.showMinicart = false; spyOn(titleObject.sharedService, 'showMinicart'); titleObject.displayMinicart(); expect(titleObject.sharedService.showMinicart).toHaveBeenCalledWith(true); })); it('modal popup functionality', async(() => { spyOn(titleObject.onTitleAction, 'emit'); titleObject.triggerModal('customer'); expect(titleObject.onTitleAction.emit).toHaveBeenCalledWith('customer'); })); it('should navigate to Search Component', async(() => { titleObject.routerToLink('search'); expect(spyNavigate).toHaveBeenCalledWith(['search']); })); });