Skip to content

Commit

Permalink
refactor: inline quote role service (CXSPA-4763) (#17864)
Browse files Browse the repository at this point in the history
  • Loading branch information
Uli-Tiger authored Sep 25, 2023
1 parent 4409b78 commit 63cefcd
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
QuoteAction,
QuoteActionType,
QuoteFacade,
QuoteRoleType,
QuoteState,
} from '@spartacus/quote/root';

Expand Down Expand Up @@ -586,4 +587,29 @@ describe('QuoteActionsByRoleComponent', () => {
).toEqual('btn-tertiary');
});
});

describe('stateToRoleTypeForDialogConfig', () => {
it('should return buyer-role', () => {
expect(
component['stateToRoleTypeForDialogConfig'](QuoteState.BUYER_DRAFT)
).toBe(QuoteRoleType.BUYER);
});
it('should return seller-role', () => {
expect(
component['stateToRoleTypeForDialogConfig'](QuoteState.SELLER_SUBMITTED)
).toBe(QuoteRoleType.SELLER);
});
it('should return seller-approver-role', () => {
expect(
component['stateToRoleTypeForDialogConfig'](
QuoteState.SELLERAPPROVER_APPROVED
)
).toBe(QuoteRoleType.SELLERAPPROVER);
});
it('should return default (not_available) role type if no role matches', () => {
expect(
component['stateToRoleTypeForDialogConfig'](QuoteState.CANCELLED)
).toBe(QuoteRoleType.NOT_AVAILABLE);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import {
ViewContainerRef,
} from '@angular/core';
import { GlobalMessageService, GlobalMessageType } from '@spartacus/core';
import { QuoteRoleService } from '@spartacus/quote/core';
import {
Quote,
QuoteAction,
QuoteActionType,
QuoteFacade,
QuoteRoleType,
QuoteState,
} from '@spartacus/quote/root';
import { LAUNCH_CALLER, LaunchDialogService } from '@spartacus/storefront';
Expand Down Expand Up @@ -46,7 +46,6 @@ export class QuoteActionsByRoleComponent implements OnInit, OnDestroy {
protected launchDialogService: LaunchDialogService,
protected viewContainerRef: ViewContainerRef,
protected globalMessageService: GlobalMessageService,
protected quoteRoleService: QuoteRoleService,
protected config: QuoteUIConfig
) {}

Expand Down Expand Up @@ -164,7 +163,7 @@ export class QuoteActionsByRoleComponent implements OnInit, OnDestroy {
const mappingConfig = this.config.quote?.confirmActionDialogMapping;
return (
!!mappingConfig?.[state]?.[action] ||
!!mappingConfig?.[this.quoteRoleService.stateToRole(state)]?.[action]
!!mappingConfig?.[this.stateToRoleTypeForDialogConfig(state)]?.[action]
);
}

Expand Down Expand Up @@ -199,7 +198,7 @@ export class QuoteActionsByRoleComponent implements OnInit, OnDestroy {

const config =
mappingConfig?.[state]?.[action] ??
mappingConfig?.[this.quoteRoleService.stateToRole(state)]?.[action];
mappingConfig?.[this.stateToRoleTypeForDialogConfig(state)]?.[action];
if (!config) {
throw new Error(
`Dialog Config expected for quote in state ${state} and action ${action}, but none found in config ${mappingConfig}`
Expand All @@ -208,4 +207,14 @@ export class QuoteActionsByRoleComponent implements OnInit, OnDestroy {

return config;
}

protected stateToRoleTypeForDialogConfig(state: QuoteState): QuoteRoleType {
let foundRole: QuoteRoleType = QuoteRoleType.NOT_AVAILABLE;
Object.values(QuoteRoleType).forEach((role) => {
if (state.startsWith(role + '_')) {
foundRole = role;
}
});
return foundRole;
}
}
1 change: 0 additions & 1 deletion feature-libs/quote/core/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@
*/

export * from './cart-utils.service';
export * from './quote-role.service';
40 changes: 0 additions & 40 deletions feature-libs/quote/core/services/quote-role.service.spec.ts

This file was deleted.

23 changes: 0 additions & 23 deletions feature-libs/quote/core/services/quote-role.service.ts

This file was deleted.

0 comments on commit 63cefcd

Please sign in to comment.