|
| 1 | +var Analytics = require('analytics.js').constructor; |
| 2 | +var integration = require('analytics.js-integration'); |
| 3 | +var tester = require('analytics.js-integration-tester'); |
| 4 | +var sandbox = require('clear-env'); |
| 5 | +var Elevio = require('./'); |
| 6 | + |
| 7 | + |
| 8 | +describe('Elevio', function(){ |
| 9 | + var analytics; |
| 10 | + var elevio; |
| 11 | + var options = { |
| 12 | + accountId: 'konami' |
| 13 | + }; |
| 14 | + |
| 15 | + beforeEach(function(){ |
| 16 | + analytics = new Analytics(); |
| 17 | + elevio = new Elevio(options); |
| 18 | + analytics.use(Elevio); |
| 19 | + analytics.use(tester); |
| 20 | + analytics.add(elevio); |
| 21 | + }); |
| 22 | + |
| 23 | + afterEach(function(){ |
| 24 | + analytics.restore(); |
| 25 | + analytics.reset(); |
| 26 | + elevio.reset(); |
| 27 | + sandbox(); |
| 28 | + }); |
| 29 | + |
| 30 | + it('should have the right settings', function(){ |
| 31 | + analytics.compare(Elevio, integration('Elevio') |
| 32 | + .assumesPageview() |
| 33 | + .global('_elev') |
| 34 | + .option('accountId', '')); |
| 35 | + }); |
| 36 | + |
| 37 | + describe('before loading', function(){ |
| 38 | + beforeEach(function(){ |
| 39 | + analytics.stub(window, '_elev'); |
| 40 | + analytics.stub(elevio, 'load'); |
| 41 | + }); |
| 42 | + describe('#initialize', function(){ |
| 43 | + it('should create window._elev', function(){ |
| 44 | + analytics.initialize(); |
| 45 | + analytics.page(); |
| 46 | + analytics.assert(window._elev instanceof Object); |
| 47 | + }); |
| 48 | + it('should call #load', function(){ |
| 49 | + analytics.initialize(); |
| 50 | + analytics.page(); |
| 51 | + analytics.called(elevio.load); |
| 52 | + }); |
| 53 | + }); |
| 54 | + }); |
| 55 | + |
| 56 | + describe('loading', function(){ |
| 57 | + it('should load', function(done){ |
| 58 | + analytics.load(elevio, done); |
| 59 | + }); |
| 60 | + }); |
| 61 | + |
| 62 | + describe('after loading', function(){ |
| 63 | + beforeEach(function(done){ |
| 64 | + analytics.once('ready', done); |
| 65 | + analytics.initialize(); |
| 66 | + analytics.page(); |
| 67 | + }); |
| 68 | + |
| 69 | + describe('#identify', function(){ |
| 70 | + beforeEach(function(){ |
| 71 | + // TODO: stub the integration global api. |
| 72 | + // For example: |
| 73 | + // analytics.stub(window.api, 'identify'); |
| 74 | + }); |
| 75 | + |
| 76 | + it('should send an email', function(){ |
| 77 | + analytics.identify('id', { email: '[email protected]' }); |
| 78 | + analytics.assert(window._elev.user.email === '[email protected]'); |
| 79 | + }); |
| 80 | + |
| 81 | + it('should send a full name', function(){ |
| 82 | + analytics.identify('id', { name: 'Test Person' }); |
| 83 | + analytics.assert(window._elev.user.name === 'Test Person'); |
| 84 | + }); |
| 85 | + |
| 86 | + it('should not send name', function(){ |
| 87 | + analytics.identify('id'); |
| 88 | + analytics.assert(window._elev.user.name === undefined); |
| 89 | + }); |
| 90 | + |
| 91 | + // TODO seems Identify.prototype.name returns nothing when no last name is sent |
| 92 | + // it('should send a first name', function(){ |
| 93 | + // analytics.identify(undefined, { firstName: 'Test' }); |
| 94 | + // analytics.assert(window._elev.user.name === 'Test'); |
| 95 | + // }); |
| 96 | + |
| 97 | + it('should send a combined name', function(){ |
| 98 | + analytics.identify('id', { firstName: 'Test', lastName: 'Person' }); |
| 99 | + analytics.assert(window._elev.user.name === 'Test Person'); |
| 100 | + }); |
| 101 | + |
| 102 | + it('should send their plan', function(){ |
| 103 | + analytics.identify('id', { plan: 'gold' }); |
| 104 | + analytics.assert(window._elev.user.plan instanceof Array); |
| 105 | + analytics.assert(window._elev.user.plan[0] === 'gold'); |
| 106 | + }); |
| 107 | + }); |
| 108 | + }); |
| 109 | +}); |
0 commit comments