import { Component, OnInit, OnDestroy } from '@angular/core'; import { Router, ActivatedRoute } from '@angular/router'; import { Observable } from 'rxjs/Rx'; import { DebugElement } from '@angular/core'; import { FormsModule } from '@angular/forms'; import { inject, tick, TestBed, getTestBed, async, fakeAsync, ComponentFixture } from '@angular/core/testing'; import { RouterTestingModule } from '@angular/router/testing'; import { Http, HttpModule, ConnectionBackend, RequestOptions, BaseRequestOptions, XHRBackend } from '@angular/http'; import { MockBackend, MockConnection } from '@angular/http/testing'; import { SharedService } from '../shared.service'; import { UserService } from '../../services/user.service'; import { CheckoutService } from '../../services/checkout.service'; import { CartService } from '../../services/cart.service'; import { CustomerService } from '../../services/customer.service'; import { LookupService } from '../../services/lookup.service'; import { CatalogService } from '../../services/catalog.service'; import { TradeinService } from '../../services/tradein.service'; import { LoggingService } from '../../services/logging.service'; import { SurveyComponent } from './survey.component'; import { By } from '@angular/platform-browser'; import { RatingComponent } from '../rating/rating.component'; import { MarketingService } from '../../services/marketing.service'; import { userMockData } from '../mock-data'; import { HttpClient, HttpHandler } from '@angular/common/http'; import { cartData } from '../spec.constants'; // import {Conne} describe('Survey Component', () => { let obj: SurveyComponent; let fixture: ComponentFixture; let debugElement: DebugElement; let el: HTMLElement; beforeEach(async(() => { TestBed.configureTestingModule({ providers: [ MockBackend, BaseRequestOptions, SharedService, UserService, CartService, CustomerService, LookupService, CatalogService, TradeinService, LoggingService, CheckoutService, MarketingService, HttpClient, HttpHandler ], imports: [ FormsModule, HttpModule, RouterTestingModule ], declarations: [SurveyComponent, RatingComponent] }); fixture = TestBed.createComponent(SurveyComponent); obj = fixture.componentInstance; TestBed.compileComponents(); obj['user'] = userMockData; })); // tests here it('should be created', () => { expect(obj).toBeTruthy(); }); it('All methods are defined', () => { expect(obj.show).toBeDefined(); expect(obj.hide).toBeDefined(); expect(obj.onContainerClicked).toBeDefined(); }); it('should hide the modal', () => { obj.visibleAnimate = true; obj.hide(); expect(obj.visibleAnimate).toBeFalsy(); }); it('should show the modal', () => { obj.visibleAnimate = false; obj.show(cartData); expect(obj.visible).toBeTruthy(); }); it('Should open the modal if it is opened and viceverse', async(() => { debugElement = fixture.debugElement.query(By.css('.fade')); el = debugElement.nativeElement; obj.show(cartData); el.click(); expect(obj.visible).toEqual(true); })); });