-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f3f4271
commit 3636606
Showing
5 changed files
with
141 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import assert from 'assert'; | ||
import EventManager from './../../src/EventManager'; | ||
import fireEvent from './../functions/fireEvent'; | ||
|
||
describe('CustomEvents', () => { | ||
|
||
let _eventManager; | ||
let _digitalData; | ||
let _ddListener; | ||
|
||
let btn; | ||
let div; | ||
|
||
beforeEach(() => { | ||
_digitalData = { | ||
page: { | ||
categoryId: 1 | ||
}, | ||
type: 'product', | ||
events: [] | ||
}; | ||
_ddListener = []; | ||
_eventManager = new EventManager(_digitalData, _ddListener); | ||
_eventManager.setSendViewedPageEvent(true); | ||
|
||
// create button | ||
btn = document.createElement('button'); | ||
const t = document.createTextNode('click me'); | ||
btn.appendChild(t); | ||
btn.className = 'test-btn'; | ||
|
||
// create div | ||
div = document.createElement('div'); | ||
div.appendChild(btn); | ||
div.id = 'test-div'; | ||
|
||
document.body.appendChild(div); | ||
}); | ||
|
||
afterEach(() => { | ||
if (_eventManager) { | ||
_eventManager.reset(); | ||
_eventManager = undefined; | ||
} | ||
|
||
div.remove(); | ||
_digitalData.events = []; | ||
}); | ||
|
||
it('should track custom events', (done) => { | ||
_eventManager.import([ | ||
{ | ||
name: 'Event: Viewed Product Detail', | ||
trigger: 'event', | ||
event: 'Viewed Page', | ||
handler: function() { | ||
return { | ||
name: 'Viewed Product Detail', | ||
} | ||
} | ||
}, | ||
{ | ||
name: 'Event: Clicked Product', | ||
trigger: 'click', | ||
cssSelector: '.test-btn', | ||
handler: function() { | ||
return { | ||
name: 'Clicked Product', | ||
}; | ||
}, | ||
}, | ||
{ | ||
name: 'Test Name', | ||
trigger: 'impression', | ||
cssSelector: '.ddl_product', | ||
handler: function() { | ||
return { | ||
name: 'Viewed Product', | ||
}; | ||
} | ||
} | ||
]); | ||
_eventManager.initialize(); | ||
|
||
fireEvent(btn, 'click'); | ||
|
||
setTimeout(() => { | ||
assert.equal(_digitalData.events[0].name, 'Viewed Page'); | ||
assert.equal(_digitalData.events[1].name, 'Viewed Product Detail'); | ||
assert.equal(_digitalData.events[2].name, 'Clicked Product'); | ||
done(); | ||
}, 10); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters