import { PurchaseEstimateComponent } from './purchase-estimate/purchase-estimate.component'; import { cartData } from './../../../shared/spec.constants'; import { BlockReviewComponent } from './blockreview/block-review.component'; import { AuthenticateComponent } from './authenticate/authenticate.component'; // 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 { TestBed, async, fakeAsync, ComponentFixture } from '@angular/core/testing'; import { RouterTestingModule } from '@angular/router/testing'; import { SharedService } from '../../../shared/shared.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 { CartService } from '../../../services/cart.service'; import { CartServiceStub } from '../../../services/cart.service.stub'; import { OrderDetailComponent } from './order-detail.component'; import { cartDataResponse, shippingData, userMockData, customerSearchResponse, paymentData, financeData, promotionData } from '../../../shared/mock-data'; import { OrderInfoComponent } from './order-info/order-info.component'; import { ProductsDetailComponent } from './products-detail/products-detail.component'; import { OrderShippingComponent } from './order-shipping/order-shipping.component'; import { OrderPaymentComponent } from './order-payment/order-payment.component'; import { OrderPromoComponent } from './order-promo/order-promo.component'; import { OrderAdvanceComponent } from './order-advance/order-advance.component'; import { ReturnExchangeComponent } from './return-exchange/return-exchange.component'; import { AssociatedOrdersComponent } from './associated-orders/associated-orders.component'; import { PopupComponent } from '../../../shared/popup/popup.component'; import { ProductsComponent } from '../../../shared/products/products.component'; import { ReturnCartComponent } from './return-exchange/returncart/return-cart.component'; import { CheckoutService } from '../../../services/checkout.service'; import { ManualReviewComponent } from '../../manualreview/manual-review.component'; import * as Constants from '../../../shared/constants'; import { LoggingService } from '../../../services/logging.service'; import { TradeinService } from '../../../services/tradein.service'; import { IssueCreditComponent } from './issue-credit/issue-credit.component'; import { CreditIssueCartComponent } from './issue-credit/creditissue/creditissue-cart.component'; import { HttpClient, HttpHandler } from '@angular/common/http'; describe('Order detail Component', () => { let orderDetailObject: OrderDetailComponent; let fixture: ComponentFixture; let dataStub: CartServiceStub; let spyNavigate: any; beforeEach(async(() => { TestBed.configureTestingModule({ providers: [ SharedService, UserService, CheckoutService, CartService, CustomerService, LookupService, CatalogService, LoggingService, TradeinService, HttpClient, HttpHandler ], imports: [ FormsModule, RouterTestingModule ], declarations: [OrderDetailComponent, OrderInfoComponent, ProductsDetailComponent, OrderShippingComponent, OrderPaymentComponent, OrderPromoComponent, OrderAdvanceComponent, ReturnExchangeComponent, AssociatedOrdersComponent, PopupComponent, ProductsComponent, ReturnCartComponent, IssueCreditComponent, CreditIssueCartComponent, ManualReviewComponent, AuthenticateComponent, BlockReviewComponent, PurchaseEstimateComponent] }); fixture = TestBed.createComponent(OrderDetailComponent); orderDetailObject = fixture.componentInstance; dataStub = fixture.debugElement.injector.get(CartService); TestBed.compileComponents(); TestBed.get(SharedService); TestBed.get(CartService); TestBed.get(UserService); orderDetailObject.storeId = 10553; orderDetailObject['cart'] = cartData; orderDetailObject['user'] = userMockData; orderDetailObject.userService.user = orderDetailObject['user']; spyNavigate = spyOn(orderDetailObject.router, 'navigate'); })); // tests here it('should be created', () => { expect(orderDetailObject).toBeTruthy(); }); it('All methods are defined', async(() => { expect(orderDetailObject.showOrderShipping).toBeDefined(); })); it('Navigates to order list', fakeAsync(() => { orderDetailObject['orderList'] = { orders: [{ orderId: 12345, fullOrderId: 'string', firstName: 'string', lastName: 'string', customerId: 11, storeId: 1, refType: 'string', status: 'string', logonId: 1, createdDate: 'string' }, { orderId: 12346, fullOrderId: 'string', firstName: 'string', lastName: 'string', customerId: 12, storeId: Constants.STORE_ID_CD, refType: 'string', status: 'string', logonId: 1, createdDate: 'string' } ], totalCount: 2, isTotalGreaterThanMax: true } orderDetailObject.navigateToSearch(); expect(spyNavigate).toHaveBeenCalledWith(['/home/search/order-list']); })); it('should resolve show order shipping test data', fakeAsync(() => { const spy = spyOn(dataStub, 'getCartShipping').and.returnValue( Observable.of(shippingData) ); orderDetailObject.showOrderShipping(48919251); fixture.detectChanges(); expect(orderDetailObject.showOrderShippingData).toEqual(shippingData); })); it('should resolve show order payment test data', fakeAsync(() => { const spy = spyOn(dataStub, 'getCartPayment').and.returnValue( Observable.of(paymentData) ); orderDetailObject.showOrderPayment(48919251); fixture.detectChanges(); expect(orderDetailObject.showOrderPaymentResponse).toEqual(paymentData); })); it('should resolve show order finance test data', fakeAsync(() => { const spy = spyOn(dataStub, 'getCartFinance').and.returnValue( Observable.of(financeData) ); orderDetailObject.showOrderFinance(48919251); fixture.detectChanges(); expect(orderDetailObject.showOrderFinanceComponent).toEqual(financeData); })); it('should resolve show order promo test data', fakeAsync(() => { const spy = spyOn(dataStub, 'getCartPromo').and.returnValue( Observable.of(promotionData) ); orderDetailObject.showOrderPromo(48919251); fixture.detectChanges(); console.log(); expect(orderDetailObject.showOrderPromoResponse).toEqual(promotionData); })); it('Order Status is mapped correctly', fakeAsync(() => { let orderStatus: string; orderDetailObject['orderStatusItems'] = ['P', 'P10']; orderStatus = orderDetailObject.getStatusLabel('PPP'); expect(orderStatus).toEqual('Not Found'); })); it('conflicts are resolved', async(() => { spyOn(orderDetailObject.cartService, 'setCart'); orderDetailObject.cart = null; orderDetailObject.resolveConflicts(); expect(orderDetailObject.cartService.setCart).toHaveBeenCalledWith(orderDetailObject.cart); })); it('resumeThisOrder working correctly', async(() => { orderDetailObject.cart = null; spyOn(orderDetailObject, 'resumeThisOrder'); orderDetailObject.resumeThisOrder(); expect(orderDetailObject.resumeThisOrder).toHaveBeenCalled(); })); it('resumeThisOrder working correctly', async(() => { const check = true; spyOn(orderDetailObject, 'ngOnInit'); orderDetailObject.refreshCart(check); expect(orderDetailObject.associatedOrders).toEqual(null); })); it('showBlindAssociatedOrders working correctly', async(() => { const spy = spyOn(dataStub, 'getSapOrderList').and.returnValue( Observable.of(cartData) ); orderDetailObject.showBlindAssociatedOrders('12345'); expect(orderDetailObject.cartService.getSapOrderList).toHaveBeenCalled(); })); it('Associated orders are showed correctly', fakeAsync(() => { const cartStub = fixture.debugElement.injector.get(CartService); const spy = spyOn(cartStub, 'getAssociatedOrders').and.returnValue( Observable.of(cartData) ); orderDetailObject.showAssociatedOrders(12345); expect(orderDetailObject.cartService.getAssociatedOrders).toHaveBeenCalled(); })); it('should resolve show order customer test data', fakeAsync(() => { const customerSearchStub = fixture.debugElement.injector.get(CustomerService); const spy = spyOn(customerSearchStub, 'getCustomerProfile').and.returnValue( Observable.of(customerSearchResponse) ); orderDetailObject.showOrderCustomer(20045); fixture.detectChanges(); expect(orderDetailObject.customer).toEqual(customerSearchResponse); })); });