diff --git a/src/app/product-store/product-detail/product-props/product-props.component.spec.ts b/src/app/product-store/product-detail/product-props/product-props.component.spec.ts index 5726b9e..8dc5e7b 100644 --- a/src/app/product-store/product-detail/product-props/product-props.component.spec.ts +++ b/src/app/product-store/product-detail/product-props/product-props.component.spec.ts @@ -100,15 +100,15 @@ describe('ProductPropertyComponent', () => { classifications: new FormControl(null) }) component.formGroup = formGroup as FormGroup - component.changeMode = 'NEW' + component.changeMode = 'CREATE' component.onSubmit() expect(apiServiceSpy.createProduct).toHaveBeenCalled() - expect(msgServiceSpy.success).toHaveBeenCalledWith({ summaryKey: 'ACTIONS.CREATE.MESSAGE.PRODUCT_OK' }) + expect(msgServiceSpy.success).toHaveBeenCalledWith({ summaryKey: 'ACTIONS.CREATE.PRODUCT.OK' }) }) - it('should call updateProduct onSubmit in view mode', () => { + it('should call updateProduct onSubmit in edit mode', () => { apiServiceSpy.updateProduct.and.returnValue(of({})) const formGroup = new FormGroup({ id: new FormControl('id'), @@ -123,15 +123,15 @@ describe('ProductPropertyComponent', () => { classifications: new FormControl(null) }) component.formGroup = formGroup as FormGroup - component.changeMode = 'VIEW' + component.changeMode = 'EDIT' component.onSubmit() expect(apiServiceSpy.updateProduct).toHaveBeenCalled() - expect(msgServiceSpy.success).toHaveBeenCalledWith({ summaryKey: 'ACTIONS.EDIT.MESSAGE.PRODUCT_OK' }) + expect(msgServiceSpy.success).toHaveBeenCalledWith({ summaryKey: 'ACTIONS.EDIT.PRODUCT.OK' }) }) - it('should display error if searchProducts fails', () => { + it('should display error if updateProduct fails', () => { apiServiceSpy.updateProduct.and.returnValue(throwError(() => new Error())) const formGroup = new FormGroup({ id: new FormControl('id'), @@ -146,17 +146,17 @@ describe('ProductPropertyComponent', () => { classifications: new FormControl(null) }) component.formGroup = formGroup as FormGroup - component.changeMode = 'VIEW' + component.changeMode = 'EDIT' component.onSubmit() expect(component.formGroup.valid).toBeTrue() expect(msgServiceSpy.error).toHaveBeenCalledWith({ - summaryKey: 'ACTIONS.EDIT.MESSAGE.PRODUCT_NOK' + summaryKey: 'ACTIONS.EDIT.PRODUCT.NOK' }) }) - it('should display error if searchProducts fails', () => { + it('should display error if createProduct fails', () => { apiServiceSpy.createProduct.and.returnValue(throwError(() => new Error())) const formGroup = new FormGroup({ id: new FormControl('id'), @@ -171,13 +171,13 @@ describe('ProductPropertyComponent', () => { classifications: new FormControl(null) }) component.formGroup = formGroup as FormGroup - component.changeMode = 'NEW' + component.changeMode = 'CREATE' component.onSubmit() expect(component.formGroup.valid).toBeTrue() expect(msgServiceSpy.error).toHaveBeenCalledWith({ - summaryKey: 'ACTIONS.CREATE.MESSAGE.PRODUCT_NOK' + summaryKey: 'ACTIONS.CREATE.PRODUCT.NOK' }) }) diff --git a/src/app/product-store/product-detail/product-props/product-props.component.ts b/src/app/product-store/product-detail/product-props/product-props.component.ts index ccc2bcc..9f244b9 100644 --- a/src/app/product-store/product-detail/product-props/product-props.component.ts +++ b/src/app/product-store/product-detail/product-props/product-props.component.ts @@ -86,6 +86,8 @@ export class ProductPropertyComponent implements OnChanges { this.changeMode !== 'VIEW' ? this.formGroup.enable() : this.formGroup.disable() } + /** CREATE/UPDATE product + */ public onSubmit() { if (this.formGroup.valid) { this.changeMode === 'CREATE' ? this.createProduct() : this.updateProduct() @@ -120,15 +122,6 @@ export class ProductPropertyComponent implements OnChanges { }) } - private displaySaveError(err: any) { - err.error && err.error.errorCode && err.error.errorCode === 'MERGE_ENTITY_FAILED' // 'PERSIST_ENTITY_FAILED' - ? this.msgService.error({ - summaryKey: 'ACTIONS.' + this.changeMode + '.PRODUCT.NOK', - detailKey: 'VALIDATION.PRODUCT.UNIQUE_CONSTRAINT' - }) - : this.msgService.error({ summaryKey: 'ACTIONS.' + this.changeMode + '.PRODUCT.NOK' }) - } - private updateProduct() { this.productApi .updateProduct({ @@ -154,6 +147,17 @@ export class ProductPropertyComponent implements OnChanges { }) } + private displaySaveError(err: any) { + err.error && err.error.errorCode && err.error.errorCode === 'MERGE_ENTITY_FAILED' // 'PERSIST_ENTITY_FAILED' + ? this.msgService.error({ + summaryKey: 'ACTIONS.' + this.changeMode + '.PRODUCT.NOK', + detailKey: 'VALIDATION.PRODUCT.UNIQUE_CONSTRAINT' + }) + : this.msgService.error({ summaryKey: 'ACTIONS.' + this.changeMode + '.PRODUCT.NOK' }) + } + + /** File Handling + */ public onFileUpload(ev: Event, fieldType: 'logo'): void { if (ev.target && (ev.target as HTMLInputElement).files) { const files = (ev.target as HTMLInputElement).files diff --git a/src/app/product-store/product-detail/product.detail.component.spec.ts b/src/app/product-store/product-detail/product.detail.component.spec.ts index 67d0467..79759ae 100644 --- a/src/app/product-store/product-detail/product.detail.component.spec.ts +++ b/src/app/product-store/product-detail/product.detail.component.spec.ts @@ -191,7 +191,7 @@ describe('ProductDetailComponent', () => { expect(component.productPropsComponent.onSubmit).toHaveBeenCalled() }) - it('should behave correctly onCreate', () => { + it('should behave correctly onCreate henry', () => { const data: any = { id: 'id ' } component.onCreate(data) @@ -207,7 +207,7 @@ describe('ProductDetailComponent', () => { expect(component.close).toHaveBeenCalled() }) - it('should behave correctly onNameChange if change false', () => { + it('should behave correctly onChange if change false', () => { spyOn(component, 'getProduct') component.onChange(false) diff --git a/src/app/product-store/product-search/product-search.component.spec.ts b/src/app/product-store/product-search/product-search.component.spec.ts index bfa3f25..5cc6b4a 100644 --- a/src/app/product-store/product-search/product-search.component.spec.ts +++ b/src/app/product-store/product-search/product-search.component.spec.ts @@ -60,7 +60,7 @@ describe('ProductSearchComponent', () => { }) it('should prepare action buttons on init', () => { - translateServiceSpy.get.and.returnValue(of({ 'ACTIONS.CREATE.PRODUCT': 'Create' })) + translateServiceSpy.get.and.returnValue(of({ 'ACTIONS.CREATE.LABEL': 'Create' })) spyOn(component, 'onNewProduct') component.ngOnInit() @@ -104,7 +104,7 @@ describe('ProductSearchComponent', () => { }) it('should call loadProducts onSearch', () => { - translateServiceSpy.get.and.returnValue(of({ 'ACTIONS.CREATE.PRODUCT': 'Create' })) + translateServiceSpy.get.and.returnValue(of({ 'ACTIONS.CREATE.LABEL': 'Create' })) spyOn(component, 'loadProducts') component.onSearch()