1- import { type DOMWindow , JSDOM , ResourceLoader } from 'jsdom' ;
21import CoreModule from 'src/core/CoreModule' ;
32import { SubscriptionModel } from 'src/core/models/SubscriptionModel' ;
43import { ModelChangeTags } from 'src/core/types/models' ;
@@ -14,15 +13,8 @@ import OneSignal from '../../../src/onesignal/OneSignal';
1413import { ONESIGNAL_EVENTS } from '../../../src/onesignal/OneSignalEvents' ;
1514import UserNamespace from '../../../src/onesignal/UserNamespace' ;
1615import Context from '../../../src/page/models/Context' ;
17- import { getSlidedownElement } from '../../../src/page/slidedown/SlidedownElement' ;
1816import Emitter from '../../../src/shared/libraries/Emitter' ;
19- import { CUSTOM_LINK_CSS_CLASSES } from '../../../src/shared/slidedown/constants' ;
20- import {
21- DEFAULT_USER_AGENT ,
22- DEVICE_OS ,
23- ONESIGNAL_ID ,
24- SUB_ID_3 ,
25- } from '../../constants' ;
17+ import { DEVICE_OS , ONESIGNAL_ID , SUB_ID_3 } from '../../constants' ;
2618import MockNotification from '../mocks/MockNotification' ;
2719import TestContext from './TestContext' ;
2820import { type TestEnvironmentConfig } from './TestEnvironment' ;
@@ -60,55 +52,6 @@ export function stubNotification(config: TestEnvironmentConfig) {
6052 }
6153}
6254
63- export async function stubDomEnvironment ( config : TestEnvironmentConfig ) {
64- if ( ! config ) {
65- config = { } ;
66- }
67-
68- let url = 'https://localhost:3001/webpush/sandbox?https=1' ;
69-
70- if ( config . url ) {
71- url = config . url . toString ( ) ;
72- global . location = url ;
73- }
74-
75- let html = '<!doctype html><html><head></head><body></body></html>' ;
76-
77- if ( config . addPrompts ) {
78- html = `<!doctype html><html><head>\
79- <div class="${ CUSTOM_LINK_CSS_CLASSES . containerClass } "></div>\
80- <div class="${ CUSTOM_LINK_CSS_CLASSES . containerClass } "></div>\
81- </head><body>\
82- ${ getSlidedownElement ( { } ) . outerHTML } </div></body></html>` ;
83- }
84-
85- const resourceLoader = new ResourceLoader ( {
86- userAgent : config . userAgent
87- ? config . userAgent . toString ( )
88- : DEFAULT_USER_AGENT . toString ( ) ,
89- } ) ;
90-
91- // global document object must be defined for `getSlidedownElement` to work correctly.
92- // this line initializes the document object
93- const dom = new JSDOM ( html , {
94- resources : resourceLoader ,
95- url : url ,
96- contentType : 'text/html' ,
97- runScripts : 'dangerously' ,
98- pretendToBeVisual : true ,
99- } ) ;
100-
101- const windowDef = dom . window ;
102- ( windowDef as any ) . location = url ;
103-
104- const windowTop : DOMWindow = windowDef ;
105- dom . reconfigure ( { url, windowTop } ) ;
106- global . window = windowDef ;
107- global . window . isSecureContext = true ;
108- global . document = windowDef . document ;
109- return dom ;
110- }
111-
11255export const createPushSub = ( {
11356 id = SUB_ID_3 ,
11457 token = 'push-token' ,
0 commit comments