1
1
import * as utils from '../../../src/utils.js' ;
2
2
import { loadExternalScript } from '../../../src/adloader.js' ;
3
- import {
3
+ import * as geoedgeRtdModule from '../../../modules/geoedgeRtdProvider.js' ;
4
+ import { server } from '../../../test/mocks/xhr.js' ;
5
+ import * as events from '../../../src/events.js' ;
6
+ import CONSTANTS from '../../../src/constants.json' ;
7
+
8
+ let {
4
9
geoedgeSubmodule,
5
10
getClientUrl,
6
11
getInPageUrl,
7
12
htmlPlaceholder,
8
13
setWrapper,
9
14
getMacros,
10
- wrapper ,
11
- WRAPPER_URL
12
- } from '../../../modules/geoedgeRtdProvider.js' ;
13
- import { server } from '../../../test/mocks/xhr.js' ;
14
- import * as events from '../../../src/events.js' ;
15
- import CONSTANTS from '../../../src/constants.json' ;
15
+ WRAPPER_URL ,
16
+ preloadClient,
17
+ markAsLoaded
18
+ } = geoedgeRtdModule ;
16
19
17
20
let key = '123123123' ;
18
21
function makeConfig ( gpt ) {
@@ -65,13 +68,11 @@ describe('Geoedge RTD module', function () {
65
68
} ) ;
66
69
} ) ;
67
70
describe ( 'init' , function ( ) {
68
- let insertElementStub ;
69
-
70
71
before ( function ( ) {
71
- insertElementStub = sinon . stub ( utils , 'insertElement ' ) ;
72
+ sinon . spy ( geoedgeRtdModule , 'preloadClient ' ) ;
72
73
} ) ;
73
74
after ( function ( ) {
74
- utils . insertElement . restore ( ) ;
75
+ geoedgeRtdModule . preloadClient . restore ( ) ;
75
76
} ) ;
76
77
it ( 'should return false when missing params or key' , function ( ) {
77
78
let missingParams = geoedgeSubmodule . init ( { } ) ;
@@ -87,14 +88,13 @@ describe('Geoedge RTD module', function () {
87
88
let isWrapperRequest = request && request . url && request . url && request . url === WRAPPER_URL ;
88
89
expect ( isWrapperRequest ) . to . equal ( true ) ;
89
90
} ) ;
90
- it ( 'should preload the client' , function ( ) {
91
- let isLinkPreloadAsScript = arg => arg . tagName === 'LINK' && arg . rel === 'preload' && arg . as === 'script' && arg . href === getClientUrl ( key ) ;
92
- expect ( insertElementStub . calledWith ( sinon . match ( isLinkPreloadAsScript ) ) ) . to . equal ( true ) ;
91
+ it ( 'should call preloadClient' , function ( ) {
92
+ expect ( preloadClient . called ) ;
93
93
} ) ;
94
94
it ( 'should emit billable events with applicable winning bids' , function ( done ) {
95
95
let counter = 0 ;
96
96
events . on ( CONSTANTS . EVENTS . BILLABLE_EVENT , function ( event ) {
97
- if ( event . vendor === 'geoedge' && event . type === 'impression' ) {
97
+ if ( event . vendor === geoedgeSubmodule . name && event . type === 'impression' ) {
98
98
counter += 1 ;
99
99
}
100
100
expect ( counter ) . to . equal ( 1 ) ;
@@ -104,18 +104,35 @@ describe('Geoedge RTD module', function () {
104
104
} ) ;
105
105
it ( 'should load the in page code when gpt params is true' , function ( ) {
106
106
geoedgeSubmodule . init ( makeConfig ( true ) ) ;
107
- let isInPageUrl = arg => arg == getInPageUrl ( key ) ;
107
+ let isInPageUrl = arg => arg === getInPageUrl ( key ) ;
108
108
expect ( loadExternalScript . calledWith ( sinon . match ( isInPageUrl ) ) ) . to . equal ( true ) ;
109
109
} ) ;
110
110
it ( 'should set the window.grumi config object when gpt params is true' , function ( ) {
111
111
let hasGrumiObj = typeof window . grumi === 'object' ;
112
112
expect ( hasGrumiObj && window . grumi . key === key && window . grumi . fromPrebid ) . to . equal ( true ) ;
113
113
} ) ;
114
114
} ) ;
115
+ describe ( 'preloadClient' , function ( ) {
116
+ let iframe ;
117
+ preloadClient ( key ) ;
118
+ let loadExternalScriptCall = loadExternalScript . getCall ( 0 ) ;
119
+ it ( 'should create an invisible iframe and insert it to the DOM' , function ( ) {
120
+ iframe = document . getElementById ( 'grumiFrame' ) ;
121
+ expect ( iframe && iframe . style . display === 'none' ) ;
122
+ } ) ;
123
+ it ( 'should assign params object to the iframe\'s window' , function ( ) {
124
+ let grumi = iframe . contentWindow . grumi ;
125
+ expect ( grumi . key ) . to . equal ( key ) ;
126
+ } ) ;
127
+ it ( 'should preload the client into the iframe' , function ( ) {
128
+ let isClientUrl = arg => arg === getClientUrl ( key ) ;
129
+ expect ( loadExternalScriptCall . calledWithMatch ( isClientUrl ) ) . to . equal ( true ) ;
130
+ } ) ;
131
+ } ) ;
115
132
describe ( 'setWrapper' , function ( ) {
116
133
it ( 'should set the wrapper' , function ( ) {
117
134
setWrapper ( mockWrapper ) ;
118
- expect ( wrapper ) . to . equal ( mockWrapper ) ;
135
+ expect ( geoedgeRtdModule . wrapper ) . to . equal ( mockWrapper ) ;
119
136
} ) ;
120
137
} ) ;
121
138
describe ( 'getMacros' , function ( ) {
0 commit comments