Skip to content

Commit

Permalink
Merge branch 'develop-6.3.x' into epic/b2b-commerce-quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristophHi committed Jul 12, 2023
2 parents 601de19 + a2c3715 commit 15d23f9
Show file tree
Hide file tree
Showing 16 changed files with 180 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ <h2 class="cx-checkout-title d-none d-lg-block d-xl-block">
<cx-address-form
[showTitleCode]="true"
[setAsDefaultField]="!isGuestCheckout"
[addressData]="selectedAddress"
cancelBtnLabel="{{ backBtnText | cxTranslate }}"
(backToAddress)="hideNewAddressForm(true)"
(submitAddress)="addAddress($event)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
import {
ChangeDetectionStrategy,
Component,
OnInit,
Optional,
} from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { ActiveCartFacade } from '@spartacus/cart/base/root';
import {
Expand All @@ -29,6 +34,7 @@ import {
tap,
} from 'rxjs/operators';
import { CheckoutStepService } from '../services/checkout-step.service';
import { CheckoutConfigService } from '../services';

export interface CardWithAddress {
card: Card;
Expand All @@ -49,6 +55,8 @@ export class CheckoutDeliveryAddressComponent implements OnInit {
addressFormOpened = false;
doneAutoSelect = false;

selectedAddress?: Address;

get isGuestCheckout(): boolean {
return !!getLastValueSync(this.activeCartFacade.isGuestCart());
}
Expand All @@ -65,6 +73,32 @@ export class CheckoutDeliveryAddressComponent implements OnInit {
);
}

// TODO(CXSPA-): make checkoutConfigService a required dependency
constructor(
userAddressService: UserAddressService,
checkoutDeliveryAddressFacade: CheckoutDeliveryAddressFacade,
activatedRoute: ActivatedRoute,
translationService: TranslationService,
activeCartFacade: ActiveCartFacade,
checkoutStepService: CheckoutStepService,
checkoutDeliveryModesFacade: CheckoutDeliveryModesFacade,
globalMessageService: GlobalMessageService,
// eslint-disable-next-line @typescript-eslint/unified-signatures
checkoutConfigService: CheckoutConfigService
);
/**
* @deprecated since 6.2
*/
constructor(
userAddressService: UserAddressService,
checkoutDeliveryAddressFacade: CheckoutDeliveryAddressFacade,
activatedRoute: ActivatedRoute,
translationService: TranslationService,
activeCartFacade: ActiveCartFacade,
checkoutStepService: CheckoutStepService,
checkoutDeliveryModesFacade: CheckoutDeliveryModesFacade,
globalMessageService: GlobalMessageService
);
constructor(
protected userAddressService: UserAddressService,
protected checkoutDeliveryAddressFacade: CheckoutDeliveryAddressFacade,
Expand All @@ -73,7 +107,8 @@ export class CheckoutDeliveryAddressComponent implements OnInit {
protected activeCartFacade: ActiveCartFacade,
protected checkoutStepService: CheckoutStepService,
protected checkoutDeliveryModesFacade: CheckoutDeliveryModesFacade,
protected globalMessageService: GlobalMessageService
protected globalMessageService: GlobalMessageService,
@Optional() protected checkoutConfigService?: CheckoutConfigService
) {}

ngOnInit(): void {
Expand Down Expand Up @@ -137,6 +172,14 @@ export class CheckoutDeliveryAddressComponent implements OnInit {
}

addAddress(address: Address | undefined): void {
if (
!address &&
this.shouldUseAddressSavedInCart() &&
this.selectedAddress
) {
this.next();
}

if (!address) {
return;
}
Expand Down Expand Up @@ -242,6 +285,8 @@ export class CheckoutDeliveryAddressComponent implements OnInit {
this.setAddress(selected);
}
this.doneAutoSelect = true;
} else if (selected && this.shouldUseAddressSavedInCart()) {
this.selectedAddress = selected;
}
}

Expand Down Expand Up @@ -296,4 +341,8 @@ export class CheckoutDeliveryAddressComponent implements OnInit {
protected onError(): void {
this.busy$.next(false);
}

protected shouldUseAddressSavedInCart(): boolean {
return !!this.checkoutConfigService?.shouldUseAddressSavedInCart();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ export class CheckoutConfigService {
: this.findMatchingDeliveryMode(deliveryModes, index + 1);
}

shouldUseAddressSavedInCart(): boolean {
return !!this.checkoutConfig?.checkout?.guestUseSavedAddress;
}

getPreferredDeliveryMode(deliveryModes: DeliveryMode[]): string | undefined {
deliveryModes.sort(this.compareDeliveryCost);
return this.findMatchingDeliveryMode(deliveryModes);
Expand Down
4 changes: 4 additions & 0 deletions feature-libs/checkout/base/root/config/checkout-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ export abstract class CheckoutConfig {
* Allow for guest checkout.
*/
guest?: boolean;
/**
* Use delivery address saved in cart for pre-filling delivery address form.
*/
guestUseSavedAddress?: boolean;
};
}

Expand Down
21 changes: 21 additions & 0 deletions integration-libs/cdc/root/service/cdc-js.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { TestBed } from '@angular/core/testing';
import {
AuthService,
BaseSite,
BaseSiteService,
GlobalMessageService,
GlobalMessageType,
Expand Down Expand Up @@ -37,6 +38,9 @@ class BaseSiteServiceStub implements Partial<BaseSiteService> {
getActive(): Observable<string> {
return of('electronics-spa');
}
get(_siteUid?: string): Observable<BaseSite | undefined> {
return of({ uid: 'electronics-spa', channel: 'B2C' });
}
}
class LanguageServiceStub implements Partial<LanguageService> {
getActive(): Observable<string> {
Expand Down Expand Up @@ -441,6 +445,7 @@ describe('CdcJsService', () => {

describe('loginUserWithoutScreenSet', () => {
it('should login user without screenset', (done) => {
expect(service['getCurrentBaseSite']()).toBe('electronics-spa');
spyOn(service['gigyaSDK'].accounts, 'login').and.callFake(
(options: { callback: Function }) => {
options.callback({ status: 'OK' });
Expand Down Expand Up @@ -696,6 +701,22 @@ describe('CdcJsService', () => {
});
});

describe('getCurrentBaseSiteChannel', () => {
it('should return the channel value of the base site - B2C', () => {
spyOn(baseSiteService, 'get').and.returnValue(
of({ uid: 'electronics-spa', channel: 'B2C' })
);
expect(service['getCurrentBaseSiteChannel']()).toBe('B2C');
});

it('should return the channel of the base site - B2B', () => {
spyOn(baseSiteService, 'get').and.returnValue(
of({ uid: 'powertools-spa', channel: 'B2B' })
);
expect(service['getCurrentBaseSiteChannel']()).toBe('B2B');
});
});

describe('updateProfileWithoutScreenSet', () => {
it('should not call accounts.setAccountInfo', (done) => {
spyOn(service['gigyaSDK'].accounts, 'setAccountInfo').and.callFake(
Expand Down
17 changes: 16 additions & 1 deletion integration-libs/cdc/root/service/cdc-js.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,18 @@ export class CdcJsService implements OnDestroy {
context?: any
): Observable<{ status: string }> {
const missingConsentErrorCode = 206001;
let ignoreInterruptions = false;
const channel = this.getCurrentBaseSiteChannel();
if (channel && channel === 'B2C') {
ignoreInterruptions = true;
}
return this.getSessionExpirationValue().pipe(
switchMap((sessionExpiration) => {
return this.invokeAPI('accounts.login', {
loginID: email,
password: password,
include: 'missing-required-fields',
ignoreInterruptions: true,
ignoreInterruptions: ignoreInterruptions,
...(context && { context: context }),
sessionExpiry: sessionExpiration,
}).pipe(
Expand Down Expand Up @@ -366,6 +371,16 @@ export class CdcJsService implements OnDestroy {
return baseSite;
}

private getCurrentBaseSiteChannel(): string {
let channel: string = '';
const baseSiteUid: string = this.getCurrentBaseSite();
this.baseSiteService
.get(baseSiteUid)
.pipe(take(1))
.subscribe((data) => (channel = data?.channel ?? ''));
return channel;
}

/**
* Trigger CDC forgot password using CDC APIs.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import * as cart from '../../../helpers/cart';
import * as configuration from '../../../helpers/product-configurator';
import * as textfieldConfiguration from '../../../helpers/textfield-configuration';
import * as common from '../../../helpers/common';

const electronicsShop = 'electronics-spa';
const testProduct = '1934793';
Expand Down Expand Up @@ -46,8 +47,8 @@ context('Textfield Configuration', () => {
electronicsShop,
testProduct
);
textfieldConfiguration.clickOnAddToCartBtnOnPD();
textfieldConfiguration.clickOnViewCartBtnOnPD();
common.clickOnAddToCartBtnOnPD();
common.clickOnViewCartBtnOnPD();
cart.verifyCartNotEmpty();
textfieldConfiguration.clickOnEditConfigurationLink(0);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import * as configurationCartVc from '../../../helpers/product-configurator-cart
import * as configurationOverview from '../../../helpers/product-configurator-overview';
import * as configurationOverviewVc from '../../../helpers/product-configurator-overview-vc';
import * as configurationVc from '../../../helpers/product-configurator-vc';
import * as common from '../../../helpers/common';

const electronicsShop = 'electronics-spa';
const testProductMultiLevel = 'CONF_HOME_THEATER_ML';
Expand Down Expand Up @@ -98,8 +99,8 @@ context('Product Configuration', () => {
it('should be able to navigate from the cart after adding product directly to the cart', () => {
clickAllowAllFromBanner();
configuration.searchForProduct(testProductMultiLevel);
configuration.clickOnAddToCartBtnOnPD();
configuration.clickOnViewCartBtnOnPD();
common.clickOnAddToCartBtnOnPD();
common.clickOnViewCartBtnOnPD();
cart.verifyCartNotEmpty();
configurationCart.clickOnEditConfigurationLink(0);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as configuration from '../../../helpers/product-configurator';
import { clickAllowAllFromBanner } from '../../../helpers/anonymous-consents';
import * as configurationOverviewVc from '../../../helpers/product-configurator-overview-vc';
import * as configurationVc from '../../../helpers/product-configurator-vc';
import * as common from '../../../helpers/common';

const electronicsShop = 'electronics-spa';
const testProduct = 'CONF_CAMERA_SL';
Expand Down Expand Up @@ -96,7 +97,7 @@ context('Product Configuration', () => {

it('should be able to navigate from the product details page', () => {
clickAllowAllFromBanner();
configurationVc.goToPDPage(electronicsShop, testProduct);
common.goToPDPage(electronicsShop, testProduct);
configurationVc.clickOnConfigureBtnInCatalog(testProduct);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import * as configuration from '../../../helpers/product-configurator';
import * as configurationCpq from '../../../helpers/product-configurator-cpq';
import * as configurationOverview from '../../../helpers/product-configurator-overview';
import * as configurationOverviewCpq from '../../../helpers/product-configurator-overview-cpq';
import * as configurationCart from '../../../helpers/product-configurator-cart';
import * as configurationCartCpq from '../../../helpers/product-configurator-cart-cpq';
import * as common from '../../../helpers/common';
import { clickAllowAllFromBanner } from '../../../helpers/anonymous-consents';

const POWERTOOLS = 'powertools-spa';
Expand Down Expand Up @@ -109,14 +108,14 @@ context('CPQ Configuration', () => {
});

it('should be able to navigate from the product details page', () => {
configurationCpq.goToPDPage(POWERTOOLS, PROD_CODE_CAM);
common.goToPDPage(POWERTOOLS, PROD_CODE_CAM);
configurationCpq.clickOnConfigureBtnInCatalog();
});
});

describe('Handling different UI type', () => {
it('should support radio button attribute type', () => {
configurationCpq.goToPDPage(POWERTOOLS, PROD_CODE_COF);
common.goToPDPage(POWERTOOLS, PROD_CODE_COF);
configurationCpq.clickOnConfigureBtnInCatalog();

configuration.checkAttributeDisplayed(ATTR_COF_CUPS, RADGRP);
Expand All @@ -137,7 +136,7 @@ context('CPQ Configuration', () => {
});

it('should support checkbox list attribute type', () => {
configurationCpq.goToPDPage(POWERTOOLS, PROD_CODE_COF);
common.goToPDPage(POWERTOOLS, PROD_CODE_COF);
configurationCpq.clickOnConfigureBtnInCatalog();

configuration.checkAttributeDisplayed(ATTR_COF_MODE, CHKBOX);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import * as configurationOverview from '../../../helpers/product-configurator-ov
import * as configurationOverviewCpq from '../../../helpers/product-configurator-overview-cpq';
import * as configurationCart from '../../../helpers/product-configurator-cart';
import * as configurationCartCpq from '../../../helpers/product-configurator-cart-cpq';
import * as common from '../../../helpers/common';
import { clickAllowAllFromBanner } from '../../../helpers/anonymous-consents';

const POWERTOOLS = 'powertools-spa';
Expand Down Expand Up @@ -127,14 +128,14 @@ testConfig.forEach((config) => {
});

it('should be able to navigate from the product details page', () => {
configurationCpq.goToPDPage(POWERTOOLS, PROD_CODE_CAM);
common.goToPDPage(POWERTOOLS, PROD_CODE_CAM);
configurationCpq.clickOnConfigureBtnInCatalog();
});
});

describe('Handling different UI type', () => {
it('should support radio button attribute type', () => {
configurationCpq.goToPDPage(POWERTOOLS, PROD_CODE_COF);
common.goToPDPage(POWERTOOLS, PROD_CODE_COF);
configurationCpq.clickOnConfigureBtnInCatalog();

configuration.checkAttributeDisplayed(ATTR_COF_CUPS, RADGRP);
Expand Down Expand Up @@ -165,7 +166,7 @@ testConfig.forEach((config) => {
});

it('should support checkbox list attribute type', () => {
configurationCpq.goToPDPage(POWERTOOLS, PROD_CODE_COF);
common.goToPDPage(POWERTOOLS, PROD_CODE_COF);
configurationCpq.clickOnConfigureBtnInCatalog();

configuration.checkAttributeDisplayed(ATTR_COF_MODE, CHKBOX);
Expand Down Expand Up @@ -555,9 +556,9 @@ testConfig.forEach((config) => {

describe('Configuration Process', () => {
it('should support configuration aspect in product search, cart, checkout and order history', () => {
configurationCpq.goToPDPage(POWERTOOLS, PROD_CODE_CAM);
configuration.clickOnAddToCartBtnOnPD();
configuration.clickOnViewCartBtnOnPD();
common.goToPDPage(POWERTOOLS, PROD_CODE_CAM);
common.clickOnAddToCartBtnOnPD();
common.clickOnViewCartBtnOnPD();

cy.get('cx-mini-cart .count').then((elem) => {
const numberOfCartItems = Number(elem.text());
Expand Down
Loading

0 comments on commit 15d23f9

Please sign in to comment.