import { CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA } from '@angular/core'; import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { Router } from '@angular/router'; import { ConfigService } from '@arrow/bom/config'; import { BomItemService, CartHandoverService, DialogService, SocketsService, Utils } from '@arrow/bom/core'; import { LoggerService } from '@arrow/bom/logger'; import { CurrencyConverterPipe, SharedModule } from '@arrow/bom/shared'; import { WptDialogRef, WPT_DIALOG_DATA } from '@arrow/warpaint/dialog'; import { WptTableModule } from '@arrow/warpaint/table'; import { Observable, of } from 'rxjs'; import { BuyingOptionService } from '../buying-option.service'; import { PackageValidatorFactory } from '../validator/packaging-validator-factory'; import { BuyingOptionsComponent } from './buying-options.component'; const mockCurrencyConverterPipe: Partial = { transform: (val: number) => { return of(val); } }; const mockBuyingOptionService: Partial = { isTargetArrowcom: () => false, getUserSelectedCurrency: () => 'USD' }; const mockSockets: Partial = { observeAction: subject => { switch (subject) { case 'rowDeleted': return of(0); break; default: return new Observable(); } }, emitAction: (actionName: string, params?: any) => { return of({}); } }; const mockRouter = { navigate: jasmine.createSpy('navigate'), events: new Observable() }; function provideDialogData() { return { // See Row model row : { pricing: { total: { price: '100' } }, item: { multiplier: '1', buyingOptions: [] } }, // See PaginationParamsModel paginationParams : { currentPage: 0, itemsPerPage: 25, filter: {}, sorting: {} } }; } describe('BuyingOptionsComponent', () => { let component: BuyingOptionsComponent; let fixture: ComponentFixture; const packageValidatorFactorySpyObj = jasmine.createSpyObj('PackageValidatorFactory', ['getValidator']); const configServiceSpyObj = jasmine.createSpyObj('ConfigService', ['getTarget']); const utilsSpyObj = jasmine.createSpyObj('Utils', ['getCurrencySymbol']); beforeEach(async(() => { TestBed.configureTestingModule({ schemas: [NO_ERRORS_SCHEMA, CUSTOM_ELEMENTS_SCHEMA], imports: [ SharedModule, // This is needed to resolve CurrencyConverterPipe instantiation issue WptTableModule ], declarations: [ BuyingOptionsComponent, ], providers: [ { provide: WptDialogRef, useValue: {} }, { provide: SocketsService, useValue: mockSockets }, { provide: BuyingOptionService, useValue: mockBuyingOptionService }, { provide: Router, useValue: mockRouter }, { provide: DialogService, useValue: {} }, { provide: BomItemService, useValue: {} }, { provide: LoggerService, useValue: {} }, { provide: PackageValidatorFactory, useValue: packageValidatorFactorySpyObj }, { provide: WPT_DIALOG_DATA, useFactory: provideDialogData }, // Below 4 were needed to resolve CurrencyConverterPipe instantiation issue { provide: CurrencyConverterPipe, useValue: mockCurrencyConverterPipe }, { provide: CartHandoverService, useValue: {} }, { provide: ConfigService, useValue: configServiceSpyObj }, { provide: Utils, useValue: utilsSpyObj } ], }).compileComponents(); })); beforeEach(() => { fixture = TestBed.createComponent(BuyingOptionsComponent); component = fixture.componentInstance; fixture.detectChanges(); }); it('should create', () => { expect(component).toBeTruthy(); }); });