@@ -15,6 +15,7 @@ const {
1515 isNil,
1616 getWindowLocation,
1717 getCanonicalUrl,
18+ getDocumentReferrer,
1819 dispatchEvent,
1920 createCustomEvent,
2021 hasOrderIdRecord,
@@ -215,6 +216,18 @@ describe('ConstructorIO - Utils - Helpers', () => {
215216 } ) ;
216217
217218 describe ( 'getCanonicalUrl' , ( ) => {
219+ it ( 'Should return android app referrers in a valid url structure' , ( ) => {
220+ const cleanup = jsdom ( ) ;
221+
222+ const canonicalUrl = 'android-app://com.google.android.googlequicksearchbox/' ;
223+ const canonicalEle = document . querySelector ( '[rel=canonical]' ) ;
224+ canonicalEle . setAttribute ( 'href' , canonicalUrl ) ;
225+
226+ expect ( getCanonicalUrl ( ) ) . to . equal ( 'https://com.google.android.googlequicksearchbox/' ) ;
227+
228+ cleanup ( ) ;
229+ } ) ;
230+
218231 it ( 'Should return the canonical URL from the DOM link element' , ( ) => {
219232 const cleanup = jsdom ( ) ;
220233
@@ -264,6 +277,67 @@ describe('ConstructorIO - Utils - Helpers', () => {
264277 } ) ;
265278 } ) ;
266279
280+ describe ( 'getDocumentReferrer' , ( ) => {
281+ it ( 'Should return android app referrers in a valid url structure' , ( ) => {
282+ const cleanup = jsdom ( ) ;
283+
284+ const referrerUrl = 'android-app://com.google.android.googlequicksearchbox/' ;
285+ Object . defineProperty ( document , 'referrer' , {
286+ value : referrerUrl ,
287+ configurable : true ,
288+ } ) ;
289+
290+ expect ( getDocumentReferrer ( ) ) . to . equal ( 'https://com.google.android.googlequicksearchbox/' ) ;
291+
292+ cleanup ( ) ;
293+ } ) ;
294+
295+ it ( 'Should return the referrer URL from the document' , ( ) => {
296+ const cleanup = jsdom ( ) ;
297+
298+ const referrerUrl = 'https://constructor.io/products/item' ;
299+ Object . defineProperty ( document , 'referrer' , {
300+ value : referrerUrl ,
301+ configurable : true ,
302+ } ) ;
303+
304+ expect ( getDocumentReferrer ( ) ) . to . equal ( referrerUrl ) ;
305+
306+ cleanup ( ) ;
307+ } ) ;
308+
309+ it ( 'Should return null for a relative url' , ( ) => {
310+ const cleanup = jsdom ( ) ;
311+
312+ const relativeUrl = '/products/item' ;
313+ Object . defineProperty ( document , 'referrer' , {
314+ value : relativeUrl ,
315+ configurable : true ,
316+ } ) ;
317+
318+ const result = getDocumentReferrer ( ) ;
319+ expect ( result ) . to . be . null ;
320+
321+ cleanup ( ) ;
322+ } ) ;
323+
324+ it ( 'Should return null when referrer is empty' , ( ) => {
325+ const cleanup = jsdom ( ) ;
326+
327+ Object . defineProperty ( document , 'referrer' , {
328+ value : '' ,
329+ configurable : true ,
330+ } ) ;
331+
332+ expect ( getDocumentReferrer ( ) ) . to . be . null ;
333+ cleanup ( ) ;
334+ } ) ;
335+
336+ it ( 'Should return null when not in a DOM context' , ( ) => {
337+ expect ( getDocumentReferrer ( ) ) . to . be . null ;
338+ } ) ;
339+ } ) ;
340+
267341 describe ( 'dispatchEvent' , ( ) => {
268342 it ( 'Should dispatch an event if in a DOM context' , ( ) => {
269343 const cleanup = jsdom ( ) ;
0 commit comments