|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +var Analytics = require('@segment/analytics.js-core').constructor; |
| 4 | +var integration = require('@segment/analytics.js-integration'); |
| 5 | +var sandbox = require('@segment/clear-env'); |
| 6 | +var tester = require('@segment/analytics.js-integration-tester'); |
| 7 | +var Userlike = require('../lib/'); |
| 8 | + |
| 9 | +describe('Userlike', function() { |
| 10 | + var userlike; |
| 11 | + var analytics; |
| 12 | + var options = { |
| 13 | + secretKey: 'c3e839df9320d85ff590d07477c32cff837c02d7d4acaa18af91205800606b6c', |
| 14 | + listen: true |
| 15 | + }; |
| 16 | + |
| 17 | + beforeEach(function() { |
| 18 | + analytics = new Analytics(); |
| 19 | + userlike = new Userlike(options); |
| 20 | + analytics.use(Userlike); |
| 21 | + analytics.use(tester); |
| 22 | + analytics.add(userlike); |
| 23 | + }); |
| 24 | + |
| 25 | + afterEach(function() { |
| 26 | + analytics.restore(); |
| 27 | + analytics.reset(); |
| 28 | + userlike.reset(); |
| 29 | + sandbox(); |
| 30 | + }); |
| 31 | + |
| 32 | + it('should have the right settings', function() { |
| 33 | + analytics.compare(Userlike, integration('Userlike') |
| 34 | + .assumesPageview() |
| 35 | + .global('userlikeConfig') |
| 36 | + .global('userlikeData') |
| 37 | + .option('secretKey', '')); |
| 38 | + }); |
| 39 | + |
| 40 | + describe('before loading', function() { |
| 41 | + beforeEach(function() { |
| 42 | + analytics.identify({ email: 'email', name: 'name' }); |
| 43 | + analytics.stub(userlike, 'load'); |
| 44 | + }); |
| 45 | + |
| 46 | + describe('#initialize', function() { |
| 47 | + it('should create window.userlikeData', function() { |
| 48 | + analytics.initialize(); |
| 49 | + analytics.page(); |
| 50 | + analytics.deepEqual(window.userlikeData, { |
| 51 | + custom: { |
| 52 | + segmentio: { |
| 53 | + secretKey: options.secretKey, |
| 54 | + listen: true, |
| 55 | + visitor: { |
| 56 | + name: 'name', |
| 57 | + email: 'email' |
| 58 | + } |
| 59 | + } |
| 60 | + } |
| 61 | + }); |
| 62 | + }); |
| 63 | + |
| 64 | + it('should call #load', function() { |
| 65 | + analytics.initialize(); |
| 66 | + analytics.page(); |
| 67 | + analytics.called(userlike.load); |
| 68 | + }); |
| 69 | + }); |
| 70 | + }); |
| 71 | + |
| 72 | + describe('loading', function() { |
| 73 | + it('should load', function(done) { |
| 74 | + analytics.load(userlike, done); |
| 75 | + }); |
| 76 | + }); |
| 77 | + |
| 78 | + describe('after loading', function() { |
| 79 | + beforeEach(function(done) { |
| 80 | + analytics.once('ready', done); |
| 81 | + analytics.initialize(); |
| 82 | + analytics.page(); |
| 83 | + }); |
| 84 | + |
| 85 | + // TODO: The way Userlike's API is structured makes starting it |
| 86 | + // programmatically pretty hard. Revisit these tests |
| 87 | + xdescribe('#listen', function() { |
| 88 | + beforeEach(function() { |
| 89 | + /* |
| 90 | + analytics.once('ready', done); |
| 91 | + analytics.initialize(); |
| 92 | + analytics.stub(analytics, 'track'); |
| 93 | + */ |
| 94 | + }); |
| 95 | + |
| 96 | + it('should send a chat started event', function() { |
| 97 | + /* |
| 98 | + setTimeout(function() { |
| 99 | + userlikeStartChat(); |
| 100 | + }, 1000); |
| 101 | + setTimeout(function() { |
| 102 | + analytics.called(analytics.track, 'Live Chat Conversation Started', {}, { context: { integration: { name: 'snapengage', version: '1.0.0' }}}); |
| 103 | + }, 2000); |
| 104 | + */ |
| 105 | + }); |
| 106 | + |
| 107 | + it('should send a chat sent event', function() { |
| 108 | + /* |
| 109 | + setTimeout(function() { |
| 110 | + userlikeSendEvent(); |
| 111 | + }, 1000); |
| 112 | + setTimeout(function() { |
| 113 | + analytics.called(analytics.track, 'Live Chat Message Sent', {}, { context: { integration: { name: 'snapengage', version: '1.0.0' }}}); |
| 114 | + }, 2000); |
| 115 | + */ |
| 116 | + }); |
| 117 | + |
| 118 | + it('should send a chat received event', function() { |
| 119 | + /* |
| 120 | + setTimeout(function() { |
| 121 | + userlikeSendEvent(); |
| 122 | + }, 1000); |
| 123 | + setTimeout(function() { |
| 124 | + analytics.called(analytics.track, 'Live Chat Message Received', {}, { context: { integration: { name: 'snapengage', version: '1.0.0' }}}); |
| 125 | + }, 2000); |
| 126 | + */ |
| 127 | + }); |
| 128 | + |
| 129 | + it('should send a chat ended event', function() { |
| 130 | + /* |
| 131 | + setTimeout(function() { |
| 132 | + userlikeQuitChat(); |
| 133 | + }, 1000); |
| 134 | + setTimeout(function() { |
| 135 | + analytics.called(analytics.track, 'Live Chat Conversation Ended', {}, { context: { integration: { name: 'snapengage', version: '1.0.0' }}}); |
| 136 | + }, 2000); |
| 137 | + */ |
| 138 | + }); |
| 139 | + }); |
| 140 | + }); |
| 141 | +}); |
0 commit comments