Skip to content

Commit

Permalink
refactor: use product context access directive in account wishlist fe…
Browse files Browse the repository at this point in the history
…ature
  • Loading branch information
dhhyi committed Mar 8, 2021
1 parent a290cfc commit 782590e
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<ng-container *ngIf="product$ | async as product">
<ng-container *ishProductContextAccess="let product = product">
<div class="row" data-testing-id="wishlist-product">
<div class="col-3 col-md-2 list-item">
<ish-product-image imageType="S" [link]="true"></ish-product-image>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { TranslateModule } from '@ngx-translate/core';
import { MockComponent, MockPipe } from 'ng-mocks';
import { instance, mock } from 'ts-mockito';

import { ProductContextFacade } from 'ish-core/facades/product-context.facade';
import { DatePipe } from 'ish-core/pipes/date.pipe';
import { ProductAddToBasketComponent } from 'ish-shared/components/product/product-add-to-basket/product-add-to-basket.component';
import { ProductBundleDisplayComponent } from 'ish-shared/components/product/product-bundle-display/product-bundle-display.component';
Expand Down Expand Up @@ -43,11 +42,7 @@ describe('Account Wishlist Detail Line Item Component', () => {
],
imports: [TranslateModule.forRoot()],
providers: [{ provide: WishlistsFacade, useFactory: () => instance(mock(WishlistsFacade)) }],
})
.overrideComponent(AccountWishlistDetailLineItemComponent, {
set: { providers: [{ provide: ProductContextFacade, useFactory: () => instance(mock(ProductContextFacade)) }] },
})
.compileComponents();
}).compileComponents();
});

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { ChangeDetectionStrategy, Component, Input, OnChanges, OnInit } from '@angular/core';
import { Observable } from 'rxjs';

import { ProductContextFacade } from 'ish-core/facades/product-context.facade';
import { ProductView } from 'ish-core/models/product-view/product-view.model';
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';

import { WishlistsFacade } from '../../../facades/wishlists.facade';
import { Wishlist, WishlistItem } from '../../../models/wishlist/wishlist.model';
Expand All @@ -14,24 +10,13 @@ import { Wishlist, WishlistItem } from '../../../models/wishlist/wishlist.model'
selector: 'ish-account-wishlist-detail-line-item',
templateUrl: './account-wishlist-detail-line-item.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
providers: [ProductContextFacade],
})
export class AccountWishlistDetailLineItemComponent implements OnChanges, OnInit {
constructor(private wishlistsFacade: WishlistsFacade, private context: ProductContextFacade) {}
export class AccountWishlistDetailLineItemComponent {
constructor(private wishlistsFacade: WishlistsFacade) {}

@Input() wishlistItemData: WishlistItem;
@Input() currentWishlist: Wishlist;

product$: Observable<ProductView>;

ngOnInit() {
this.product$ = this.context.select('product');
}

ngOnChanges() {
this.context.set('sku', () => this.wishlistItemData.sku);
}

moveItemToOtherWishlist(sku: string, wishlistMoveData: { id: string; title: string }) {
if (wishlistMoveData.id) {
this.wishlistsFacade.moveItemToWishlist(this.currentWishlist.id, wishlistMoveData.id, sku);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ <h1>{{ wishlist?.title }}</h1>
<ng-container *ngFor="let item of wishlist.items">
<div class="list-item-row">
<ish-account-wishlist-detail-line-item
ishProductContext
[sku]="item.sku"
[wishlistItemData]="item"
[currentWishlist]="wishlist"
></ish-account-wishlist-detail-line-item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
import { FaIconComponent } from '@fortawesome/angular-fontawesome';
import { NgbPopoverModule } from '@ng-bootstrap/ng-bootstrap';
import { TranslateModule } from '@ngx-translate/core';
import { MockComponent } from 'ng-mocks';
import { MockComponent, MockDirective } from 'ng-mocks';
import { instance, mock } from 'ts-mockito';

import { ProductContextDirective } from 'ish-core/directives/product-context.directive';
import { ErrorMessageComponent } from 'ish-shared/components/common/error-message/error-message.component';
import { LoadingComponent } from 'ish-shared/components/common/loading/loading.component';

Expand All @@ -29,6 +30,7 @@ describe('Account Wishlist Detail Page Component', () => {
MockComponent(FaIconComponent),
MockComponent(LoadingComponent),
MockComponent(WishlistPreferencesDialogComponent),
MockDirective(ProductContextDirective),
],
providers: [{ provide: WishlistsFacade, useFactory: () => instance(mock(WishlistsFacade)) }],
}).compileComponents();
Expand Down

1 comment on commit 782590e

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Azure Demo Servers are available:

Please sign in to comment.