Skip to content

Commit

Permalink
Feature/cxspa 4626 edit quote config (#17814)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristophHi authored Sep 8, 2023
1 parent e8dddff commit e8c81be
Show file tree
Hide file tree
Showing 12 changed files with 333 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,23 @@ describe('ConfigureCartEntryComponent', () => {
);
});

it('should find correct owner type in case entry knows quote', () => {
it('should find correct owner type quoteEntry in case entry knows quote and it is read-only', () => {
component.readOnly = true;
component.cartEntry = { quoteCode: quoteCode };
expect(component.getOwnerType()).toBe(
CommonConfigurator.OwnerType.QUOTE_ENTRY
);
});

it('should find correct owner type cartEntry in case entry knows quote and it is editable', () => {
component.cartEntry = { quoteCode: quoteCode };
expect(component.getOwnerType()).toBe(
CommonConfigurator.OwnerType.CART_ENTRY
);
});

it('should throw error in case both quote and order code are present', () => {
component.readOnly = true;
component.cartEntry = { orderCode: orderCode, quoteCode: quoteCode };
expect(() => component.getOwnerType()).toThrowError();
});
Expand All @@ -87,6 +96,7 @@ describe('ConfigureCartEntryComponent', () => {
});

it('should take order code into account in case entry is from order', () => {
component.readOnly = true;
const orderCode = '01008765';
component.cartEntry = { entryNumber: 0, orderCode: orderCode };
expect(component.getEntityKey()).toBe(orderCode + '+0');
Expand All @@ -99,17 +109,26 @@ describe('ConfigureCartEntryComponent', () => {
expect(component['getCode']()).toBeUndefined();
});

it('should return a quote code', () => {
it('should return a quote code in case entry knows quote and is read-only', () => {
component.readOnly = true;
component.cartEntry = { quoteCode: quoteCode };
expect(component['getCode']()).toEqual(quoteCode);
});

it('should return undefined in case entry knows quote and is editable, because then we are working on a (quote) cart', () => {
component.readOnly = false;
component.cartEntry = { quoteCode: quoteCode };
expect(component['getCode']()).toBe(undefined);
});

it('should return an order code', () => {
component.readOnly = true;
component.cartEntry = { orderCode: orderCode };
expect(component['getCode']()).toEqual(orderCode);
});

it('should throw error in case both quote and order code are present', () => {
component.readOnly = true;
component.cartEntry = { orderCode: orderCode, quoteCode: quoteCode };
expect(() => component['getCode']()).toThrowError();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class ConfigureCartEntryComponent {
* @returns - an owner type
*/
getOwnerType(): CommonConfigurator.OwnerType {
if (this.cartEntry.quoteCode || this.cartEntry.orderCode) {
if (this.isOrderOrQuoteRelated()) {
if (!this.cartEntry.quoteCode) {
return CommonConfigurator.OwnerType.ORDER_ENTRY;
}
Expand Down Expand Up @@ -76,7 +76,7 @@ export class ConfigureCartEntryComponent {
* @returns Document code if order or quote bound, undefined in other cases
*/
protected getCode(): string | undefined {
if (this.cartEntry.quoteCode || this.cartEntry.orderCode) {
if (this.isOrderOrQuoteRelated()) {
if (!this.cartEntry.quoteCode) {
return this.cartEntry.orderCode;
}
Expand All @@ -91,6 +91,12 @@ export class ConfigureCartEntryComponent {
}
}

protected isOrderOrQuoteRelated(): boolean {
return this.cartEntry.quoteCode || this.cartEntry.orderCode
? this.readOnly
: false;
}

/**
* Retrieves a corresponding route depending whether the configuration is read only or not.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
} from '@spartacus/checkout/base/root';
import {
OCC_USER_ID_ANONYMOUS,
OCC_USER_ID_CURRENT,
QueryState,
StateUtils,
UserIdService,
Expand Down Expand Up @@ -37,6 +36,7 @@ let OWNER_CART_ENTRY = ConfiguratorModelUtils.createInitialOwner();
let OWNER_ORDER_ENTRY = ConfiguratorModelUtils.createInitialOwner();
let OWNER_QUOTE_ENTRY = ConfiguratorModelUtils.createInitialOwner();
let OWNER_PRODUCT = ConfiguratorModelUtils.createInitialOwner();

const CART_CODE = '0000009336';
const CART_ENTRY_ID = '3';
const CART_GUID = 'e767605d-7336-48fd-b156-ad50d004ca10';
Expand All @@ -46,6 +46,7 @@ const ORDER_ENTRY_NUMBER = 2;
const QUOTE_ENTRY_NUMBER = 4;
const PRODUCT_CODE = 'CONF_LAPTOP';
const CONFIG_ID = '1234-56-7890';
const USER_ID = 'ab3f7a08-690a-4616-b1fe-4f0847fcb79f';

const cart: Cart = {
code: CART_CODE,
Expand Down Expand Up @@ -95,7 +96,7 @@ class MockCheckoutQueryFacade {

class MockUserIdService {
getUserId(): Observable<string> {
return of(OCC_USER_ID_ANONYMOUS);
return of(USER_ID);
}
}

Expand Down Expand Up @@ -197,7 +198,7 @@ describe('ConfiguratorCartService', () => {
owner: OWNER_CART_ENTRY,
cartEntryNumber: OWNER_CART_ENTRY.id,
cartId: CART_GUID,
userId: OCC_USER_ID_ANONYMOUS,
userId: USER_ID,
};
const productConfigurationLoaderState: StateUtils.LoaderState<Configurator.Configuration> =
{
Expand Down Expand Up @@ -307,7 +308,7 @@ describe('ConfiguratorCartService', () => {
owner: OWNER_ORDER_ENTRY,
orderEntryNumber: '' + ORDER_ENTRY_NUMBER,
orderId: ORDER_ID,
userId: OCC_USER_ID_CURRENT,
userId: USER_ID,
};
const productConfigurationLoaderState: StateUtils.LoaderState<Configurator.Configuration> =
{
Expand Down Expand Up @@ -357,7 +358,7 @@ describe('ConfiguratorCartService', () => {
it('should dispatch ReadQuoteEntryConfiguration action in case configuration is not present so far', () => {
const params: CommonConfigurator.ReadConfigurationFromQuoteEntryParameters =
{
userId: OCC_USER_ID_CURRENT,
userId: USER_ID,
quoteId: QUOTE_ID,
quoteEntryNumber: '' + QUOTE_ENTRY_NUMBER,
owner: OWNER_QUOTE_ENTRY,
Expand Down Expand Up @@ -391,7 +392,7 @@ describe('ConfiguratorCartService', () => {
it('should get cart, create addToCartParameters and call addToCart action without setting quantity', () => {
const addToCartParams: Configurator.AddToCartParameters = {
cartId: CART_GUID,
userId: OCC_USER_ID_ANONYMOUS,
userId: USER_ID,
productCode: PRODUCT_CODE,
quantity: 1,
configId: CONFIG_ID,
Expand All @@ -410,7 +411,7 @@ describe('ConfiguratorCartService', () => {
it('should get cart, create addToCartParameters and call addToCart action with setting quantity', () => {
const addToCartParams: Configurator.AddToCartParameters = {
cartId: CART_GUID,
userId: OCC_USER_ID_ANONYMOUS,
userId: USER_ID,
productCode: PRODUCT_CODE,
quantity: 100,
configId: CONFIG_ID,
Expand All @@ -431,7 +432,7 @@ describe('ConfiguratorCartService', () => {
it('should create updateParameters and call updateCartEntry action', () => {
const params: Configurator.UpdateConfigurationForCartEntryParameters = {
cartId: CART_GUID,
userId: OCC_USER_ID_ANONYMOUS,
userId: USER_ID,
cartEntryNumber: productConfiguration.owner.id,
configuration: productConfiguration,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ import { Injectable } from '@angular/core';
import { select, Store } from '@ngrx/store';
import { ActiveCartFacade, OrderEntry } from '@spartacus/cart/base/root';
import { CheckoutQueryFacade } from '@spartacus/checkout/base/root';
import {
OCC_USER_ID_CURRENT,
StateUtils,
UserIdService,
} from '@spartacus/core';
import { StateUtils, UserIdService } from '@spartacus/core';
import {
CommonConfigurator,
CommonConfiguratorUtilsService,
Expand Down Expand Up @@ -122,18 +118,23 @@ export class ConfiguratorCartService {
const ownerIdParts = this.commonConfigUtilsService.decomposeOwnerId(
owner.id
);
const readFromOrderEntryParameters: CommonConfigurator.ReadConfigurationFromOrderEntryParameters =
{
userId: OCC_USER_ID_CURRENT,
orderId: ownerIdParts.documentId,
orderEntryNumber: ownerIdParts.entryNumber,
owner: owner,
};
this.store.dispatch(
new ConfiguratorActions.ReadOrderEntryConfiguration(
readFromOrderEntryParameters
)
);
this.userIdService
.getUserId()
.pipe(take(1))
.subscribe((userId) => {
const readFromOrderEntryParameters: CommonConfigurator.ReadConfigurationFromOrderEntryParameters =
{
userId: userId,
orderId: ownerIdParts.documentId,
orderEntryNumber: ownerIdParts.entryNumber,
owner: owner,
};
this.store.dispatch(
new ConfiguratorActions.ReadOrderEntryConfiguration(
readFromOrderEntryParameters
)
);
});
}
}),
filter(
Expand Down Expand Up @@ -181,18 +182,23 @@ export class ConfiguratorCartService {
const ownerIdParts = this.commonConfigUtilsService.decomposeOwnerId(
owner.id
);
const readFromQuoteEntryParameters: CommonConfigurator.ReadConfigurationFromQuoteEntryParameters =
{
userId: OCC_USER_ID_CURRENT,
quoteId: ownerIdParts.documentId,
quoteEntryNumber: ownerIdParts.entryNumber,
owner: owner,
};
this.store.dispatch(
new ConfiguratorActions.ReadQuoteEntryConfiguration(
readFromQuoteEntryParameters
)
);
this.userIdService
.getUserId()
.pipe(take(1))
.subscribe((userId) => {
const readFromQuoteEntryParameters: CommonConfigurator.ReadConfigurationFromQuoteEntryParameters =
{
userId: userId,
quoteId: ownerIdParts.documentId,
quoteEntryNumber: ownerIdParts.entryNumber,
owner: owner,
};
this.store.dispatch(
new ConfiguratorActions.ReadQuoteEntryConfiguration(
readFromQuoteEntryParameters
)
);
});
}
}),
filter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,22 @@
</cx-icon>
<span class="cx-text">{{ 'quote.commons.cart' | cxTranslate }}</span>
</div>

<ng-container
*ngIf="state.showCart && (quoteDetails$ | async) as quoteDetails"
>
<ng-container *ngIf="state.showCart">
<ng-template
*ngIf="!quoteDetails.isEditable"
[cxOutlet]="cartOutlets.CART_ITEM_LIST"
[cxOutletContext]="{
items: quoteDetails.entries ?? [],
readonly: !quoteDetails.isEditable
readonly: true
}"
>
</ng-template>
<ng-template
*ngIf="quoteDetails.isEditable && (cartDetails$ | async) as cartDetails"
[cxOutlet]="cartOutlets.CART_ITEM_LIST"
[cxOutletContext]="{
items: cartDetails.entries ?? [],
readonly: false
}"
>
</ng-template>
Expand Down
Loading

0 comments on commit e8c81be

Please sign in to comment.