import { CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA } from '@angular/core'; import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { ListItemModel, ListItemConstructor, Utils } from '@arrow/bom/core'; import { BomPartStockComponent } from './bom-part-stock.component'; describe('BomPartStockComponent', () => { let component: BomPartStockComponent; let fixture: ComponentFixture; beforeEach(async(() => { TestBed.configureTestingModule({ schemas: [NO_ERRORS_SCHEMA, CUSTOM_ELEMENTS_SCHEMA], declarations: [BomPartStockComponent], providers : [ { provide : Utils, useValue: jasmine.createSpyObj('Utils', ['translateByKeyWithFallback']) } ] }).compileComponents(); })); beforeEach(() => { fixture = TestBed.createComponent(BomPartStockComponent); component = fixture.componentInstance; component.item = createBomListItemModelArray(1)[0]; fixture.detectChanges(); }); const createBomListItemModelArray = (size: number, data: any = { } ) => { const result: ListItemModel[] = []; data.alternates = data.alternates || []; data.partInfo = data.partInfo || {}; data.input = data.input || { used: {}, original: {}, previousOriginal: {} }; data.isLoading = false; data.priceSourceLoading = false; for (let i = 0; i <= size; i++) { const itemConstructor: ListItemConstructor = { data, rowId: i.toString() }; result.push(new ListItemModel(itemConstructor)); } return result; }; it('should create', () => { expect(component).toBeTruthy(); }); it('should recalculate MBO', () => {}); [ { input: -1, shouldDisplay: false }, { input: 0, shouldDisplay: true }, { input: 1, shouldDisplay: true } ].forEach((testCase, index) => { it(`should properly display Buffer for ${testCase.input}`, () => { component.item.priceSourceLoading = false; component.item.isLoading = false; component.item.matchStatus = 1; component.item.bufferStock = testCase.input; // Act fixture.detectChanges(); // Assert let bufferStockElement = fixture.componentInstance.bufferStockEl; console.log(bufferStockElement) if (!testCase.shouldDisplay) { expect(bufferStockElement).toBeUndefined(); } else { expect(Number(bufferStockElement.nativeElement.innerHTML.trim())).toEqual(component.item.bufferStock); } }); }); [ { input: -1, shouldDisplay: false }, { input: 0, shouldDisplay: true }, { input: 1, shouldDisplay: true } ].forEach((testCase, index) => { it(`should properly display Factory for ${testCase.input}`, () => { component.item.priceSourceLoading = false; component.item.isLoading = false; component.item.matchStatus = 1; component.item.factoryStock = testCase.input; // Act fixture.detectChanges(); // Assert let factoryStockElement = fixture.componentInstance.factoryStockEl; if (!testCase.shouldDisplay) { expect(factoryStockElement).toBeUndefined(); } else { expect(Number(factoryStockElement.nativeElement.innerHTML.trim())).toEqual(component.item.factoryStock); } }); }); });