From 0defe75adb87538b48f54f43e7f535e9aba51b1d Mon Sep 17 00:00:00 2001 From: ncoronel Date: Fri, 14 Aug 2026 09:26:43 -0300 Subject: [PATCH] feat(variant-selector): implement manual selection when autoSelectFirst is disabled --- .../product-list.component.spec.ts | 12 +++++ .../product-ticket-selector.component.html | 7 +-- .../variant-selector.component.html | 7 ++- .../variant-selector.component.spec.ts | 35 ++++++++++++ .../variant-selector.component.ts | 54 ++++++++++++++++--- 5 files changed, 101 insertions(+), 14 deletions(-) diff --git a/src/app/shared/components/product-list/product-list.component.spec.ts b/src/app/shared/components/product-list/product-list.component.spec.ts index 02db057..361f66c 100644 --- a/src/app/shared/components/product-list/product-list.component.spec.ts +++ b/src/app/shared/components/product-list/product-list.component.spec.ts @@ -258,6 +258,15 @@ describe('ProductListComponent', () => { expect(element.querySelector('.product-list--single')).not.toBeNull(); expect(element.querySelectorAll('app-product-ticket-selector')).toHaveLength(1); expect(element.querySelectorAll('.variant-selector__select')).toHaveLength(4); + expect( + (element.querySelector('.ticket-selector__actions .btn-primary') as HTMLButtonElement) + .disabled, + ).toBe(true); + + const ticketSelector = fixture.debugElement.query(By.directive(ProductTicketSelectorComponent)) + .componentInstance as ProductTicketSelectorComponent; + ticketSelector['updateRow'](1, 401); + fixture.detectChanges(); (element.querySelector('.ticket-selector__add-row-button') as HTMLButtonElement).click(); fixture.detectChanges(); @@ -265,6 +274,9 @@ describe('ProductListComponent', () => { expect(element.querySelectorAll('.ticket-selector__row')).toHaveLength(2); expect(element.querySelectorAll('.variant-selector__select')).toHaveLength(8); + ticketSelector['updateRow'](2, 402); + fixture.detectChanges(); + (element.querySelector('.ticket-selector__actions .btn-primary') as HTMLButtonElement).click(); expect(buySpy).toHaveBeenCalledWith({ diff --git a/src/app/shared/components/product-ticket-selector/product-ticket-selector.component.html b/src/app/shared/components/product-ticket-selector/product-ticket-selector.component.html index b16d9ae..6a0fb27 100644 --- a/src/app/shared/components/product-ticket-selector/product-ticket-selector.component.html +++ b/src/app/shared/components/product-ticket-selector/product-ticket-selector.component.html @@ -26,6 +26,7 @@ class="ticket-selector__fields" [variants]="variantsForRow(row.id)" [disabled]="disabled()" + [autoSelectFirst]="false" [selectedVariant]="row.variantId" (selectedVariantChange)="updateRow(row.id, $event)" /> @@ -55,11 +56,7 @@
- + Comprar
diff --git a/src/app/shared/components/variant-selector/variant-selector.component.html b/src/app/shared/components/variant-selector/variant-selector.component.html index bb068dc..102491f 100644 --- a/src/app/shared/components/variant-selector/variant-selector.component.html +++ b/src/app/shared/components/variant-selector/variant-selector.component.html @@ -4,11 +4,14 @@