Skip to content

Commit

Permalink
fix: display a product unavailable image on product detail page if th…
Browse files Browse the repository at this point in the history
…ere are no product images (#653)
  • Loading branch information
SGrueber authored Apr 16, 2021
1 parent 6f0200d commit 0d1be10
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ describe('Product Images Component', () => {
let component: ProductImagesComponent;
let fixture: ComponentFixture<ProductImagesComponent>;
let element: HTMLElement;
let context: ProductContextFacade;

beforeEach(async () => {
const context = mock(ProductContextFacade);
context = mock(ProductContextFacade);
when(context.select('product')).thenReturn(
of({
sku: 'sku',
Expand Down Expand Up @@ -117,4 +118,17 @@ describe('Product Images Component', () => {
fixture.detectChanges();
expect(element.getElementsByTagName('ish-product-image')).toBeTruthy();
});

it('should render product image unavailable on component', () => {
when(context.select('product')).thenReturn(
of({
sku: 'sku',
name: 'Lenco',
images: [],
} as ProductView)
);

fixture.detectChanges();
expect(element.getElementsByTagName('ish-product-image')).toHaveLength(2);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ export class ProductImagesComponent implements OnInit {
this.product$ = this.context.select('product');
}

getImageViewIDs$(imageType: string) {
return this.product$.pipe(map(p => ProductHelper.getImageViewIDs(p, imageType)));
getImageViewIDs$(imageType: string): Observable<string[]> {
return this.product$.pipe(
map(p => ProductHelper.getImageViewIDs(p, imageType)),
map(ids => (ids?.length ? ids : ['default']))
);
}

/**
Expand Down

0 comments on commit 0d1be10

Please sign in to comment.