feat(store-layout): add checkout redirection on buy button click and update button functionality
This commit is contained in:
@@ -18,8 +18,8 @@
|
|||||||
[backgroundColor]="'#ffffff'"
|
[backgroundColor]="'#ffffff'"
|
||||||
(closed)="isCartOpen.set(false)"
|
(closed)="isCartOpen.set(false)"
|
||||||
>
|
>
|
||||||
<app-button variant="secondary" class="flex-grow-1">Seguir comprando</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">Comprar</app-button>
|
<app-button variant="primary" class="flex-grow-1" (click)="onCheckoutClick()">Comprar</app-button>
|
||||||
</app-cart>
|
</app-cart>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -146,4 +146,26 @@ describe('StoreLayoutComponent', () => {
|
|||||||
|
|
||||||
expect(router.navigate).not.toHaveBeenCalled();
|
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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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[] = [
|
protected readonly footerSections: StoreFooterSection[] = [
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user