-
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 order templates widget on MyAccount overview page (#502)
- Loading branch information
Showing
20 changed files
with
245 additions
and
50 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
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
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
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
38 changes: 38 additions & 0 deletions
38
...ensions/order-templates/shared/order-template-widget/order-template-widget.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,38 @@ | ||
<ish-info-box | ||
heading="account.ordertemplates.widget.heading" | ||
class="infobox-wrapper h-100" | ||
cssClass="infobox-color-widget d-flex flex-column" | ||
> | ||
<div class="loading-container"> | ||
<div *ngIf="!(loading$ | async); else loading" class="pb-2"> | ||
<ng-container *ngIf="orderTemplates$ | async as orderTemplates; else emptyList"> | ||
<ng-container *ngIf="orderTemplates.length; else emptyList"> | ||
<div *ngFor="let orderTemplate of orderTemplates" class="mb-2"> | ||
{{ orderTemplate.title }} | ||
<a *ngIf="orderTemplate.items?.length" class="align-top float-right"> | ||
<ish-product-add-to-basket | ||
displayType="icon" | ||
[product]="dummyProduct" | ||
class="p-0 mb-0" | ||
(productToBasket)="addTemplateToBasket(orderTemplate)" | ||
></ish-product-add-to-basket> | ||
</a> | ||
</div> | ||
</ng-container> | ||
</ng-container> | ||
<ng-template #emptyList> | ||
{{ 'account.order_template.list.no_templates.text' | translate }} | ||
</ng-template> | ||
</div> | ||
</div> | ||
|
||
<div class="mt-auto"> | ||
<a routerLink="/account/order-templates" data-testing-id="order-templates-list-link"> | ||
{{ 'account.ordertemplates.widget.view_all.link' | translate }} | ||
</a> | ||
</div> | ||
</ish-info-box> | ||
|
||
<ng-template #loading> | ||
<ish-loading></ish-loading> | ||
</ng-template> |
83 changes: 83 additions & 0 deletions
83
...ions/order-templates/shared/order-template-widget/order-template-widget.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,83 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { TranslateModule } from '@ngx-translate/core'; | ||
import { MockComponent } from 'ng-mocks'; | ||
import { of } from 'rxjs'; | ||
import { anything, capture, instance, mock, verify, when } from 'ts-mockito'; | ||
|
||
import { InfoBoxComponent } from 'ish-shared/components/common/info-box/info-box.component'; | ||
import { LoadingComponent } from 'ish-shared/components/common/loading/loading.component'; | ||
import { ProductAddToBasketComponent } from 'ish-shared/components/product/product-add-to-basket/product-add-to-basket.component'; | ||
|
||
import { OrderTemplatesFacade } from '../../facades/order-templates.facade'; | ||
import { OrderTemplate } from '../../models/order-template/order-template.model'; | ||
|
||
import { OrderTemplateWidgetComponent } from './order-template-widget.component'; | ||
|
||
describe('Order Template Widget Component', () => { | ||
let component: OrderTemplateWidgetComponent; | ||
let fixture: ComponentFixture<OrderTemplateWidgetComponent>; | ||
let element: HTMLElement; | ||
let orderTemplatesFacade: OrderTemplatesFacade; | ||
|
||
const orderTemplates = [ | ||
{ id: '1', title: 'order template' }, | ||
{ id: '2', title: 'order template 2' }, | ||
] as OrderTemplate[]; | ||
|
||
beforeEach(async () => { | ||
orderTemplatesFacade = mock(OrderTemplatesFacade); | ||
when(orderTemplatesFacade.orderTemplates$).thenReturn(of(orderTemplates)); | ||
when(orderTemplatesFacade.addOrderTemplateToBasket(anything())).thenReturn(); | ||
await TestBed.configureTestingModule({ | ||
imports: [TranslateModule.forRoot()], | ||
declarations: [ | ||
MockComponent(InfoBoxComponent), | ||
MockComponent(LoadingComponent), | ||
MockComponent(ProductAddToBasketComponent), | ||
OrderTemplateWidgetComponent, | ||
], | ||
providers: [{ provide: OrderTemplatesFacade, useFactory: () => instance(orderTemplatesFacade) }], | ||
}).compileComponents(); | ||
}); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(OrderTemplateWidgetComponent); | ||
component = fixture.componentInstance; | ||
element = fixture.nativeElement; | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(component).toBeTruthy(); | ||
expect(element).toBeTruthy(); | ||
expect(() => fixture.detectChanges()).not.toThrow(); | ||
}); | ||
|
||
it('should render loading component if order templates are loading', () => { | ||
when(orderTemplatesFacade.orderTemplateLoading$).thenReturn(of(true)); | ||
fixture.detectChanges(); | ||
expect(element.querySelector('ish-loading')).toBeTruthy(); | ||
}); | ||
|
||
it('should render order template list after creation', () => { | ||
fixture.detectChanges(); | ||
expect(element.querySelector('.loading-container').textContent.trim()).toMatchInlineSnapshot( | ||
`"order template order template 2"` | ||
); | ||
}); | ||
|
||
it('should trigger add product to basket with right order template', () => { | ||
expect(() => fixture.detectChanges()).not.toThrow(); | ||
|
||
component.addTemplateToBasket(orderTemplates[1]); | ||
|
||
verify(orderTemplatesFacade.addOrderTemplateToBasket(anything())).once(); | ||
expect(capture(orderTemplatesFacade.addOrderTemplateToBasket).last()).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
"id": "2", | ||
"title": "order template 2", | ||
}, | ||
] | ||
`); | ||
}); | ||
}); |
36 changes: 36 additions & 0 deletions
36
...xtensions/order-templates/shared/order-template-widget/order-template-widget.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,36 @@ | ||
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core'; | ||
import { Observable } from 'rxjs'; | ||
import { map } from 'rxjs/operators'; | ||
|
||
import { GenerateLazyComponent } from 'ish-core/utils/module-loader/generate-lazy-component.decorator'; | ||
import { whenTruthy } from 'ish-core/utils/operators'; | ||
|
||
import { OrderTemplatesFacade } from '../../facades/order-templates.facade'; | ||
import { OrderTemplate } from '../../models/order-template/order-template.model'; | ||
|
||
@Component({ | ||
selector: 'ish-order-template-widget', | ||
templateUrl: './order-template-widget.component.html', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
@GenerateLazyComponent() | ||
export class OrderTemplateWidgetComponent implements OnInit { | ||
loading$: Observable<boolean>; | ||
orderTemplates$: Observable<OrderTemplate[]>; | ||
|
||
dummyProduct = { sku: 'dummy', available: true }; | ||
|
||
constructor(private facade: OrderTemplatesFacade) {} | ||
|
||
ngOnInit() { | ||
this.loading$ = this.facade.orderTemplateLoading$; | ||
this.orderTemplates$ = this.facade.orderTemplates$.pipe( | ||
whenTruthy(), | ||
map(orderTemplates => orderTemplates.slice(0, 3)) | ||
); | ||
} | ||
|
||
addTemplateToBasket(orderTemplate: OrderTemplate) { | ||
this.facade.addOrderTemplateToBasket(orderTemplate); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/app/extensions/wishlists/shared/wishlist-widget/wishlist-widget.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
Oops, something went wrong.