diff --git a/e2e/cypress/integration/specs/extras/order-templates-management.b2b.e2e-spec.ts b/e2e/cypress/integration/specs/extras/order-templates-management.b2b.e2e-spec.ts index b0b1542625d..ed9d1bc7b66 100644 --- a/e2e/cypress/integration/specs/extras/order-templates-management.b2b.e2e-spec.ts +++ b/e2e/cypress/integration/specs/extras/order-templates-management.b2b.e2e-spec.ts @@ -107,7 +107,7 @@ describe('Order Template MyAccount Functionality', () => { at(OrderTemplatesDetailsPage, page => { page.moveProductToOrderTemplate(_.product1, anotherOrderTemplate); cy.wait(500); - page.OrderTemplateTitle.should('equal', anotherOrderTemplate); + page.OrderTemplateTitle.should('contain', anotherOrderTemplate); page.getOrderTemplateItemById(_.product1).should('exist'); OrderTemplatesDetailsPage.navigateToOverviewPage(); }); diff --git a/e2e/cypress/integration/specs/extras/order-templates-shopping.b2b.e2e-spec.ts b/e2e/cypress/integration/specs/extras/order-templates-shopping.b2b.e2e-spec.ts index fa103743521..037ba0b2545 100644 --- a/e2e/cypress/integration/specs/extras/order-templates-shopping.b2b.e2e-spec.ts +++ b/e2e/cypress/integration/specs/extras/order-templates-shopping.b2b.e2e-spec.ts @@ -69,11 +69,12 @@ describe('Order Template Shopping Experience Functionality', () => { it('user adds an order template from order template detail page to cart', () => { at(OrderTemplatesDetailsPage, page => { page.addOrderTemplateToBasket(_.product1, 4); - cy.wait(1500); + cy.wait(2000); page.header.miniCart.goToCart(); }); at(CartPage, page => { page.lineItems.contains(_.product1).should('exist'); + page.lineItems.contains(_.product2).should('exist'); page.lineItems .contains(_.product1) .closest('[data-testing-id="product-list-item"]') @@ -113,7 +114,7 @@ describe('Order Template Shopping Experience Functionality', () => { }); at(OrderTemplatesOverviewPage, page => { page.addOrderTemplateToCart(accountOrderTemplate); - cy.wait(1500); + cy.wait(2000); page.header.miniCart.text.should('contain', '11 items'); page.header.miniCart.goToCart(); }); @@ -129,7 +130,7 @@ describe('Order Template Shopping Experience Functionality', () => { it('user adds only the selected product in order template details', () => { at(CartPage, page => { page.lineItem(0).remove(); - cy.wait(1500); + cy.wait(2000); page.addProductToOrderTemplate(); page.addToOrderTemplate.addProductToOrderTemplateFromPage(accountOrderTemplate, true); }); diff --git a/src/app/extensions/order-templates/models/order-template/order-template.mapper.ts b/src/app/extensions/order-templates/models/order-template/order-template.mapper.ts index e9071ab9579..b910341b210 100644 --- a/src/app/extensions/order-templates/models/order-template/order-template.mapper.ts +++ b/src/app/extensions/order-templates/models/order-template/order-template.mapper.ts @@ -5,7 +5,7 @@ import { OrderTemplate, OrderTemplateItem } from './order-template.model'; @Injectable({ providedIn: 'root' }) export class OrderTemplateMapper { - private static parseIDfromURI(uri: string): string { + private static parseIdFromURI(uri: string): string { const match = /wishlists[^\/]*\/([^\?]*)/.exec(uri); if (match) { return match[1]; @@ -32,13 +32,14 @@ export class OrderTemplateMapper { creationDate: Number(item.creationDate), desiredQuantity: { value: item.desiredQuantity.value, - // TBD: is the unit necessarry? + // TBD: is the unit necessary? // unit: item.desiredQuantity.unit, }, })); } else { items = []; } + return { id: orderTemplateId, title: orderTemplateData.title, @@ -65,7 +66,7 @@ export class OrderTemplateMapper { fromDataToIds(orderTemplateData: OrderTemplateData): OrderTemplate { if (orderTemplateData) { return { - id: OrderTemplateMapper.parseIDfromURI(orderTemplateData.uri), + id: OrderTemplateMapper.parseIdFromURI(orderTemplateData.uri), title: orderTemplateData.title, }; } diff --git a/src/app/extensions/order-templates/pages/account-order-template-detail/account-order-template-detail-line-item/account-order-template-detail-line-item.component.html b/src/app/extensions/order-templates/pages/account-order-template-detail/account-order-template-detail-line-item/account-order-template-detail-line-item.component.html index 6fd90fc2290..317d75e3ef9 100644 --- a/src/app/extensions/order-templates/pages/account-order-template-detail/account-order-template-detail-line-item/account-order-template-detail-line-item.component.html +++ b/src/app/extensions/order-templates/pages/account-order-template-detail/account-order-template-detail-line-item/account-order-template-detail-line-item.component.html @@ -1,9 +1,8 @@
-
+
- - +
@@ -53,7 +52,7 @@
{{ orderTemplateItemData?.creationDate | ishDate: 'shortDate' }}
-
+
diff --git a/src/app/extensions/order-templates/pages/account-order-template-detail/account-order-template-detail-line-item/account-order-template-detail-line-item.component.ts b/src/app/extensions/order-templates/pages/account-order-template-detail/account-order-template-detail-line-item/account-order-template-detail-line-item.component.ts index a0a8a1d8e7e..c5a5e2389e1 100644 --- a/src/app/extensions/order-templates/pages/account-order-template-detail/account-order-template-detail-line-item/account-order-template-detail-line-item.component.ts +++ b/src/app/extensions/order-templates/pages/account-order-template-detail/account-order-template-detail-line-item/account-order-template-detail-line-item.component.ts @@ -45,7 +45,7 @@ export class AccountOrderTemplateDetailLineItemComponent implements OnChanges, O updateQuantities() { this.addToCartForm.valueChanges - .pipe(debounceTime(800), takeUntil(this.destroy$)) + .pipe(debounceTime(500), takeUntil(this.destroy$)) .subscribe(val => this.updateProductQuantity(this.orderTemplateItemData.sku, val.quantity)); } diff --git a/src/app/extensions/order-templates/pages/account-order-template-detail/account-order-template-detail-page.component.html b/src/app/extensions/order-templates/pages/account-order-template-detail/account-order-template-detail-page.component.html index 7f60c28a477..b37546ffff1 100644 --- a/src/app/extensions/order-templates/pages/account-order-template-detail/account-order-template-detail-page.component.html +++ b/src/app/extensions/order-templates/pages/account-order-template-detail/account-order-template-detail-page.component.html @@ -2,14 +2,16 @@ - {{ 'account.order_template.order_template.edit.rename' | translate }} -

{{ orderTemplate?.title }}

+

+ {{ orderTemplate?.title }} + {{ 'account.order_template.order_template.edit.rename' | translate }} +

@@ -40,7 +42,8 @@

{{ orderTemplate?.title }}

diff --git a/src/app/extensions/order-templates/pages/account-order-template-detail/account-order-template-detail-page.component.ts b/src/app/extensions/order-templates/pages/account-order-template-detail/account-order-template-detail-page.component.ts index 8bee6348fa4..15d013f86ad 100644 --- a/src/app/extensions/order-templates/pages/account-order-template-detail/account-order-template-detail-page.component.ts +++ b/src/app/extensions/order-templates/pages/account-order-template-detail/account-order-template-detail-page.component.ts @@ -1,13 +1,13 @@ import { ChangeDetectionStrategy, Component, OnDestroy, OnInit } from '@angular/core'; import { FormArray } from '@angular/forms'; import { Observable, Subject } from 'rxjs'; -import { takeUntil } from 'rxjs/operators'; +import { takeUntil, withLatestFrom } from 'rxjs/operators'; import { ShoppingFacade } from 'ish-core/facades/shopping.facade'; import { HttpError } from 'ish-core/models/http-error/http-error.model'; import { OrderTemplatesFacade } from '../../facades/order-templates.facade'; -import { OrderTemplate } from '../../models/order-template/order-template.model'; +import { OrderTemplate, OrderTemplateItem } from '../../models/order-template/order-template.model'; @Component({ selector: 'ish-account-order-template-detail-page', @@ -20,6 +20,8 @@ export class AccountOrderTemplateDetailPageComponent implements OnInit, OnDestro orderTemplateLoading$: Observable; selectedItemsForm: FormArray; + selectedItems: OrderTemplateItem[]; + dummyProduct = { sku: 'dummy', inStock: true, availability: true }; private destroy$ = new Subject(); @@ -30,6 +32,12 @@ export class AccountOrderTemplateDetailPageComponent implements OnInit, OnDestro this.orderTemplateLoading$ = this.orderTemplatesFacade.orderTemplateLoading$; this.orderTemplateError$ = this.orderTemplatesFacade.orderTemplateError$; this.initForm(); + + this.selectedItemsForm.valueChanges + .pipe(withLatestFrom(this.orderTemplate$), takeUntil(this.destroy$)) + .subscribe(([, orderTemplate]) => { + this.selectedItems = this.filterItems(orderTemplate); + }); } private initForm() { @@ -58,11 +66,15 @@ export class AccountOrderTemplateDetailPageComponent implements OnInit, OnDestro }); } + filterItems(orderTemplate): OrderTemplateItem[] { + return orderTemplate.items.filter(item => + this.selectedItemsForm.value.find(p => p.sku === item.sku && p.productCheckbox === true) + ); + } + addSelectedItemsToCart(orderTemplate: OrderTemplate) { - orderTemplate.items.forEach(item => { - if (this.selectedItemsForm.value.find(p => p.sku === item.sku && p.productCheckbox === true)) { - this.shoppingFacade.addProductToBasket(item.sku, item.desiredQuantity.value); - } + this.filterItems(orderTemplate).forEach(item => { + this.shoppingFacade.addProductToBasket(item.sku, item.desiredQuantity.value); }); } } diff --git a/src/app/extensions/order-templates/pages/account-order-template/account-order-template-list/account-order-template-list.component.html b/src/app/extensions/order-templates/pages/account-order-template/account-order-template-list/account-order-template-list.component.html index 69645608eb8..2ed852f15ce 100644 --- a/src/app/extensions/order-templates/pages/account-order-template/account-order-template-list/account-order-template-list.component.html +++ b/src/app/extensions/order-templates/pages/account-order-template/account-order-template-list/account-order-template-list.component.html @@ -29,7 +29,8 @@ diff --git a/src/app/extensions/order-templates/pages/account-order-template/account-order-template-list/account-order-template-list.component.ts b/src/app/extensions/order-templates/pages/account-order-template/account-order-template-list/account-order-template-list.component.ts index 0ceb952177b..08860069837 100644 --- a/src/app/extensions/order-templates/pages/account-order-template/account-order-template-list/account-order-template-list.component.ts +++ b/src/app/extensions/order-templates/pages/account-order-template/account-order-template-list/account-order-template-list.component.ts @@ -22,6 +22,8 @@ export class AccountOrderTemplateListComponent { */ @Output() deleteOrderTemplate = new EventEmitter(); + dummyProduct = { sku: 'dummy', inStock: true, availability: true }; + constructor(private translate: TranslateService, private productFacade: ShoppingFacade) {} addTemplateToCart(orderTemplateId: string) { @@ -44,7 +46,7 @@ export class AccountOrderTemplateListComponent { /** Determine the heading of the delete modal and opens the modal. */ openDeleteConfirmationDialog(orderTemplate: OrderTemplate, modal: ModalDialogComponent) { this.translate - .get('modal.heading.remove.order.template', { 0: orderTemplate.title }) + .get('account.order_templates.delete_dialog.header', { 0: orderTemplate.title }) .pipe(take(1)) .subscribe(res => (modal.options.titleText = res)); diff --git a/src/app/extensions/order-templates/services/order-template/order-template.service.spec.ts b/src/app/extensions/order-templates/services/order-template/order-template.service.spec.ts index b567fb95c01..ce1d5eb1efd 100644 --- a/src/app/extensions/order-templates/services/order-template/order-template.service.spec.ts +++ b/src/app/extensions/order-templates/services/order-template/order-template.service.spec.ts @@ -49,12 +49,25 @@ describe('Order Template Service', () => { }); }); + it("should get an order template when 'getOrderTemplate' is called", done => { + when(apiServiceMock.get(`customers/-/users/-/wishlists/1234`)).thenReturn(of({ id: '1234' })); + + orderTemplateService.getOrderTemplate('1234').subscribe(() => { + verify(apiServiceMock.get(`customers/-/users/-/wishlists/1234`)).once(); + done(); + }); + }); + it("should create an order template when 'createOrderTemplate' is called", done => { const orderTemplateId = '1234'; const orderTemplateHeader: OrderTemplateHeader = { title: 'order template title' }; when(apiServiceMock.post(`customers/-/users/-/wishlists`, anything())).thenReturn( of({ title: orderTemplateId } as OrderTemplateData) ); + when(apiServiceMock.post(`customers/-/users/-/wishlists`, anything())).thenReturn( + of({ title: orderTemplateId } as OrderTemplateData) + ); + when(apiServiceMock.get(`customers/-/users/-/wishlists/1234`)).thenReturn(of({ id: '1234' })); orderTemplateService.createOrderTemplate(orderTemplateHeader).subscribe(data => { expect(orderTemplateId).toEqual(data.id); diff --git a/src/app/extensions/order-templates/services/order-template/order-template.service.ts b/src/app/extensions/order-templates/services/order-template/order-template.service.ts index 73b263dddf8..5391b2c1359 100644 --- a/src/app/extensions/order-templates/services/order-template/order-template.service.ts +++ b/src/app/extensions/order-templates/services/order-template/order-template.service.ts @@ -32,7 +32,7 @@ export class OrderTemplateService { * @param orderTemplateId The order template id. * @returns The order template. */ - private getOrderTemplate(orderTemplateId): Observable { + getOrderTemplate(orderTemplateId: string): Observable { if (!orderTemplateId) { return throwError('getOrderTemplate() called without orderTemplateId'); } @@ -46,12 +46,10 @@ export class OrderTemplateService { * @param OrderTemplateDetails The order template data. * @returns The created order template. */ - createOrderTemplate(orderTemplatetData: OrderTemplateHeader): Observable { + createOrderTemplate(orderTemplateData: OrderTemplateHeader): Observable { return this.apiService - .post('customers/-/users/-/wishlists', orderTemplatetData) - .pipe( - map((response: OrderTemplateData) => this.orderTemplateMapper.fromData(orderTemplatetData, response.title)) - ); + .post('customers/-/users/-/wishlists', orderTemplateData) + .pipe(concatMap((response: OrderTemplateData) => this.getOrderTemplate(response.title))); } /** diff --git a/src/app/extensions/order-templates/shared/order-templates/select-order-template-modal/select-order-template-modal.component.html b/src/app/extensions/order-templates/shared/order-templates/select-order-template-modal/select-order-template-modal.component.html index fbdd3bf9282..37cc8a64d7c 100644 --- a/src/app/extensions/order-templates/shared/order-templates/select-order-template-modal/select-order-template-modal.component.html +++ b/src/app/extensions/order-templates/shared/order-templates/select-order-template-modal/select-order-template-modal.component.html @@ -51,6 +51,7 @@ id="orderTemplate" /> (); diff --git a/src/app/shared/components/basket/line-item-list/line-item-list.component.html b/src/app/shared/components/basket/line-item-list/line-item-list.component.html index 4c8367b9515..75f62cf3c53 100644 --- a/src/app/shared/components/basket/line-item-list/line-item-list.component.html +++ b/src/app/shared/components/basket/line-item-list/line-item-list.component.html @@ -49,8 +49,7 @@
+