Skip to content

Commit

Permalink
feat: add throwPaymentError global function (#17875)
Browse files Browse the repository at this point in the history
CXSPA-4484
  • Loading branch information
FollowTheFlo authored Sep 29, 2023
1 parent 25c7469 commit 2ce1f6e
Show file tree
Hide file tree
Showing 49 changed files with 672 additions and 112 deletions.
3 changes: 3 additions & 0 deletions core-libs/setup/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,9 @@
"@spartacus/opf/base/assets": [
"../../integration-libs/opf/base/assets/public_api"
],
"@spartacus/opf/base/components": [
"../../integration-libs/opf/base/components/public_api"
],
"@spartacus/opf/base/core": [
"../../integration-libs/opf/base/core/public_api"
],
Expand Down
3 changes: 3 additions & 0 deletions feature-libs/asm/tsconfig.schematics.json
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,9 @@
"@spartacus/opf/base/assets": [
"../../integration-libs/opf/base/assets/public_api"
],
"@spartacus/opf/base/components": [
"../../integration-libs/opf/base/components/public_api"
],
"@spartacus/opf/base/core": [
"../../integration-libs/opf/base/core/public_api"
],
Expand Down
3 changes: 3 additions & 0 deletions feature-libs/cart/tsconfig.schematics.json
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,9 @@
"@spartacus/opf/base/assets": [
"../../integration-libs/opf/base/assets/public_api"
],
"@spartacus/opf/base/components": [
"../../integration-libs/opf/base/components/public_api"
],
"@spartacus/opf/base/core": [
"../../integration-libs/opf/base/core/public_api"
],
Expand Down
3 changes: 3 additions & 0 deletions feature-libs/checkout/tsconfig.schematics.json
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,9 @@
"@spartacus/opf/base/assets": [
"../../integration-libs/opf/base/assets/public_api"
],
"@spartacus/opf/base/components": [
"../../integration-libs/opf/base/components/public_api"
],
"@spartacus/opf/base/core": [
"../../integration-libs/opf/base/core/public_api"
],
Expand Down
3 changes: 3 additions & 0 deletions feature-libs/customer-ticketing/tsconfig.schematics.json
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,9 @@
"@spartacus/opf/base/assets": [
"../../integration-libs/opf/base/assets/public_api"
],
"@spartacus/opf/base/components": [
"../../integration-libs/opf/base/components/public_api"
],
"@spartacus/opf/base/core": [
"../../integration-libs/opf/base/core/public_api"
],
Expand Down
3 changes: 3 additions & 0 deletions feature-libs/order/tsconfig.schematics.json
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,9 @@
"@spartacus/opf/base/assets": [
"../../integration-libs/opf/base/assets/public_api"
],
"@spartacus/opf/base/components": [
"../../integration-libs/opf/base/components/public_api"
],
"@spartacus/opf/base/core": [
"../../integration-libs/opf/base/core/public_api"
],
Expand Down
3 changes: 3 additions & 0 deletions feature-libs/organization/tsconfig.schematics.json
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,9 @@
"@spartacus/opf/base/assets": [
"../../integration-libs/opf/base/assets/public_api"
],
"@spartacus/opf/base/components": [
"../../integration-libs/opf/base/components/public_api"
],
"@spartacus/opf/base/core": [
"../../integration-libs/opf/base/core/public_api"
],
Expand Down
3 changes: 3 additions & 0 deletions feature-libs/pickup-in-store/tsconfig.schematics.json
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,9 @@
"@spartacus/opf/base/assets": [
"../../integration-libs/opf/base/assets/public_api"
],
"@spartacus/opf/base/components": [
"../../integration-libs/opf/base/components/public_api"
],
"@spartacus/opf/base/core": [
"../../integration-libs/opf/base/core/public_api"
],
Expand Down
3 changes: 3 additions & 0 deletions feature-libs/product-configurator/tsconfig.schematics.json
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,9 @@
"@spartacus/opf/base/assets": [
"../../integration-libs/opf/base/assets/public_api"
],
"@spartacus/opf/base/components": [
"../../integration-libs/opf/base/components/public_api"
],
"@spartacus/opf/base/core": [
"../../integration-libs/opf/base/core/public_api"
],
Expand Down
3 changes: 3 additions & 0 deletions feature-libs/product/tsconfig.schematics.json
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,9 @@
"@spartacus/opf/base/assets": [
"../../integration-libs/opf/base/assets/public_api"
],
"@spartacus/opf/base/components": [
"../../integration-libs/opf/base/components/public_api"
],
"@spartacus/opf/base/core": [
"../../integration-libs/opf/base/core/public_api"
],
Expand Down
3 changes: 3 additions & 0 deletions feature-libs/qualtrics/tsconfig.schematics.json
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,9 @@
"@spartacus/opf/base/assets": [
"../../integration-libs/opf/base/assets/public_api"
],
"@spartacus/opf/base/components": [
"../../integration-libs/opf/base/components/public_api"
],
"@spartacus/opf/base/core": [
"../../integration-libs/opf/base/core/public_api"
],
Expand Down
3 changes: 3 additions & 0 deletions feature-libs/requested-delivery-date/tsconfig.schematics.json
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,9 @@
"@spartacus/opf/base/assets": [
"../../integration-libs/opf/base/assets/public_api"
],
"@spartacus/opf/base/components": [
"../../integration-libs/opf/base/components/public_api"
],
"@spartacus/opf/base/core": [
"../../integration-libs/opf/base/core/public_api"
],
Expand Down
3 changes: 3 additions & 0 deletions feature-libs/smartedit/tsconfig.schematics.json
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,9 @@
"@spartacus/opf/base/assets": [
"../../integration-libs/opf/base/assets/public_api"
],
"@spartacus/opf/base/components": [
"../../integration-libs/opf/base/components/public_api"
],
"@spartacus/opf/base/core": [
"../../integration-libs/opf/base/core/public_api"
],
Expand Down
3 changes: 3 additions & 0 deletions feature-libs/storefinder/tsconfig.schematics.json
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,9 @@
"@spartacus/opf/base/assets": [
"../../integration-libs/opf/base/assets/public_api"
],
"@spartacus/opf/base/components": [
"../../integration-libs/opf/base/components/public_api"
],
"@spartacus/opf/base/core": [
"../../integration-libs/opf/base/core/public_api"
],
Expand Down
3 changes: 3 additions & 0 deletions feature-libs/tracking/tsconfig.schematics.json
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,9 @@
"@spartacus/opf/base/assets": [
"../../integration-libs/opf/base/assets/public_api"
],
"@spartacus/opf/base/components": [
"../../integration-libs/opf/base/components/public_api"
],
"@spartacus/opf/base/core": [
"../../integration-libs/opf/base/core/public_api"
],
Expand Down
3 changes: 3 additions & 0 deletions feature-libs/user/tsconfig.schematics.json
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,9 @@
"@spartacus/opf/base/assets": [
"../../integration-libs/opf/base/assets/public_api"
],
"@spartacus/opf/base/components": [
"../../integration-libs/opf/base/components/public_api"
],
"@spartacus/opf/base/core": [
"../../integration-libs/opf/base/core/public_api"
],
Expand Down
3 changes: 3 additions & 0 deletions integration-libs/cdc/tsconfig.schematics.json
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,9 @@
"@spartacus/opf/base/assets": [
"../../integration-libs/opf/base/assets/public_api"
],
"@spartacus/opf/base/components": [
"../../integration-libs/opf/base/components/public_api"
],
"@spartacus/opf/base/core": [
"../../integration-libs/opf/base/core/public_api"
],
Expand Down
3 changes: 3 additions & 0 deletions integration-libs/cds/tsconfig.schematics.json
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,9 @@
"@spartacus/opf/base/assets": [
"../../integration-libs/opf/base/assets/public_api"
],
"@spartacus/opf/base/components": [
"../../integration-libs/opf/base/components/public_api"
],
"@spartacus/opf/base/core": [
"../../integration-libs/opf/base/core/public_api"
],
Expand Down
3 changes: 3 additions & 0 deletions integration-libs/digital-payments/tsconfig.schematics.json
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,9 @@
"@spartacus/opf/base/assets": [
"../../integration-libs/opf/base/assets/public_api"
],
"@spartacus/opf/base/components": [
"../../integration-libs/opf/base/components/public_api"
],
"@spartacus/opf/base/core": [
"../../integration-libs/opf/base/core/public_api"
],
Expand Down
3 changes: 3 additions & 0 deletions integration-libs/epd-visualization/tsconfig.schematics.json
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,9 @@
"@spartacus/opf/base/assets": [
"../../integration-libs/opf/base/assets/public_api"
],
"@spartacus/opf/base/components": [
"../../integration-libs/opf/base/components/public_api"
],
"@spartacus/opf/base/core": [
"../../integration-libs/opf/base/core/public_api"
],
Expand Down
26 changes: 24 additions & 2 deletions integration-libs/opf/_index.scss
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
@import '@spartacus/styles/scss/core';
@import '@spartacus/checkout';

@import 'bootstrap/scss/functions';
@import 'bootstrap/scss/variables';
@import 'bootstrap/scss/_mixins';

@import './checkout/styles/index';
@import './base/styles/index';

$opf-components-allowlist: cx-opf-checkout-payment-and-review,
cx-opf-checkout-payments, cx-opf-checkout-billing-address-form,
cx-opf-checkout-payment-wrapper, cx-opf-error-modal !default;

$skipComponentStyles: () !default;

@each $selector in $opf-components-allowlist {
#{$selector} {
// skip selectors if they're added to the $skipComponentStyles list
@if (index($skipComponentStyles, $selector) == null) {
@extend %#{$selector} !optional;
}
}
}

// add body specific selectors
body {
@each $selector in $opf-components-allowlist {
@if (index($skipComponentStyles, $selector) == null) {
@extend %#{$selector}__body !optional;
}
}
}
6 changes: 6 additions & 0 deletions integration-libs/opf/base/components/ng-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$schema": "../../../../node_modules/ng-packagr/ng-package.schema.json",
"lib": {
"entryFile": "./public_api.ts"
}
}
14 changes: 14 additions & 0 deletions integration-libs/opf/base/components/opf-base-components.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* SPDX-FileCopyrightText: 2023 SAP Spartacus team <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

import { NgModule } from '@angular/core';
import { OpfErrorModalModule } from './opf-error-modal/opf-error-modal.module';

@NgModule({
imports: [OpfErrorModalModule],
providers: [],
})
export class OpfBaseComponentsModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* SPDX-FileCopyrightText: 2023 SAP Spartacus team <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

import { DIALOG_TYPE, LayoutConfig } from '@spartacus/storefront';
import { OpfErrorModalComponent } from './opf-error-modal.component';

export const defaultOpfErrorModalLayoutConfig: LayoutConfig = {
launch: {
OPF_ERROR: {
inline: true,
component: OpfErrorModalComponent,
dialogType: DIALOG_TYPE.POPOVER_CENTER_BACKDROP,
},
},
};
10 changes: 10 additions & 0 deletions integration-libs/opf/base/components/opf-error-modal/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* SPDX-FileCopyrightText: 2023 SAP Spartacus team <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

export * from './default-opf-error-modal.layout.config';
export * from './opf-error-modal.component';
export * from './opf-error-modal.module';
export * from './opf-error-modal.service';
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<ng-container>
<div
[cxFocus]="focusConfig"
class="cx-opf-error-modal"
(esc)="dismissModal('Escape click')"
>
<div
class="cx-opf-error-modal-container"
*ngIf="errorDialogOptions$ | async as errorDialogOptions"
>
<div class="cx-opf-error-modal-body modal-body">
<p class="cx-confirmation">
{{ errorDialogOptions?.message }}
</p>
</div>
<div class="cx-opf-error-modal-footer cx-modal-footer">
<button class="btn btn-primary" (click)="dismissModal('Cancel')">
{{ errorDialogOptions?.confirm }}
</button>
</div>
</div>
</div>
</ng-container>
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { I18nTestingModule } from '@spartacus/core';
import { ErrorDialogOptions } from '@spartacus/opf/base/root';
import { LaunchDialogService } from '@spartacus/storefront';
import { BehaviorSubject, Observable, of } from 'rxjs';
import { OpfErrorModalComponent } from './opf-error-modal.component';
import { OpfErrorModalService } from './opf-error-modal.service';

const dialogClose$ = new BehaviorSubject<any>('');
let mockDialogOptions: ErrorDialogOptions = {
messageString: 'Opf Test Message',
confirmString: 'Opf Test Confirm',
};
class MockLaunchDialogService implements Partial<LaunchDialogService> {
get data$(): Observable<any> | undefined {
return of(mockDialogOptions);
}
get dialogClose() {
return dialogClose$.asObservable();
}

closeDialog() {}
}

class MockOpfErrorModalService implements Partial<OpfErrorModalService> {
getMessageAndConfirmTranslations(dialogOptions: ErrorDialogOptions) {
return of({
message: dialogOptions.messageString,
confirm: dialogOptions.confirmString,
});
}
}

describe('OpfErrorModalComponent', () => {
let component: OpfErrorModalComponent;
let fixture: ComponentFixture<OpfErrorModalComponent>;
let launchDialogService: LaunchDialogService;
let opfErrorModalService: OpfErrorModalService;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [I18nTestingModule],
declarations: [OpfErrorModalComponent],
providers: [
{ provide: OpfErrorModalService, useClass: MockOpfErrorModalService },
{
provide: LaunchDialogService,
useClass: MockLaunchDialogService,
},
],
});

fixture = TestBed.createComponent(OpfErrorModalComponent);
component = fixture.componentInstance;
launchDialogService = TestBed.inject(LaunchDialogService);
opfErrorModalService = TestBed.inject(OpfErrorModalService);
});

it('should create', () => {
expect(component).toBeTruthy();
});

it('should close dialogue when modal is dismissed', () => {
spyOn(launchDialogService, 'closeDialog').and.callThrough();
component.dismissModal('opf test');

expect(launchDialogService.closeDialog).toHaveBeenCalled();
});

it('should closeModal when user click outside', () => {
const el = fixture.debugElement.nativeElement;
spyOn(component, 'dismissModal');

el.click();
expect(component.dismissModal).toHaveBeenCalledWith('Backdrop click');
});

it('should call the transalation service when component is init', () => {
spyOn(
opfErrorModalService,
'getMessageAndConfirmTranslations'
).and.callThrough();
component.ngOnInit();
fixture.detectChanges();
expect(
opfErrorModalService.getMessageAndConfirmTranslations
).toHaveBeenCalled();
});
});
Loading

0 comments on commit 2ce1f6e

Please sign in to comment.