-
Notifications
You must be signed in to change notification settings - Fork 390
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
Add CTA Scripts feature #17991
Conversation
integration-libs/opf/base/components/opf-cta/opf-cta-scripts/opf-cta-scripts.service.ts
Outdated
Show resolved
Hide resolved
opfCtaScriptsService.getCtaHtmlslList = createSpy().and.returnValue( | ||
throwError('error') | ||
); | ||
createComponentInstance(); |
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...
opfCtaScriptsService.getCtaHtmlslList = createSpy().and.returnValue( | ||
of(undefined) | ||
); | ||
createComponentInstance(); |
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.
same situation as line 58 commented above
return loadedList; | ||
}, []), | ||
map((list) => { | ||
return this.removeScriptTags(list); |
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.
remove all script tags so they are not displayed in DOM (we don't sanitize html snippet). the script tags are already executed in prior step 'loadAndRunScript' so not needed anymore.
} | ||
}) | ||
.catch(() => { | ||
resolve(undefined); |
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.
All resolve(undefined)
are use for the logic : if a resource file (either css or js) fails to load, don't display the html snippet in UI.
@@ -0,0 +1,4 @@ | |||
%cx-opf-cta-element { |
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.
adding basic styling so CTA elements are separated vertically with 1rem (0.5+0.5).
protected removeScriptTags(htmls: string[]) { | ||
return htmls.map((html) => { | ||
const element = new DOMParser().parseFromString(html, 'text/html'); | ||
Array.from(element.getElementsByTagName('script')).forEach((script) => { |
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.
I spent a bit of time to look for removeChild solution, nothing was working, so I used the string manipulation solution with 'replace', it is even shorter.
integration-libs/opf/base/components/opf-cta/opf-cta-element/opf-cta-element.component.ts
Outdated
Show resolved
Hide resolved
4 flaky tests on run #41756 ↗︎
Details:
regression/variants/apparel-checkout-as-guest.core-e2e.cy.ts • 1 flaky test • B2C
ssr/pages.core-e2e.cy.ts • 3 flaky tests • SSRReview all test suite changes for PR #17991 ↗︎ |
switchMap((ctaScriptsRequest) => this.fetchCtaScripts(ctaScriptsRequest)), | ||
switchMap((scriptslist) => this.runCtaScripts(scriptslist)), | ||
finalize(() => { | ||
this.clearResources(); |
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.
avoid to clearResources in component ngOnDestroy fct.
cleaner solution.
CXSPA-4532
tests coverage is 100% on all files
display CTA scripts on 3 pages: pdp, confirmationPage, orderDetails