|
| 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 Navilytics = require('../lib/'); |
| 8 | + |
| 9 | +describe('Navilytics', function() { |
| 10 | + var analytics; |
| 11 | + var navilytics; |
| 12 | + var settings; |
| 13 | + |
| 14 | + beforeEach(function() { |
| 15 | + settings = { |
| 16 | + memberId: '1042', |
| 17 | + projectId: '73' |
| 18 | + }; |
| 19 | + analytics = new Analytics(); |
| 20 | + navilytics = new Navilytics(settings); |
| 21 | + analytics.use(Navilytics); |
| 22 | + analytics.use(tester); |
| 23 | + analytics.add(navilytics); |
| 24 | + }); |
| 25 | + |
| 26 | + afterEach(function() { |
| 27 | + analytics.restore(); |
| 28 | + analytics.reset(); |
| 29 | + navilytics.reset(); |
| 30 | + sandbox(); |
| 31 | + }); |
| 32 | + |
| 33 | + it('should have the right settings', function() { |
| 34 | + analytics.compare(Navilytics, integration('Navilytics') |
| 35 | + .assumesPageview() |
| 36 | + .global('__nls') |
| 37 | + .option('memberId', '') |
| 38 | + .option('projectId', '')); |
| 39 | + }); |
| 40 | + |
| 41 | + describe('before loading', function() { |
| 42 | + beforeEach(function() { |
| 43 | + analytics.stub(navilytics, 'load'); |
| 44 | + }); |
| 45 | + |
| 46 | + describe('#initialize', function() { |
| 47 | + it('should call #load', function() { |
| 48 | + analytics.initialize(); |
| 49 | + analytics.page(); |
| 50 | + analytics.called(navilytics.load); |
| 51 | + }); |
| 52 | + |
| 53 | + it('should create window.__nls', function() { |
| 54 | + analytics.assert(window.__nls === undefined); |
| 55 | + analytics.initialize(); |
| 56 | + analytics.page(); |
| 57 | + analytics.deepEqual(window.__nls, []); |
| 58 | + }); |
| 59 | + }); |
| 60 | + }); |
| 61 | + |
| 62 | + describe('loading', function() { |
| 63 | + it('should load', function(done) { |
| 64 | + analytics.load(navilytics, done); |
| 65 | + }); |
| 66 | + }); |
| 67 | + |
| 68 | + describe('after loading', function() { |
| 69 | + beforeEach(function(done) { |
| 70 | + analytics.once('ready', done); |
| 71 | + analytics.initialize(); |
| 72 | + analytics.page(); |
| 73 | + }); |
| 74 | + |
| 75 | + describe('#track', function() { |
| 76 | + beforeEach(function() { |
| 77 | + analytics.stub(window.__nls, 'push'); |
| 78 | + }); |
| 79 | + |
| 80 | + it('should tag the recording', function() { |
| 81 | + analytics.track('event'); |
| 82 | + analytics.called(window.__nls.push, ['tagRecording', 'event']); |
| 83 | + }); |
| 84 | + }); |
| 85 | + }); |
| 86 | +}); |
0 commit comments