-
Notifications
You must be signed in to change notification settings - Fork 390
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add throwPaymentError global function (#17875)
CXSPA-4484
- Loading branch information
1 parent
25c7469
commit 2ce1f6e
Showing
49 changed files
with
672 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
14
integration-libs/opf/base/components/opf-base-components.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
18 changes: 18 additions & 0 deletions
18
...gration-libs/opf/base/components/opf-error-modal/default-opf-error-modal.layout.config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
10
integration-libs/opf/base/components/opf-error-modal/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
23 changes: 23 additions & 0 deletions
23
integration-libs/opf/base/components/opf-error-modal/opf-error-modal.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
88 changes: 88 additions & 0 deletions
88
integration-libs/opf/base/components/opf-error-modal/opf-error-modal.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
Oops, something went wrong.