feat: update cart service and components to handle productVariantId, improve item removal and addition feedback

This commit is contained in:
2026-07-02 11:00:40 -03:00
parent c9d8265790
commit d31cb65d65
6 changed files with 43 additions and 14 deletions

View File

@@ -59,7 +59,7 @@ describe('ProductDetailPageComponent', () => {
navigate: vi.fn()
};
cartServiceStub = {
addItem: vi.fn().mockReturnValue(of({}))
addItem: vi.fn().mockReturnValue(of({ message: 'Producto agregado al carrito' }))
};
toastServiceStub = {
success: vi.fn(),
@@ -277,6 +277,8 @@ describe('ProductDetailPageComponent', () => {
it('keeps quantity at a minimum of one and increments locally', async () => {
await configureTestingModule();
const fixture = TestBed.createComponent(ProductDetailPageComponent);
fixture.detectChanges();
fixture.componentInstance['selectedVariant'].set({
variant_id: 1,
cantidad_maxima: 10,

View File

@@ -230,8 +230,9 @@ export class ProductDetailPageComponent implements OnInit, OnDestroy {
this.addingToCart.set(true);
this.cartService.addItem(variant.variant_id, this.quantity()).subscribe({
next: () => {
this.toastService.success('Producto agregado al carrito');
next: (res) => {
const msg = res.message || 'Producto agregado al carrito';
this.toastService.success(msg);
this.addingToCart.set(false);
},
error: (err: HttpErrorResponse) => {