import { CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA } from '@angular/core'; import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { FormControl, FormGroup } from '@angular/forms'; import { ConfigService } from '@arrow/bom/config'; import { AnalyticsService, AppSessionService, BomItemService, BomService, SocketsService, TestUtils, UserService2, Utils } from '@arrow/bom/core'; import { WptTableModule } from '@arrow/warpaint/table'; import { Observable, of } from 'rxjs'; import { ListComponent } from './list.component'; import { Row } from './ORM/types/custom/row.interface'; let testUtils: TestUtils; describe('ListComponent', () => { let component: ListComponent; let fixture: ComponentFixture; 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 mockBomService: Partial = { getBomQuantitiesInformation: () => of() }; beforeEach(async(() => { const configServiceSpyObj = jasmine.createSpyObj('ConfigService', ['getTarget']); const bomItemServiceSpyObj = jasmine.createSpyObj('BomItemService', ['resetSelection']); TestBed.configureTestingModule({ schemas: [NO_ERRORS_SCHEMA, CUSTOM_ELEMENTS_SCHEMA], imports:[ WptTableModule ], declarations: [ ListComponent ], providers: [ { provide: BomItemService, useValue: bomItemServiceSpyObj }, { provide: ConfigService, useValue: configServiceSpyObj }, { provide: AppSessionService, useValue: {} }, { provide: UserService2, useValue: {} }, { provide: AnalyticsService, useValue: {} }, { provide: SocketsService, useValue: mockSockets }, { provide: Utils, useValue: {} }, { provide: BomService, useValue: mockBomService }, TestUtils ] }).compileComponents(); })); beforeEach(() => { fixture = TestBed.createComponent(ListComponent); component = fixture.componentInstance; testUtils = TestBed.inject(TestUtils); fixture.detectChanges(); }); it('should create', () => { expect(component).toBeTruthy(); }); it('should update quantity control value based on multiplier', () => { const expectedQuantity = 200; const item = testUtils.createBomListItemModelArray(1)[0]; item.quantity = 2; item.multiplier = 10; item.quantities = [ { id : 'qtyColumnId', displayQuantity: expectedQuantity, autoRoundedState : null } ]; const row: Row = { item, id: '0', control: new FormGroup({ // TODO: not sure I understand why there is a logic not to update quantity if original value was positive, i.e,. 999 qtyColumnId: new FormControl(-1) }) }; component.onUpdateQuantity(row, 'qtyColumnId', 10) expect(row.control.get('qtyColumnId').value).toBe(expectedQuantity, 'quantity value not updated'); }); });