feat(product): add crate and edit ops in settings
This commit is contained in:
31
src/app/components/product-add/product-add.spec.ts
Normal file
31
src/app/components/product-add/product-add.spec.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { ProductAdd } from './product-add';
|
||||
import { ProductSettings } from '../../services/product-settings';
|
||||
import { provideTranslateService } from '@ngx-translate/core';
|
||||
|
||||
describe('ProductAdd', () => {
|
||||
let component: ProductAdd;
|
||||
let fixture: ComponentFixture<ProductAdd>;
|
||||
|
||||
let productSettings: Partial<ProductSettings>;
|
||||
|
||||
beforeEach(async () => {
|
||||
productSettings = {
|
||||
save: vi.fn(),
|
||||
};
|
||||
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [ProductAdd],
|
||||
providers: [{ provide: ProductSettings, useValue: productSettings }, provideTranslateService()],
|
||||
}).compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(ProductAdd);
|
||||
component = fixture.componentInstance;
|
||||
await fixture.whenStable();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
31
src/app/components/product-add/product-add.ts
Normal file
31
src/app/components/product-add/product-add.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { Component, inject } from '@angular/core';
|
||||
import { SettingsBaseAddEdit } from '../settings-base-add-edit/settings-base-add-edit';
|
||||
import { ProductFormGroup } from '../../pages/settings/products/product-formgroup';
|
||||
import { ActionBtn } from '../action-btn/action-btn';
|
||||
import { TranslatePipe } from '@ngx-translate/core';
|
||||
import { UpperfirstPipe } from '../../pipes/upperfirst-pipe';
|
||||
import { ProductSettings } from '../../services/product-settings';
|
||||
import { Product } from '../../models/Product';
|
||||
|
||||
@Component({
|
||||
selector: 'app-product-add',
|
||||
imports: [ActionBtn, TranslatePipe, UpperfirstPipe],
|
||||
templateUrl: './../settings-base-add-edit/settings-base-add-edit.html',
|
||||
styleUrl: './../settings-base-add-edit/settings-base-add-edit.scss',
|
||||
})
|
||||
export class ProductAdd extends SettingsBaseAddEdit {
|
||||
btnText = 'common.save';
|
||||
title = 'settings.product.new_product';
|
||||
readonly form = new ProductFormGroup();
|
||||
|
||||
private readonly productSettings = inject(ProductSettings);
|
||||
|
||||
async submit() {
|
||||
const product = new Product(
|
||||
this.form.controls.barcode.value,
|
||||
this.form.controls.name.value,
|
||||
'',
|
||||
);
|
||||
await this.productSettings.save(product, this.form.controls.image.value);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user