import { cartData } from './../../../shared/mock-data'; import { TestBed, async, fakeAsync, ComponentFixture } from '@angular/core/testing'; import { FormsModule } from '@angular/forms'; import { RouterTestingModule } from '@angular/router/testing'; import { Observable } from 'rxjs/Rx'; import { OrderListComponent } from './order-list.component'; import { LookupService } from '../../../services/lookup.service'; import { SharedService } from '../../../shared/shared.service'; import { UserService } from '../../../services/user.service'; import { CartService } from '../../../services/cart.service'; import { CustomerService } from '../../../services/customer.service'; import { CatalogService } from '../../../services/catalog.service'; import { CartServiceStub } from '../../../services/cart.service.stub'; import { cartDataResponse, customerSearchResponse, orderDate } from '../../../shared/mock-data'; import { BehaviorSubject } from 'rxjs/BehaviorSubject'; import Utils from '../../../shared/utils'; 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 { HttpHandler, HttpClient } from '@angular/common/http'; describe('Order List Component', () => { let orderListObject: OrderListComponent; let fixture: ComponentFixture; let cartServiceStub: CartServiceStub; let spyNavigate: any; beforeEach(async(() => { TestBed.configureTestingModule({ providers: [ SharedService, Utils, UserService, CartService, CustomerService, CatalogService, LookupService, CheckoutService, TradeinService, LoggingService, HttpClient, HttpHandler ], imports: [ FormsModule, RouterTestingModule ], declarations: [OrderListComponent] }); fixture = TestBed.createComponent(OrderListComponent); orderListObject = fixture.componentInstance; cartServiceStub = fixture.debugElement.injector.get(CartService); TestBed.compileComponents(); TestBed.get(SharedService); TestBed.get(CartService); TestBed.get(UserService); orderListObject.orderSearchModel = {}; orderListObject.lookupService.orderSearchModel = { status: true } orderListObject['cart'] = cartData; spyNavigate = spyOn(orderListObject.router, 'navigate'); })); // tests here it('should be created', () => { expect(orderListObject).toBeTruthy(); }); it('All methods are defined', async(() => { expect(orderListObject.showOrderSummary).toBeDefined(); })); it('should resolve show order summary test data', fakeAsync(() => { const spy = spyOn(cartServiceStub, 'getCartSummaryInclCancelled').and.returnValue( Observable.of(cartDataResponse) ); orderListObject.showOrderSummary(20045); fixture.detectChanges(); expect(orderListObject.showOrderSummaryData).toEqual(cartDataResponse); })); it('Order Status is mapped correctly', fakeAsync(() => { let orderStatus: string; orderListObject['orderStatusItems'] = ['P', 'P10']; orderStatus = orderListObject.getStatusLabel('PPP'); expect(orderStatus).toEqual('Not Found'); })); it('Channel Status is mapped correctly', fakeAsync(() => { let channelStatus: string; orderListObject['orderStoresItems'] = [Constants.STORE_ID_BD, Constants.STORE_ID_MYTMO]; channelStatus = orderListObject.getChannelLabel(Constants.STORE_ID_CD); expect(channelStatus).toEqual('Not Found'); })); it('Date conversion is working fine', fakeAsync(() => { const dateobj: string = orderListObject.getDateLable(orderDate).toString(); const convertedDate = new Date(orderDate).toString() expect(dateobj).toEqual(convertedDate); })); it('total number of pages are set correctly', fakeAsync(() => { orderListObject.pager = { 'totalPages': 10, 'startIndex': 1, 'endIndex': 2 } orderListObject.allItems = ['orderItems', 'orderStatus'] orderListObject.setPage(2); expect(orderListObject.pagedItems.length).toEqual(0); })); it('should sort and change the direction', async(() => { orderListObject.isDesc = false; orderListObject.sort(1); expect(orderListObject.direction).toEqual(1); expect(orderListObject.isDesc).toBeTruthy(); })); it('should order by passed parameters', async(() => { spyOn(orderListObject, 'setPage'); orderListObject.allItems = ['orderItems', 'orderStatus', 'fullOrderId.com']; orderListObject.orderBy('fullOrderId', 2); expect(orderListObject.setPage).toHaveBeenCalledWith(1); })); });