import { ComponentFixture, TestBed } from '@angular/core/testing'; import { CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA } from '@angular/core'; import { FormsModule, ReactiveFormsModule } from '@angular/forms'; //services import { BomItemService, ModalService, PermissionsService, DialogService, CartHandoverService, Utils } from '@arrow/bom/core'; import { ConfigService } from '@arrow/bom/config'; //components import { PricingComponent } from './pricing.component'; import { HttpClient } from '@angular/common/http'; import { of } from 'rxjs'; import { CurrencyConverterPipe } from '../currency-converter/currency-converter.pipe'; import { SharedModule } from '../shared.module'; let fixture: ComponentFixture; let comp: PricingComponent; // const presentationStub: any = { // listItem: { // incrementsOf: 'Increments of', // minimum: 'Minimum', // canShipToday: 'Can ship today', // canShipTomorrow: 'Can ship tomorrow', // canShipIn: 'Can ship in', // days: 'days', // addToCart: 'add to cart', // updateCart: 'update cart', // notInStock: 'Not in stock', // couldNotFindYourPart: 'We are sorry we could not find your part', // selectAltPartInfo: 'No exact matches found', // selectAltPart: 'Please select an alternate.', // updatingPrice: 'Updating price...', // updatingStock: 'Updating stock...', // noStockInfo: 'No stock info', // viewMore: 'View more', // viewLess: 'View less', // perUnit: 'Per Unit', // noPriceInfo: 'No price info', // packaging: 'Packaging', // addComment: 'Add comment', // obsolete: 'Obsolete' // }, // buyingOptions: 'Buying options' // }; const mockBomItemService: Partial = { // deleteItemClick$: new Observable(), // newItemAdded$: new Observable(), // selectAllToggle$: new Observable(), // indexShifted$: new Observable<{ // startIndex: number; // shiftAmount: number; // }>(), // userChangedSelection$: new Observable(), // selectionChanged$: new Observable(), // setItemLoading: () => {}, // updateSelection: () => {}, // deleteItemClicked: () => {}, // getSelection: () => {}, // isPartialSelection: () => true }; const mockPermissionsService: Partial = { getPermissions: () => { return of(); } }; const mockCurrencyConverterPipe: Partial = { transform: (val: number) => { return of(val); } }; describe('PricesComponent', () => { beforeEach(() => { const httpClientSpyObj = jasmine.createSpyObj('HttpClient', ['post', 'get']); const configServiceSpyObj = jasmine.createSpyObj('ConfigService', ['getTarget']); const dialogServiceSpyObj = jasmine.createSpyObj('DialogService', ['alert', 'confirm']); const utilsSpyObj = jasmine.createSpyObj('Utils', ['getCurrencySymbol']); TestBed.configureTestingModule({ schemas: [NO_ERRORS_SCHEMA, CUSTOM_ELEMENTS_SCHEMA], imports: [ FormsModule, ReactiveFormsModule, SharedModule // This is needed to resolve CurrencyConverterPipe and PricingComponent instantiation issue ], providers: [ { provide: HttpClient, useValue: httpClientSpyObj }, { provide: DialogService, useValue: dialogServiceSpyObj }, { provide: BomItemService, useValue: mockBomItemService }, { provide: PermissionsService, useValue: mockPermissionsService }, ModalService, // Below 4 were needed to resolve CurrencyConverterPipe instantiation issue { provide: CurrencyConverterPipe, useValue: mockCurrencyConverterPipe }, { provide: ConfigService, useValue: configServiceSpyObj }, { provide: CartHandoverService, useValue: {} }, { provide: Utils, useValue: utilsSpyObj } ], declarations: [ // PricingComponent ] }); TestBed.compileComponents(); fixture = TestBed.createComponent(PricingComponent); comp = fixture.componentInstance; fixture.detectChanges(); }); it('should instantiate and be defined', () => { // checks component exists expect(comp).toBeDefined(); }); });