-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for CMS component "Product List (Filter)" (#673)
- Loading branch information
Showing
6 changed files
with
201 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/app/shared/cms/components/cms-product-list-filter/cms-product-list-filter.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<ng-container *ngIf="productSKUs$ | async as productSKUs"> | ||
<div *ngIf="productSKUs?.length" class="product-list-container" [ngClass]="pagelet.stringParam('CSSClass')"> | ||
<h2 *ngIf="pagelet.stringParam('Title')">{{ pagelet.stringParam('Title') }}</h2> | ||
<ish-products-list | ||
[productSKUs]="productSKUs" | ||
[listStyle]="pagelet.stringParam('ListStyle')" | ||
[slideItems]="pagelet.numberParam('SlideItems')" | ||
[listItemStyle]="pagelet.stringParam('ListItemStyle')" | ||
[listItemCSSClass]="pagelet.stringParam('ListItemCSSClass')" | ||
> | ||
</ish-products-list> | ||
</div> | ||
</ng-container> |
99 changes: 99 additions & 0 deletions
99
...p/shared/cms/components/cms-product-list-filter/cms-product-list-filter.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { MockComponent } from 'ng-mocks'; | ||
import { of } from 'rxjs'; | ||
import { anyNumber, instance, mock, when } from 'ts-mockito'; | ||
|
||
import { CMSFacade } from 'ish-core/facades/cms.facade'; | ||
import { ShoppingFacade } from 'ish-core/facades/shopping.facade'; | ||
import { ContentPagelet } from 'ish-core/models/content-pagelet/content-pagelet.model'; | ||
import { createContentPageletView } from 'ish-core/models/content-view/content-view.model'; | ||
import { ProductsListComponent } from 'ish-shared/components/product/products-list/products-list.component'; | ||
|
||
import { CMSProductListFilterComponent } from './cms-product-list-filter.component'; | ||
|
||
describe('Cms Product List Filter Component', () => { | ||
let component: CMSProductListFilterComponent; | ||
let fixture: ComponentFixture<CMSProductListFilterComponent>; | ||
let element: HTMLElement; | ||
let cmsFacade: CMSFacade; | ||
let shoppingFacade: ShoppingFacade; | ||
let pagelet: ContentPagelet; | ||
|
||
beforeEach(async () => { | ||
cmsFacade = mock(CMSFacade); | ||
shoppingFacade = mock(ShoppingFacade); | ||
|
||
await TestBed.configureTestingModule({ | ||
declarations: [CMSProductListFilterComponent, MockComponent(ProductsListComponent)], | ||
providers: [ | ||
{ provide: CMSFacade, useFactory: () => instance(cmsFacade) }, | ||
{ provide: ShoppingFacade, useFactory: () => instance(shoppingFacade) }, | ||
], | ||
}).compileComponents(); | ||
}); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(CMSProductListFilterComponent); | ||
component = fixture.componentInstance; | ||
element = fixture.nativeElement; | ||
|
||
pagelet = { | ||
definitionQualifiedName: 'fq', | ||
id: 'id', | ||
displayName: 'name', | ||
domain: 'domain', | ||
configurationParameters: { | ||
ListStyle: 'Carousel', | ||
MaxNumberOfProducts: 6, | ||
ShowViewAll: 'true', | ||
SlideItems: 4, | ||
Scope: 'GlobalScope', | ||
Filter: 'top_seller_products', | ||
ListItemStyle: 'tile', | ||
Title: 'Filter Products Pagelet', | ||
CSSClass: 'container', | ||
ListItemCSSClass: 'col-12 col-sm-6 col-lg-3', | ||
}, | ||
}; | ||
component.pagelet = createContentPageletView(pagelet); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(component).toBeTruthy(); | ||
expect(element).toBeTruthy(); | ||
expect(() => fixture.detectChanges()).not.toThrow(); | ||
}); | ||
|
||
describe('getProductSKUs$', () => { | ||
beforeEach(() => { | ||
when( | ||
cmsFacade.parameterProductListFilter$('categoryId', 'top_seller_products', 'GlobalScope', anyNumber()) | ||
).thenReturn(of(['id-1', 'id-2', 'id-3'])); | ||
when(shoppingFacade.selectedCategoryId$).thenReturn(of('categoryId')); | ||
}); | ||
|
||
it('should get all available products for given product filter', done => { | ||
component.pagelet = createContentPageletView({ | ||
...pagelet, | ||
configurationParameters: { | ||
...pagelet.configurationParameters, | ||
MaxNumberOfProducts: 6, | ||
}, | ||
}); | ||
|
||
component.ngOnChanges(); | ||
|
||
component.productSKUs$.subscribe(productSKUs => { | ||
expect(productSKUs).toHaveLength(3); | ||
expect(productSKUs).toMatchInlineSnapshot(` | ||
Array [ | ||
"id-1", | ||
"id-2", | ||
"id-3", | ||
] | ||
`); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
40 changes: 40 additions & 0 deletions
40
src/app/shared/cms/components/cms-product-list-filter/cms-product-list-filter.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { ChangeDetectionStrategy, Component, Input, OnChanges } from '@angular/core'; | ||
import { Observable } from 'rxjs'; | ||
import { switchMap } from 'rxjs/operators'; | ||
|
||
import { CMSFacade } from 'ish-core/facades/cms.facade'; | ||
import { ShoppingFacade } from 'ish-core/facades/shopping.facade'; | ||
import { ContentPageletView } from 'ish-core/models/content-view/content-view.model'; | ||
import { CMSComponent } from 'ish-shared/cms/models/cms-component/cms-component.model'; | ||
|
||
@Component({ | ||
selector: 'ish-cms-product-list-filter', | ||
templateUrl: './cms-product-list-filter.component.html', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class CMSProductListFilterComponent implements CMSComponent, OnChanges { | ||
@Input() pagelet: ContentPageletView; | ||
|
||
productSKUs$: Observable<string[]>; | ||
|
||
constructor(private cmsFacade: CMSFacade, private shoppingFacade: ShoppingFacade) {} | ||
|
||
ngOnChanges() { | ||
if (this.pagelet.hasParam('Filter')) { | ||
this.productSKUs$ = this.getProductSKUs$(); | ||
} | ||
} | ||
|
||
getProductSKUs$(): Observable<string[]> { | ||
return this.shoppingFacade.selectedCategoryId$.pipe( | ||
switchMap(categoryId => | ||
this.cmsFacade.parameterProductListFilter$( | ||
categoryId, | ||
this.pagelet.stringParam('Filter'), | ||
this.pagelet.stringParam('Scope'), | ||
this.pagelet.numberParam('MaxNumberOfProducts') | ||
) | ||
) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters