feat(product-ticket-selector): simplify row selection handling and improve test coverage for variant selection
This commit is contained in:
@@ -27,7 +27,7 @@
|
|||||||
<select
|
<select
|
||||||
class="form-select variant-selector__select"
|
class="form-select variant-selector__select"
|
||||||
[attr.aria-label]="selector.label"
|
[attr.aria-label]="selector.label"
|
||||||
[disabled]="rowDisabled(row) || !selector.enabled"
|
[disabled]="rowDisabled(row)"
|
||||||
[value]="selectedOptionKey(row, selector.key)"
|
[value]="selectedOptionKey(row, selector.key)"
|
||||||
(change)="onSelectionKeyChange(row.id, selector, $any($event.target).value)"
|
(change)="onSelectionKeyChange(row.id, selector, $any($event.target).value)"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -133,9 +133,15 @@ describe('ProductTicketSelectorComponent', () => {
|
|||||||
fixture.componentRef.setInput('title', 'Entrada');
|
fixture.componentRef.setInput('title', 'Entrada');
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
await fixture.whenStable();
|
await fixture.whenStable();
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
expect(catalogService.getVariantOptions).toHaveBeenCalledTimes(1);
|
expect(catalogService.getVariantOptions).toHaveBeenCalledTimes(1);
|
||||||
expect(catalogService.withoutLoading).toHaveBeenCalled();
|
expect(catalogService.withoutLoading).toHaveBeenCalled();
|
||||||
|
expect(
|
||||||
|
Array.from<HTMLSelectElement>(fixture.nativeElement.querySelectorAll('select')).every(
|
||||||
|
(select) => !select.disabled,
|
||||||
|
),
|
||||||
|
).toBe(true);
|
||||||
|
|
||||||
fixture.componentInstance['onSelectionChange'](1, 'sector', {
|
fixture.componentInstance['onSelectionChange'](1, 'sector', {
|
||||||
value: 'a',
|
value: 'a',
|
||||||
|
|||||||
@@ -206,11 +206,7 @@ export class ProductTicketSelectorComponent {
|
|||||||
const row = this.findRow(rowId);
|
const row = this.findRow(rowId);
|
||||||
if (!row || this.isBusy(row)) return;
|
if (!row || this.isBusy(row)) return;
|
||||||
|
|
||||||
const selectorIndex = row.selectors.findIndex((selector) => selector.key === selectorKey);
|
const selectedValues = { ...row.selectedValues };
|
||||||
const retainedKeys = new Set(row.selectors.slice(0, selectorIndex + 1).map(({ key }) => key));
|
|
||||||
const selectedValues = Object.fromEntries(
|
|
||||||
Object.entries(row.selectedValues).filter(([key]) => retainedKeys.has(key)),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (value === null) delete selectedValues[selectorKey];
|
if (value === null) delete selectedValues[selectorKey];
|
||||||
else selectedValues[selectorKey] = this.normalizeValue(value);
|
else selectedValues[selectorKey] = this.normalizeValue(value);
|
||||||
|
|||||||
Reference in New Issue
Block a user