@@ -117,6 +117,7 @@ import { ActionPayload, ContentTypeDragPayload } from '../shared/models';
117117import { UVEStore } from '../store/dot-uve.store' ;
118118import * as uveUtils from '../utils' ;
119119import { TEMPORAL_DRAG_ITEM } from '../utils' ;
120+ import { SDK_EDITOR_SCRIPT_SOURCE } from '../utils/ema-legacy-script-injection' ;
120121
121122global . URL . createObjectURL = jest . fn (
122123 ( ) => 'blob:http://localhost:3000/12345678-1234-1234-1234-123456789012'
@@ -3483,6 +3484,77 @@ describe('EditEmaEditorComponent', () => {
34833484 } ) ;
34843485 } ) ;
34853486
3487+ describe ( 'legacy script injection (FEATURE_FLAG_UVE_LEGACY_SCRIPT_INJECTION)' , ( ) => {
3488+ let componentStore : InstanceType < typeof UVEStore > ;
3489+
3490+ beforeEach ( ( ) => {
3491+ componentStore = (
3492+ spectator . component as unknown as {
3493+ uveStore : InstanceType < typeof UVEStore > ;
3494+ }
3495+ ) . uveStore ;
3496+
3497+ jest . spyOn ( dotPageApiService , 'get' ) . mockReturnValue ( of ( MOCK_RESPONSE_VTL ) ) ;
3498+ store . loadPageAsset ( { url : 'index' , clientHost : null } ) ;
3499+ } ) ;
3500+
3501+ it ( 'should inject the UVE script when the flag is enabled' , ( ) => {
3502+ patchState ( componentStore , {
3503+ flags : {
3504+ ...componentStore . flags ( ) ,
3505+ [ FeaturedFlags . FEATURE_FLAG_UVE_LEGACY_SCRIPT_INJECTION ] : true
3506+ }
3507+ } ) ;
3508+
3509+ const iframe = spectator . query ( byTestId ( 'iframe' ) ) as HTMLIFrameElement ;
3510+ const spyWrite = jest . spyOn ( iframe . contentDocument , 'write' ) ;
3511+
3512+ iframe . dispatchEvent ( new Event ( 'load' ) ) ;
3513+ spectator . detectChanges ( ) ;
3514+
3515+ expect ( spyWrite ) . toHaveBeenCalledWith (
3516+ expect . stringContaining (
3517+ `<script src="${ SDK_EDITOR_SCRIPT_SOURCE } "></script>`
3518+ )
3519+ ) ;
3520+ } ) ;
3521+
3522+ it ( 'should NOT inject the UVE script when the flag is disabled' , ( ) => {
3523+ patchState ( componentStore , {
3524+ flags : {
3525+ ...componentStore . flags ( ) ,
3526+ [ FeaturedFlags . FEATURE_FLAG_UVE_LEGACY_SCRIPT_INJECTION ] : false
3527+ }
3528+ } ) ;
3529+
3530+ const iframe = spectator . query ( byTestId ( 'iframe' ) ) as HTMLIFrameElement ;
3531+ const spyWrite = jest . spyOn ( iframe . contentDocument , 'write' ) ;
3532+
3533+ iframe . dispatchEvent ( new Event ( 'load' ) ) ;
3534+ spectator . detectChanges ( ) ;
3535+
3536+ expect ( spyWrite ) . toHaveBeenCalledWith (
3537+ expect . not . stringContaining (
3538+ `<script src="${ SDK_EDITOR_SCRIPT_SOURCE } "></script>`
3539+ )
3540+ ) ;
3541+ } ) ;
3542+
3543+ it ( 'should NOT inject the UVE script when the flag is not set' , ( ) => {
3544+ const iframe = spectator . query ( byTestId ( 'iframe' ) ) as HTMLIFrameElement ;
3545+ const spyWrite = jest . spyOn ( iframe . contentDocument , 'write' ) ;
3546+
3547+ iframe . dispatchEvent ( new Event ( 'load' ) ) ;
3548+ spectator . detectChanges ( ) ;
3549+
3550+ expect ( spyWrite ) . toHaveBeenCalledWith (
3551+ expect . not . stringContaining (
3552+ `<script src="${ SDK_EDITOR_SCRIPT_SOURCE } "></script>`
3553+ )
3554+ ) ;
3555+ } ) ;
3556+ } ) ;
3557+
34863558 describe ( 'when pageRender is undefined' , ( ) => {
34873559 beforeEach ( ( ) => {
34883560 jest . spyOn ( dotPageApiService , 'get' ) . mockReturnValue (
0 commit comments