@@ -12,19 +12,113 @@ const basicConfig = {
12
12
pixelId : '12567839' ,
13
13
eventToEventIdMap : [
14
14
{ from : 'Sign Up' , to : '123' } ,
15
- { to : 'Lead ' , from : '1234 ' } ,
15
+ { from : 'Custom ' , to : '987 ' } ,
16
16
{ from : 'Page View' , to : '456' } ,
17
17
{ from : 'Page View' , to : '467' } ,
18
18
{ from : 'product_added' , to : '789' } ,
19
19
] ,
20
20
} ;
21
21
22
22
describe ( 'XPixel init tests' , ( ) => {
23
+ beforeAll ( ( ) => {
24
+ // Add a dummy script as it is required by the init script
25
+ const scriptElement = document . createElement ( 'script' ) ;
26
+ scriptElement . type = 'text/javascript' ;
27
+ scriptElement . id = 'dummyScript' ;
28
+ const headElements = document . getElementsByTagName ( 'head' ) ;
29
+ headElements [ 0 ] . insertBefore ( scriptElement , headElements [ 0 ] . firstChild ) ;
30
+ } ) ;
31
+
23
32
let xPixel ;
24
33
25
34
test ( 'Testing init call of XPixel' , ( ) => {
26
35
xPixel = new XPixel ( basicConfig , { loglevel : 'debug' } , destinationInfo ) ;
27
36
xPixel . init ( ) ;
28
- expect ( typeof window . twq ) . toBe ( 'object' ) ;
37
+ expect ( typeof window . twq ) . toBe ( 'function' ) ;
38
+ } ) ;
39
+ } ) ;
40
+
41
+ describe ( 'xPixel page' , ( ) => {
42
+ let xPixel ;
43
+ beforeEach ( ( ) => {
44
+ xPixel = new XPixel ( basicConfig , { loglevel : 'debug' } ) ;
45
+ xPixel . init ( ) ;
46
+ window . twq = jest . fn ( ) ;
47
+ } ) ;
48
+
49
+ test ( 'send pageview' , ( ) => {
50
+ xPixel . page ( {
51
+ message : {
52
+ context : { } ,
53
+ properties : {
54
+ category : 'test cat' ,
55
+ path : '/test' ,
56
+ url : 'http://localhost' ,
57
+ referrer : '' ,
58
+ title : 'test page' ,
59
+ testDimension : 'abc' ,
60
+ value : 35.0 ,
61
+ currency : 'GBP' ,
62
+ } ,
63
+ } ,
64
+ } ) ;
65
+ expect ( window . twq . mock . calls [ 0 ] ) . toEqual ( [ 'event' , '456' , { currency : 'GBP' , value : 35 } ] ) ;
66
+ expect ( window . twq . mock . calls [ 1 ] ) . toEqual ( [ 'event' , '467' , { currency : 'GBP' , value : 35 } ] ) ;
67
+ } ) ;
68
+ } ) ;
69
+
70
+ describe ( 'XPixel Track event' , ( ) => {
71
+ let xPixel ;
72
+ beforeEach ( ( ) => { } ) ;
73
+ test ( 'Testing Track Simple Event' , ( ) => {
74
+ xPixel = new XPixel ( basicConfig , { loglevel : 'DEBUG' } , destinationInfo ) ;
75
+ xPixel . init ( ) ;
76
+ window . twq = jest . fn ( ) ;
77
+ xPixel . track ( {
78
+ message : {
79
+ context : { } ,
80
+ event : 'Custom' ,
81
+ properties : {
82
+ customProp : 'testProp' ,
83
+ order_id : 'transactionId' ,
84
+ value : 35.0 ,
85
+ coupon : 'APPARELSALE' ,
86
+ currency : 'GBP' ,
87
+ products : [
88
+ {
89
+ customPropProd : 'testPropProd' ,
90
+ product_id : 'abc' ,
91
+ category : 'Merch' ,
92
+ name : 'Food/Drink' ,
93
+ brand : '' ,
94
+ variant : 'Extra topped' ,
95
+ price : 3.0 ,
96
+ quantity : 2 ,
97
+ currency : 'GBP' ,
98
+ position : 1 ,
99
+ value : 6.0 ,
100
+ typeOfProduct : 'Food' ,
101
+ } ,
102
+ ] ,
103
+ } ,
104
+ } ,
105
+ } ) ;
106
+ expect ( window . twq . mock . calls [ 0 ] ) . toEqual ( [
107
+ 'event' ,
108
+ '987' ,
109
+ {
110
+ currency : 'GBP' ,
111
+ value : 35 ,
112
+ contents : [
113
+ {
114
+ content_type : 'product' ,
115
+ content_id : 'abc' ,
116
+ content_name : 'Food/Drink' ,
117
+ price : 3 ,
118
+ num_items : 2 ,
119
+ } ,
120
+ ] ,
121
+ } ,
122
+ ] ) ;
29
123
} ) ;
30
124
} ) ;
0 commit comments