test: add unit tests for ProductDetailPageComponent including image handling, attributes, and quantity controls

This commit is contained in:
2026-07-01 11:31:41 -03:00
parent ae0690a6f4
commit 2764201ca0

View File

@@ -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;