test: add unit tests for ProductDetailPageComponent including image handling, attributes, and quantity controls
This commit is contained in:
parent
ae0690a6f4
commit
2764201ca0
|
|
@ -229,17 +229,17 @@ describe('ProductDetailPageComponent', () => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
const element = fixture.nativeElement as HTMLElement;
|
const element = fixture.nativeElement as HTMLElement;
|
||||||
const swatches = element.querySelectorAll('.product-detail__attribute-swatch');
|
const swatches = element.querySelectorAll('.attribute-selector__swatch');
|
||||||
const textOptions = element.querySelectorAll('.product-detail__attribute-text-option');
|
const textOptions = element.querySelectorAll('.attribute-selector__text-option');
|
||||||
const labels = Array.from(element.querySelectorAll('.product-detail__attribute-label')).map((label) =>
|
const labels = Array.from(element.querySelectorAll('.attribute-selector__label')).map((label) =>
|
||||||
label.textContent?.trim()
|
label.textContent?.trim()
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(labels).toEqual(['Color:', 'Material:']);
|
expect(labels).toEqual(['Color:', 'Material:']);
|
||||||
expect(swatches).toHaveLength(2);
|
expect(swatches).toHaveLength(2);
|
||||||
expect(textOptions).toHaveLength(2);
|
expect(textOptions).toHaveLength(2);
|
||||||
expect(swatches[0].classList.contains('product-detail__attribute-swatch--selected')).toBe(true);
|
expect(swatches[0].classList.contains('attribute-selector__swatch--selected')).toBe(true);
|
||||||
expect(textOptions[1].classList.contains('product-detail__attribute-text-option--selected')).toBe(true);
|
expect(textOptions[1].classList.contains('attribute-selector__text-option--selected')).toBe(true);
|
||||||
expect((swatches[0] as HTMLElement).style.backgroundColor).not.toBe('');
|
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 () => {
|
it('keeps quantity at a minimum of one and increments locally', async () => {
|
||||||
await configureTestingModule();
|
await configureTestingModule();
|
||||||
const fixture = TestBed.createComponent(ProductDetailPageComponent);
|
const fixture = TestBed.createComponent(ProductDetailPageComponent);
|
||||||
|
fixture.componentInstance['selectedVariant'].set({
|
||||||
|
variant_id: 1,
|
||||||
|
stock: 10,
|
||||||
|
attributes: {}
|
||||||
|
});
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
const element = fixture.nativeElement as HTMLElement;
|
const element = fixture.nativeElement as HTMLElement;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue