-
Notifications
You must be signed in to change notification settings - Fork 393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CTA Scripts feature #17991
Merged
Merged
Add CTA Scripts feature #17991
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
ddfaf96
add cta-scripts cms cpnt
FollowTheFlo aed0c6c
Merge branch 'epic/opf' into feature/CXSPA-4532
FollowTheFlo 3c93b44
add service
FollowTheFlo 7983ac9
implement script list + button + css
FollowTheFlo 787f93e
modif terminology - unit tests
FollowTheFlo 99e4f45
add cta script for pdp - remove logs - error handling
FollowTheFlo ad897cd
add unit tests
FollowTheFlo 0d6d509
add unit tests - improve rxjs piping
FollowTheFlo ef918e3
Add license header
github-actions[bot] 0589a1d
improve logic and naming
FollowTheFlo d8a190d
simplify removeScriptTags fct
FollowTheFlo dba6fda
fix sonar probs
FollowTheFlo 1783342
improve unit tests - simplify cpnt logic
FollowTheFlo 03c6766
add changeDetection
FollowTheFlo cf74564
remove css of cta wrapper as redundant
FollowTheFlo 9fd5e10
rename cta-button to cta-element
FollowTheFlo ec9d4f9
re-organize folders
FollowTheFlo 8ee7d50
simplify rxjs piping
FollowTheFlo 40c490f
refactor unit test to avoid redunduncy
FollowTheFlo 376174a
remove comments
FollowTheFlo 03df28c
fix sonar warning
FollowTheFlo ad53c0d
adjust naming and modules
FollowTheFlo 7fd6890
reject when empty resources
FollowTheFlo fd0bb5d
add unit test for resource-loader service
FollowTheFlo 9c0a7ba
Merge branch 'epic/opf' into feature/CXSPA-4532
FollowTheFlo 56142cc
rename interface with more generic name
FollowTheFlo 733cd11
remove rejects to only support happy scenario
FollowTheFlo f8dcc10
fix unit test
FollowTheFlo 9336252
Merge branch 'epic/opf' into feature/CXSPA-4532
FollowTheFlo 9513819
Merge branch 'epic/opf' into feature/CXSPA-4532
FollowTheFlo 9a6bace
add cxSafeHtml pipe
FollowTheFlo 1f33ef8
replace if/switch-case by mapping
FollowTheFlo 49dffc1
remove console logs from unit tests
FollowTheFlo 7c89c2f
fix sonar
FollowTheFlo 1f0e5b0
Merge branch 'epic/opf' into feature/CXSPA-4532
FollowTheFlo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 8 additions & 0 deletions
8
integration-libs/opf/base/components/opf-cta/opf-cta-element/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,8 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023 SAP Spartacus team <[email protected]> | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export * from './opf-cta-element.component'; | ||
export * from './opf-cta-element.module'; |
1 change: 1 addition & 0 deletions
1
integration-libs/opf/base/components/opf-cta/opf-cta-element/opf-cta-element.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 @@ | ||
<div *ngIf="ctaScriptHtml" [innerHTML]="ctaScriptHtml | cxSafeHtml"></div> |
19 changes: 19 additions & 0 deletions
19
...ration-libs/opf/base/components/opf-cta/opf-cta-element/opf-cta-element.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,19 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { OpfCtaElementComponent } from './opf-cta-element.component'; | ||
|
||
describe('OpfCtaButton', () => { | ||
let component: OpfCtaElementComponent; | ||
let fixture: ComponentFixture<OpfCtaElementComponent>; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [OpfCtaElementComponent], | ||
}); | ||
fixture = TestBed.createComponent(OpfCtaElementComponent); | ||
component = fixture.componentInstance; | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
16 changes: 16 additions & 0 deletions
16
integration-libs/opf/base/components/opf-cta/opf-cta-element/opf-cta-element.component.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,16 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023 SAP Spartacus team <[email protected]> | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { ChangeDetectionStrategy, Component, Input } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'cx-opf-cta-element', | ||
templateUrl: './opf-cta-element.component.html', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class OpfCtaElementComponent { | ||
@Input() ctaScriptHtml: string; | ||
} |
17 changes: 17 additions & 0 deletions
17
integration-libs/opf/base/components/opf-cta/opf-cta-element/opf-cta-element.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,17 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023 SAP Spartacus team <[email protected]> | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { CommonModule } from '@angular/common'; | ||
import { NgModule } from '@angular/core'; | ||
import { SafeHtmlModule } from '@spartacus/storefront'; | ||
import { OpfCtaElementComponent } from './opf-cta-element.component'; | ||
|
||
@NgModule({ | ||
declarations: [OpfCtaElementComponent], | ||
imports: [CommonModule, SafeHtmlModule], | ||
exports: [OpfCtaElementComponent], | ||
}) | ||
export class OpfCtaElementModule {} |
9 changes: 9 additions & 0 deletions
9
integration-libs/opf/base/components/opf-cta/opf-cta-scripts/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,9 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023 SAP Spartacus team <[email protected]> | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export * from './opf-cta-scripts.component'; | ||
export * from './opf-cta-scripts.module'; | ||
export * from './opf-cta-scripts.service'; |
13 changes: 13 additions & 0 deletions
13
integration-libs/opf/base/components/opf-cta/opf-cta-scripts/opf-cta-scripts.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,13 @@ | ||
<ng-container *ngIf="ctaHtmls$ | async as ctaHtmls; else loading"> | ||
<ng-container *ngIf="ctaHtmls?.length"> | ||
<cx-opf-cta-element | ||
*ngFor="let ctaHtml of ctaHtmls" | ||
[ctaScriptHtml]="ctaHtml" | ||
></cx-opf-cta-element> | ||
</ng-container> | ||
</ng-container> | ||
<ng-template #loading> | ||
<div class="cx-spinner"> | ||
<cx-spinner></cx-spinner> | ||
</div> | ||
</ng-template> |
78 changes: 78 additions & 0 deletions
78
...ration-libs/opf/base/components/opf-cta/opf-cta-scripts/opf-cta-scripts.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,78 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { of, throwError } from 'rxjs'; | ||
import { OpfCtaScriptsComponent } from './opf-cta-scripts.component'; | ||
import { OpfCtaScriptsService } from './opf-cta-scripts.service'; | ||
import createSpy = jasmine.createSpy; | ||
|
||
const mockHtmlsList = [ | ||
'<div style="border-style: solid;text-align:center;border-radius:10px;align-content:center;background-color:yellow;color:black"><h2>Thanks for purchasing our great products</h2><h3>Please use promo code:<b>123abc</b> for your next purchase<h3></div><script>console.log(\'CTA Script #1 is running\')</script>', | ||
'<div style="border-style: solid;text-align:center;border-radius:10px;align-content:center;background-color:yellow;color:black"><h2>Thanks again for purchasing our great products</h2><h3>Please use promo code:<b>123abc</b> for your next purchase<h3></div><script>console.log(\'CTA Script #2 is running\')</script>', | ||
]; | ||
const ctaElementSelector = 'cx-opf-cta-element'; | ||
describe('OpfCtaScriptsComponent', () => { | ||
let component: OpfCtaScriptsComponent; | ||
let fixture: ComponentFixture<OpfCtaScriptsComponent>; | ||
let opfCtaScriptsService: jasmine.SpyObj<OpfCtaScriptsService>; | ||
|
||
const createComponentInstance = () => { | ||
fixture = TestBed.createComponent(OpfCtaScriptsComponent); | ||
component = fixture.componentInstance; | ||
}; | ||
beforeEach(() => { | ||
opfCtaScriptsService = jasmine.createSpyObj('OpfCtaScriptsService', [ | ||
'getCtaHtmlslList', | ||
]); | ||
|
||
TestBed.configureTestingModule({ | ||
declarations: [OpfCtaScriptsComponent], | ||
providers: [ | ||
{ provide: OpfCtaScriptsService, useValue: opfCtaScriptsService }, | ||
], | ||
}).compileComponents(); | ||
}); | ||
|
||
beforeEach(() => { | ||
opfCtaScriptsService.getCtaHtmlslList.and.returnValue(of(mockHtmlsList)); | ||
createComponentInstance(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it('should return Htmls list and display ctaButton elements', (done) => { | ||
component.ctaHtmls$.subscribe((htmlList) => { | ||
expect(htmlList[0]).toBeTruthy(); | ||
fixture.detectChanges(); | ||
expect( | ||
fixture.nativeElement.querySelectorAll(ctaElementSelector).length | ||
).toEqual(2); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should isError be true when error is thrown', (done) => { | ||
opfCtaScriptsService.getCtaHtmlslList = createSpy().and.returnValue( | ||
throwError('error') | ||
); | ||
createComponentInstance(); | ||
component.ctaHtmls$.subscribe((htmlList) => { | ||
expect(htmlList).toEqual([]); | ||
fixture.detectChanges(); | ||
expect( | ||
fixture.nativeElement.querySelector(ctaElementSelector) | ||
).toBeFalsy(); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should display spinner when html list is undefined', (done) => { | ||
opfCtaScriptsService.getCtaHtmlslList = createSpy().and.returnValue( | ||
of(undefined) | ||
); | ||
createComponentInstance(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same situation as line 58 commented above |
||
fixture.detectChanges(); | ||
expect(fixture.nativeElement.querySelector('cx-spinner')).toBeTruthy(); | ||
done(); | ||
}); | ||
}); |
25 changes: 25 additions & 0 deletions
25
integration-libs/opf/base/components/opf-cta/opf-cta-scripts/opf-cta-scripts.component.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,25 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023 SAP Spartacus team <[email protected]> | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { ChangeDetectionStrategy, Component, inject } from '@angular/core'; | ||
import { of } from 'rxjs'; | ||
import { catchError } from 'rxjs/operators'; | ||
import { OpfCtaScriptsService } from './opf-cta-scripts.service'; | ||
|
||
@Component({ | ||
selector: 'cx-opf-cta-scripts', | ||
templateUrl: './opf-cta-scripts.component.html', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class OpfCtaScriptsComponent { | ||
protected opfCtaScriptService = inject(OpfCtaScriptsService); | ||
|
||
ctaHtmls$ = this.opfCtaScriptService.getCtaHtmlslList().pipe( | ||
catchError(() => { | ||
return of([]); | ||
}) | ||
); | ||
} |
32 changes: 32 additions & 0 deletions
32
integration-libs/opf/base/components/opf-cta/opf-cta-scripts/opf-cta-scripts.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,32 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023 SAP Spartacus team <[email protected]> | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { CommonModule } from '@angular/common'; | ||
import { NgModule } from '@angular/core'; | ||
import { | ||
CmsConfig, | ||
FeaturesConfig, | ||
provideDefaultConfig, | ||
} from '@spartacus/core'; | ||
import { SpinnerModule } from '@spartacus/storefront'; | ||
import { OpfCtaElementModule } from '../opf-cta-element'; | ||
import { OpfCtaScriptsComponent } from './opf-cta-scripts.component'; | ||
|
||
@NgModule({ | ||
declarations: [OpfCtaScriptsComponent], | ||
providers: [ | ||
provideDefaultConfig(<CmsConfig | FeaturesConfig>{ | ||
cmsComponents: { | ||
OpfCtaScriptsComponent: { | ||
component: OpfCtaScriptsComponent, | ||
}, | ||
}, | ||
}), | ||
], | ||
exports: [OpfCtaScriptsComponent], | ||
imports: [CommonModule, OpfCtaElementModule, SpinnerModule], | ||
}) | ||
export class OpfCtaScriptsModule {} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to have opfCtaScriptsService.getCtaHtmlslList new value generated (line 55), I had to force creation of new component. I couldn't find other solutions.
It works if we mock getCtaHtmlslList with a rxJs Subject but it then causes issue with removing subscriptions, needs to pipe with take(1) and side effect if both 'it' would run in parallel...