feat(cart): implement add to cart functionality and display empty cart message
This commit is contained in:
@@ -24,6 +24,44 @@ describe('CartComponent', () => {
|
||||
TestBed.resetTestingModule();
|
||||
});
|
||||
|
||||
it('shows an empty cart message when there are no items', async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [CartComponent],
|
||||
providers: [
|
||||
{
|
||||
provide: CartService,
|
||||
useValue: {
|
||||
cart: signal(null).asReadonly(),
|
||||
updateItemQuantity: vi.fn(),
|
||||
removeItem: vi.fn(),
|
||||
},
|
||||
},
|
||||
{
|
||||
provide: ModalService,
|
||||
useValue: {},
|
||||
},
|
||||
{
|
||||
provide: ToastService,
|
||||
useValue: {
|
||||
success: vi.fn(),
|
||||
info: vi.fn(),
|
||||
danger: vi.fn(),
|
||||
},
|
||||
},
|
||||
],
|
||||
}).compileComponents();
|
||||
|
||||
const fixture = TestBed.createComponent(CartComponent);
|
||||
fixture.detectChanges();
|
||||
|
||||
const emptyMessage = fixture.debugElement.query(By.css('.cart-empty-message'));
|
||||
|
||||
expect(emptyMessage).not.toBeNull();
|
||||
expect(emptyMessage.nativeElement.textContent.trim()).toBe('El carrito está vacío');
|
||||
expect(fixture.debugElement.query(By.css('app-cart-item'))).toBeNull();
|
||||
expect(fixture.debugElement.query(By.css('.cart-footer'))).toBeNull();
|
||||
});
|
||||
|
||||
it('opens a confirm delete modal before removing an item', async () => {
|
||||
const removeItem = vi.fn().mockReturnValue(of({ message: 'Producto eliminado.' }));
|
||||
const openConfirmDelete = vi.fn().mockReturnValue(of(true));
|
||||
@@ -71,6 +109,8 @@ describe('CartComponent', () => {
|
||||
]);
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(fixture.debugElement.query(By.css('.cart-item-media'))).toBeNull();
|
||||
|
||||
fixture.debugElement.query(By.css('app-cart-item')).triggerEventHandler('remove');
|
||||
|
||||
expect(openConfirmDelete).toHaveBeenCalledWith({
|
||||
|
||||
Reference in New Issue
Block a user