refactor(variants): standardize variant structure and improve variant handling across components

This commit is contained in:
2026-08-12 10:47:09 -03:00
parent b97753f825
commit 0f9d3e79d4
8 changed files with 149 additions and 18 deletions

View File

@@ -33,7 +33,7 @@
[description]="item.descripcion ?? ''"
[price]="price(item)"
[imageUrl]="loadImages() ? (item.image ?? null) : null"
[variants]="variantsFor(item)"
[variants]="item.variants ?? []"
[disabled]="loading()"
(buy)="emitTicketBuy(item, $event)"
/>

View File

@@ -228,7 +228,23 @@ describe('ProductListComponent', () => {
id: 401,
precio: '10000.00',
stock_tecnico: 1,
values: { tipo: 'VIP', sector: 'A', fila: '3', asiento: '12' },
values: {
tipo: { value: 'vip', label: 'VIP' },
sector: { value: 'a', label: 'Sector A' },
fila: { value: '3', label: 'Fila 3' },
asiento: { value: '12', label: 'Asiento 12' },
},
},
{
id: 402,
precio: '12000.00',
stock_tecnico: 1,
values: {
tipo: { value: 'vip', label: 'VIP' },
sector: { value: 'a', label: 'Sector A' },
fila: { value: '3', label: 'Fila 3' },
asiento: { value: '13', label: 'Asiento 13' },
},
},
],
};
@@ -243,13 +259,19 @@ describe('ProductListComponent', () => {
expect(element.querySelectorAll('app-product-ticket-selector')).toHaveLength(1);
expect(element.querySelectorAll('.variant-selector__select')).toHaveLength(4);
(element.querySelector('.ticket-selector__add-row-button') as HTMLButtonElement).click();
fixture.detectChanges();
expect(element.querySelectorAll('.ticket-selector__row')).toHaveLength(2);
expect(element.querySelectorAll('.variant-selector__select')).toHaveLength(8);
(element.querySelector('.ticket-selector__actions .btn-primary') as HTMLButtonElement).click();
expect(buySpy).toHaveBeenCalledWith({
product: ticket,
quantity: 1,
quantity: 2,
variant: 401,
variantIds: [401],
variantIds: [401, 402],
directPurchase: true,
});
});

View File

@@ -106,16 +106,6 @@ export class ProductListComponent {
return Number.isFinite(price) ? price : 0;
}
protected variantsFor(item: ProductListItem): RowVariant[] {
return (item.variants ?? []).map((variant) => ({
value: variant.id,
descripcion: variant.descripcion,
precio: variant.precio,
stock_tecnico: variant.stock_tecnico,
values: variant.values,
}));
}
protected emitRowCart(
product: ProductListItem,
event: { quantity: number; variant: unknown },

View File

@@ -32,7 +32,7 @@
&__price {
flex: 0 0 auto;
font-size: 16px;
font-size: 25px;
font-weight: 400;
strong {

View File

@@ -98,7 +98,7 @@ export class ProductTicketSelectorComponent {
);
return this.selectableVariants().filter(
(variant) => !selectedByOtherRows.has(variant.value as number),
(variant) => !selectedByOtherRows.has(variant.id as number),
);
}