feat(store-layout): add checkout redirection on buy button click and update button functionality

This commit is contained in:
ncoronel 2026-07-03 11:33:37 -03:00
parent 811f127deb
commit 97a359d65c
3 changed files with 29 additions and 2 deletions

View File

@ -18,8 +18,8 @@
[backgroundColor]="'#ffffff'"
(closed)="isCartOpen.set(false)"
>
<app-button variant="secondary" class="flex-grow-1">Seguir comprando</app-button>
<app-button variant="primary" class="flex-grow-1">Comprar</app-button>
<app-button variant="secondary" class="flex-grow-1" (click)="isCartOpen.set(false)">Seguir comprando</app-button>
<app-button variant="primary" class="flex-grow-1" (click)="onCheckoutClick()">Comprar</app-button>
</app-cart>
</div>
}

View File

@ -146,4 +146,26 @@ describe('StoreLayoutComponent', () => {
expect(router.navigate).not.toHaveBeenCalled();
});
it('redirects to /checkout when cart buy button is clicked', () => {
const router = TestBed.inject(Router);
vi.spyOn(router, 'navigate');
const fixture = TestBed.createComponent(StoreLayoutComponent);
fixture.detectChanges();
fixture.componentInstance.isCartOpen.set(true);
fixture.detectChanges();
const compiled = fixture.nativeElement as HTMLElement;
const buyButton = Array.from(compiled.querySelectorAll('app-button button'))
.find((button) => button.textContent?.trim() === 'Comprar') as HTMLButtonElement | undefined;
expect(buyButton).toBeDefined();
buyButton!.click();
fixture.detectChanges();
expect(router.navigate).toHaveBeenCalledWith(['/checkout']);
expect(fixture.componentInstance.isCartOpen()).toBe(false);
});
});

View File

@ -89,6 +89,11 @@ export class StoreLayoutComponent implements OnInit {
}
}
protected onCheckoutClick(): void {
this.isCartOpen.set(false);
void this.router.navigate(['/checkout']);
}
protected readonly footerSections: StoreFooterSection[] = [
{