|
| 1 | +var Analytics = require('analytics.js').constructor; |
| 2 | +var integration = require('analytics.js-integration'); |
| 3 | +var sandbox = require('clear-env'); |
| 4 | +var tester = require('analytics.js-integration-tester'); |
| 5 | +var ScratchIt = require('./'); |
| 6 | + |
| 7 | +describe('ScratchIt', function() { |
| 8 | + var analytics; |
| 9 | + var scratchIt; |
| 10 | + var options = { |
| 11 | + trkId: 'foo' |
| 12 | + }; |
| 13 | + |
| 14 | + beforeEach(function() { |
| 15 | + analytics = new Analytics(); |
| 16 | + scratchIt = new ScratchIt(options); |
| 17 | + analytics.use(ScratchIt); |
| 18 | + analytics.use(tester); |
| 19 | + analytics.add(scratchIt); |
| 20 | + }); |
| 21 | + |
| 22 | + afterEach(function() { |
| 23 | + analytics.restore(); |
| 24 | + analytics.reset(); |
| 25 | + scratchIt.reset(); |
| 26 | + sandbox(); |
| 27 | + }); |
| 28 | + |
| 29 | + it('should have the right settings', function() { |
| 30 | + analytics.compare(ScratchIt, integration('Scratch-it Analytics') |
| 31 | + .global('ScratchIt') |
| 32 | + .option('trkId', '')); |
| 33 | + }); |
| 34 | + |
| 35 | + describe('before loading', function() { |
| 36 | + beforeEach(function() { |
| 37 | + analytics.stub(scratchIt, 'load'); |
| 38 | + }); |
| 39 | + |
| 40 | + describe('#initialize', function() { |
| 41 | + it('should create the window.ScratchIt object', function() { |
| 42 | + analytics.assert(window.ScratchIt === undefined); |
| 43 | + analytics.initialize(); |
| 44 | + analytics.assert(window.ScratchIt); |
| 45 | + }); |
| 46 | + |
| 47 | + it('should call #load', function() { |
| 48 | + analytics.initialize(); |
| 49 | + analytics.called(scratchIt.load); |
| 50 | + }); |
| 51 | + }); |
| 52 | + }); |
| 53 | + |
| 54 | + describe('after loading', function() { |
| 55 | + beforeEach(function(done) { |
| 56 | + analytics.once('ready', done); |
| 57 | + analytics.initialize(); |
| 58 | + }); |
| 59 | + |
| 60 | + describe('#track', function() { |
| 61 | + beforeEach(function() { |
| 62 | + analytics.stub(window.ScratchIt, 'track'); |
| 63 | + }); |
| 64 | + |
| 65 | + it('should send an event with default type', function() { |
| 66 | + analytics.track('Goal Reached'); |
| 67 | + analytics.called(window.ScratchIt.track, 'track', 'Goal Reached', {}); |
| 68 | + }); |
| 69 | + |
| 70 | + it('should send an event', function() { |
| 71 | + analytics.track('Started Scratching', { event_type: 'scratching_page' }); |
| 72 | + analytics.called(window.ScratchIt.track, 'scratching_page', 'Started Scratching', {}); |
| 73 | + }); |
| 74 | + |
| 75 | + it('should send an event with properties', function() { |
| 76 | + analytics.track('Started Scratching', { event_type: 'scratching_page', foo: 'bar' }); |
| 77 | + analytics.called(window.ScratchIt.track, 'scratching_page', 'Started Scratching', { foo: 'bar' }); |
| 78 | + }); |
| 79 | + }); |
| 80 | + }); |
| 81 | +}); |
0 commit comments