Skip to content

Commit

Permalink
fix: cover undefined quote actions properly
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristophHi committed Jul 13, 2023
1 parent cad2ed2 commit cec236f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,5 +172,12 @@ describe('QuoteDetailsOverviewComponent', () => {
'quote.details.total'
);
});

it('should be able to deal with undefined actions', () => {
const quoteWoActions: Quote = { ...mockQuote, allowedActions: undefined };
expect(component.getTotalPriceDescription(quoteWoActions)).toBe(
'quote.details.estimatedTotal'
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class QuoteDetailsOverviewComponent {
* @returns 'Total' price if quote is in final state, 'Estimated total' otherwise
*/
getTotalPriceDescription(quote: Quote): string {
const readyToSubmit = quote.allowedActions.find(
const readyToSubmit = quote.allowedActions?.find(
(action) => action.type === QuoteActionType.CHECKOUT
);
return readyToSubmit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,18 @@ describe('QuoteActionsByRoleComponent', () => {
expect(actionButtons[0].nativeElement.disabled).toBe(false);
});

it('should be able to deal with undefined actions', () => {
const quoteWithoutActions: Quote = {
...mockQuote,
allowedActions: undefined,
};
mockQuoteDetails$.next(quoteWithoutActions);
fixture.detectChanges();
const actionButtons = fixture.debugElement.queryAll(By.css('.btn'));
expect(actionButtons).toBeDefined();
expect(actionButtons.length).toBe(0);
});

it('should let submit button enabled if threshold is not specified', () => {
mockQuote.threshold = undefined;
mockQuoteDetails$.next(submittableQuote);
Expand Down Expand Up @@ -310,10 +322,13 @@ describe('QuoteActionsByRoleComponent', () => {
const actionButtons = fixture.debugElement.queryAll(By.css('.btn'));

expect(actionButtons).toBeDefined();

actionButtons.filter((button, index) => {
expect(button.nativeElement.textContent.trim()).toEqual(
`quote.actions.${mockQuote.allowedActions[index].type}`
);
if (mockQuote.allowedActions) {
expect(button.nativeElement.textContent.trim()).toEqual(
`quote.actions.${mockQuote.allowedActions[index].type}`
);
}
button.nativeElement.click();
});
expect(facade.performQuoteAction).toHaveBeenCalledWith(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class QuoteActionsByRoleComponent implements OnInit, OnDestroy {
ngOnInit(): void {
//submit button present and threshold not reached: Display message
this.quoteDetails$.pipe(take(1)).subscribe((quote) => {
const mustDisableAction = quote.allowedActions.find((action) =>
const mustDisableAction = quote.allowedActions?.find((action) =>
this.mustDisableAction(action.type, quote)
);
if (mustDisableAction) {
Expand Down
2 changes: 1 addition & 1 deletion feature-libs/quote/root/model/quote.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface OccQuote {
}

export type Quote = Omit<OccQuote, 'allowedActions'> & {
allowedActions: QuoteAction[];
allowedActions?: QuoteAction[];
};

export interface QuoteAction {
Expand Down

0 comments on commit cec236f

Please sign in to comment.