import { ScrollTopComponent } from './../shared/scroll-top/scroll-top.component'; import { FormsModule } from '@angular/forms'; import {CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA} from '@angular/core'; import { TestBed, async, fakeAsync, ComponentFixture } from '@angular/core/testing'; import { RouterTestingModule } from '@angular/router/testing'; import { MockBackend } from '@angular/http/testing'; import { CheckoutComponent } from './checkout.component'; import { NavbarComponent } from '../shared/navbar/navbar.component'; import { TimeoutComponent } from '../shared/timeout/timeout.component'; import { SidebarComponent } from '../shared/sidebar/sidebar.component'; import { TitleComponent } from '../shared/title/title.component'; import { ErrorComponent } from '../shared/error/error.component'; import { FooterComponent } from '../shared/footer/footer.component'; import { OrderNotesComponent } from '../shared/ordernotes/order-notes.component'; import { PopupComponent } from '../shared/popup/popup.component'; import { FixedPluginComponent } from '../shared/fixedplugin/fixedplugin.component'; import { SharedService } from '../shared/shared.service'; import { UserService } from '../services/user.service'; import { CartService } from '../services/cart.service'; import { cartData, oktaConfig } from '../shared/mock-data'; import { HttpClient, HttpHandler } from '@angular/common/http'; 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 { CheckoutService } from '../services/checkout.service'; import { LoggingService } from '../services/logging.service'; import { OktaAuthService, OktaAuthModule } from '@okta/okta-angular'; describe('Checkout Component', () => { let checkoutComponent: CheckoutComponent; let spyNavigate: any; let fixture: ComponentFixture; beforeEach(async(() => { TestBed.configureTestingModule({ providers: [ MockBackend, SharedService, UserService, CartService, CustomerService, LookupService, CatalogService, TradeinService, CheckoutService, LoggingService, HttpClient, HttpHandler, OktaAuthService ], imports: [ FormsModule, RouterTestingModule, OktaAuthModule.initAuth(oktaConfig) ], declarations: [CheckoutComponent, NavbarComponent, TimeoutComponent, SidebarComponent, TitleComponent, ErrorComponent, FooterComponent, OrderNotesComponent, PopupComponent, FixedPluginComponent, ScrollTopComponent], schemas : [CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA] }); fixture = TestBed.createComponent(CheckoutComponent); TestBed.get(SharedService); TestBed.get(CartService); TestBed.get(UserService); checkoutComponent = fixture.componentInstance; spyNavigate = spyOn(checkoutComponent.router, 'navigate'); })); it('should be created', () => { expect(checkoutComponent).toBeTruthy(); }); it('All methods are defined', async(() => { expect(checkoutComponent.onTitleAction).toBeDefined(); expect(checkoutComponent.showOrderNotesModal).toBeDefined(); expect(checkoutComponent.showClearAllModel).toBeDefined(); expect(checkoutComponent.clearAllConfirm).toBeDefined(); })); it('should resolve on Title Action test data', fakeAsync(() => { spyOn(checkoutComponent, 'showOrderNotesModal') checkoutComponent.onTitleAction('orderNotesModal'); expect(checkoutComponent.showOrderNotesModal).toHaveBeenCalled(); })); it('should resolve show order notes model test data', fakeAsync(() => { checkoutComponent.cartService.cart = cartData; spyOn(checkoutComponent.orderNotesModal, 'show') checkoutComponent.showOrderNotesModal(); expect(checkoutComponent.orderNotesModal.show).toHaveBeenCalled(); })); it('should resolve clear order model test data', fakeAsync(() => { checkoutComponent.cartService.cart = cartData; spyOn(checkoutComponent.clearAllModal, 'show') checkoutComponent.showClearAllModel(); expect(checkoutComponent.clearAllModal.show).toHaveBeenCalled(); })); });