@@ -40,11 +40,16 @@ const mockDocument = {
40
40
} ;
41
41
42
42
// creates mock postmessage response from prebid's native.js:getAssetMessage
43
- function createResponder ( assets , url , template ) {
43
+ function createResponder ( assets , url , template , clickUrlUnesc = '' ) {
44
44
return function ( type , listener ) {
45
45
if ( type !== 'message' ) { return ; }
46
46
47
- const data = { message : 'assetResponse' , adId : AD_ID , assets, adTemplate :template , rendererUrl :url } ;
47
+ const data = {
48
+ message : 'assetResponse' ,
49
+ adId : AD_ID , assets,
50
+ adTemplate :template ,
51
+ rendererUrl :url ,
52
+ } ;
48
53
listener ( { data : JSON . stringify ( data ) , origin : ORIGIN } ) ;
49
54
} ;
50
55
}
@@ -86,8 +91,11 @@ function generateRenderer(assets) {
86
91
describe ( 'nativeAssetManager' , ( ) => {
87
92
let win ;
88
93
89
- function makeManager ( ) {
90
- return newNativeAssetManager ( win , ORIGIN ) ;
94
+ function makeManager ( args ) {
95
+ return newNativeAssetManager ( win , {
96
+ pubUrl : ORIGIN ,
97
+ ...args
98
+ } ) ;
91
99
}
92
100
93
101
beforeEach ( ( ) => {
@@ -578,4 +586,64 @@ describe('nativeAssetManager', () => {
578
586
expect ( win . document . body . style . width ) . to . equal ( '600px' ) ;
579
587
} ) ;
580
588
} ) ;
589
+
590
+ describe ( 'GAM macro %%CLICK_URL_UNESC%%' , ( ) => {
591
+ it ( "should remove %%CLICK_URL_UNESC%% if there's no variable set" , ( ) => {
592
+ const html = `<script>
593
+ let nativeTag = {};
594
+ nativeTag.adTemplate = "<div class=\"sponsored-post\">\r\n <div class=\"thumbnail\"><\/div>\r\n <div class=\"content\">\r\n <h1>\r\n <a href=\"%%CLICK_URL_UNESC%%##hb_native_linkurl##\" target=\"_blank\" class=\"pb-click\">##hb_native_title##<\/a>\r\n <\/h1>\r\n <p>##hb_native_body##<\/p>\r\n \t<div class=\"attribution\">\r\n \t<img class=\"pb-icon\" src=\"##hb_native_image##\" alt=\"icon\" height=\"150\" width=\"50\">\r\n \t\r\n \t<\/div>\r\n\t<\/div>\r\n<\/div>";
595
+ nativeTag.pubUrl = "https://www.url.com";
596
+ nativeTag.adId = "` + AD_ID + `";
597
+ nativeTag.requestAllAssets = true;
598
+ window.pbNativeTag.renderNativeAd(nativeTag);
599
+ </script>` ;
600
+ win . pbNativeData = {
601
+ pubUrl : 'https://www.url.com' ,
602
+ adId : AD_ID ,
603
+ adTemplate : '<div class=\"sponsored-post\">\r\n <div class=\"thumbnail\"><\/div>\r\n <div class=\"content\">\r\n <h1>\r\n <a href=\"%%CLICK_URL_UNESC%%##hb_native_linkurl##\" target=\"_blank\" class=\"pb-click\">##hb_native_title##<\/a>\r\n <\/h1>\r\n <p>##hb_native_body##<\/p>\r\n \t<div class=\"attribution\">\r\n \t<img class=\"pb-icon\" src=\"##hb_native_image##\" alt=\"icon\" height=\"150\" width=\"50\">\r\n \t\r\n \t<\/div>\r\n\t<\/div>\r\n<\/div>'
604
+ } ;
605
+
606
+ win . document . body . innerHTML = html ;
607
+ win . addEventListener = createResponder ( [
608
+ { key : 'body' , value : 'Body content' } ,
609
+ { key : 'title' , value : 'new value' } ,
610
+ { key : 'clickUrl' , value : 'http://www.example.com' } ,
611
+ { key : 'image' , value : 'http://www.image.com/picture.jpg' } ,
612
+ ] ) ;
613
+
614
+ const nativeAssetManager = makeManager ( ) ;
615
+ nativeAssetManager . loadAssets ( AD_ID ) ;
616
+
617
+ expect ( win . document . body . innerHTML ) . to . include ( `<a href="http://www.example.com" target="_blank" class="pb-click">new value</a>` ) ;
618
+ } ) ;
619
+
620
+ it ( "should substitute %%CLICK_URL_UNESC%% with clickUrlUnesc value" , ( ) => {
621
+ const html = `<script>
622
+ let nativeTag = {};
623
+ nativeTag.adTemplate = "<div class=\"sponsored-post\">\r\n <div class=\"thumbnail\"><\/div>\r\n <div class=\"content\">\r\n <h1>\r\n <a href=\"%%CLICK_URL_UNESC%%##hb_native_linkurl##\" target=\"_blank\" class=\"pb-click\">##hb_native_title##<\/a>\r\n <\/h1>\r\n <p>##hb_native_body##<\/p>\r\n \t<div class=\"attribution\">\r\n \t<img class=\"pb-icon\" src=\"##hb_native_image##\" alt=\"icon\" height=\"150\" width=\"50\">\r\n \t\r\n \t<\/div>\r\n\t<\/div>\r\n<\/div>";
624
+ nativeTag.pubUrl = "https://www.url.com";
625
+ nativeTag.adId = "` + AD_ID + `";
626
+ nativeTag.requestAllAssets = true;
627
+ window.pbNativeTag.renderNativeAd(nativeTag);
628
+ </script>` ;
629
+ win . pbNativeData = {
630
+ pubUrl : 'https://www.url.com' ,
631
+ adId : AD_ID ,
632
+ adTemplate : '<div class=\"sponsored-post\">\r\n <div class=\"thumbnail\"><\/div>\r\n <div class=\"content\">\r\n <h1>\r\n <a href=\"%%CLICK_URL_UNESC%%##hb_native_linkurl##\" target=\"_blank\" class=\"pb-click\">##hb_native_title##<\/a>\r\n <\/h1>\r\n <p>##hb_native_body##<\/p>\r\n \t<div class=\"attribution\">\r\n \t<img class=\"pb-icon\" src=\"##hb_native_image##\" alt=\"icon\" height=\"150\" width=\"50\">\r\n \t\r\n \t<\/div>\r\n\t<\/div>\r\n<\/div>' ,
633
+ } ;
634
+
635
+ win . document . body . innerHTML = html ;
636
+ win . addEventListener = createResponder ( [
637
+ { key : 'body' , value : 'Body content' } ,
638
+ { key : 'title' , value : 'new value' } ,
639
+ { key : 'clickUrl' , value : 'http://www.example.com' } ,
640
+ { key : 'image' , value : 'http://www.image.com/picture.jpg' } ,
641
+ ] , null , null , ) ;
642
+
643
+ const nativeAssetManager = makeManager ( { clickUrlUnesc : 'https://will.redirect/?to=' } ) ;
644
+ nativeAssetManager . loadAssets ( AD_ID ) ;
645
+
646
+ expect ( win . document . body . innerHTML ) . to . include ( `<a href="https://will.redirect/?to=http://www.example.com" target="_blank" class="pb-click">new value</a>` ) ;
647
+ } ) ;
648
+ } ) ;
581
649
} ) ;
0 commit comments