From 2764201ca039c9f8b497406890cf27640dd4d00d Mon Sep 17 00:00:00 2001 From: ncoronel Date: Wed, 1 Jul 2026 11:31:41 -0300 Subject: [PATCH] test: add unit tests for ProductDetailPageComponent including image handling, attributes, and quantity controls --- .../product-detail-page.component.spec.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/app/features/store/pages/product-detail-page/product-detail-page.component.spec.ts b/src/app/features/store/pages/product-detail-page/product-detail-page.component.spec.ts index 548085a..c37fcc7 100644 --- a/src/app/features/store/pages/product-detail-page/product-detail-page.component.spec.ts +++ b/src/app/features/store/pages/product-detail-page/product-detail-page.component.spec.ts @@ -229,17 +229,17 @@ describe('ProductDetailPageComponent', () => { fixture.detectChanges(); const element = fixture.nativeElement as HTMLElement; - const swatches = element.querySelectorAll('.product-detail__attribute-swatch'); - const textOptions = element.querySelectorAll('.product-detail__attribute-text-option'); - const labels = Array.from(element.querySelectorAll('.product-detail__attribute-label')).map((label) => + const swatches = element.querySelectorAll('.attribute-selector__swatch'); + const textOptions = element.querySelectorAll('.attribute-selector__text-option'); + const labels = Array.from(element.querySelectorAll('.attribute-selector__label')).map((label) => label.textContent?.trim() ); expect(labels).toEqual(['Color:', 'Material:']); expect(swatches).toHaveLength(2); expect(textOptions).toHaveLength(2); - expect(swatches[0].classList.contains('product-detail__attribute-swatch--selected')).toBe(true); - expect(textOptions[1].classList.contains('product-detail__attribute-text-option--selected')).toBe(true); + expect(swatches[0].classList.contains('attribute-selector__swatch--selected')).toBe(true); + expect(textOptions[1].classList.contains('attribute-selector__text-option--selected')).toBe(true); expect((swatches[0] as HTMLElement).style.backgroundColor).not.toBe(''); }); @@ -257,6 +257,11 @@ describe('ProductDetailPageComponent', () => { it('keeps quantity at a minimum of one and increments locally', async () => { await configureTestingModule(); const fixture = TestBed.createComponent(ProductDetailPageComponent); + fixture.componentInstance['selectedVariant'].set({ + variant_id: 1, + stock: 10, + attributes: {} + }); fixture.detectChanges(); const element = fixture.nativeElement as HTMLElement;