Icontem

File: test/tests_async.js

Recommend this page to a friend!
  Classes of Arturs Sosins  >  Countly Web SDK  >  test/tests_async.js  >  Download  
File: test/tests_async.js
Role: Unit test script
Content type: text/plain
Description: Unit test script
Class: Countly Web SDK
Track site accesses and errors the Countly API
Author: By
Last change: [eslint] stricter lint including styles
[tests] update tests
Merge pull request #34 from frknbasaran/ga-adapter

[ga-adapter] added countlyLoaded() method
Date: 8 months ago
Size: 9,229 bytes
 

Contents

Class file image Download
var fs = require("fs");
function exists(value){
    return (typeof value != "undefined") ? true : false;
}
casper.test.begin("Testing example_async.html", 117, function(test) {
    var tests = [];
    var cnt = 0;
    tests.push(function (message){
        test.assertEquals(message[0], 'Countly initialized');
    });
    tests.push(function (message){
        test.assertEquals(message[0], 'Processing queued call');
        test.assertEquals(message[1], '["track_sessions"]');
    });
    tests.push(function (message){
        test.assertEquals(message[0], 'Session started');
    });
    tests.push(function (message){
        test.assertEquals(message[0], 'Got metrics');
        var params = JSON.parse(message[1]);
        test.assertEquals(params._app_version, '0.0');
        test.assertEquals(params._resolution, '1024x768');
        test.assertEquals(params._locale, 'en-US');
    });
    tests.push(function (message){
        test.assertEquals(message[0], 'Processing queued call');
        var params = JSON.parse(message[1]);
        test.assertEquals(params[0], "track_pageview");
    });
    tests.push(function (message){
        test.assertEquals(message[0], 'Adding event: ');
        var params = JSON.parse(message[1]);
        test.assertEquals(params.key, "[CLY]_view");
        test.assert(exists(params.segmentation));
        test.assert(exists(params.segmentation.name));
        test.assert(exists(params.segmentation.visit));
        test.assertEquals(params.count, 1);
    });
    tests.push(function (message){
        test.assertEquals(message[0], 'Processing request');
        var params = JSON.parse(message[1]);
        test.assertEquals(params.begin_session, 1);
        test.assertEquals(params.app_key, "YOUR_APP_KEY");
        test.assert(exists(params.device_id));
        test.assert(exists(params.timestamp));
        test.assert(exists(params.hour));
        test.assert(exists(params.dow));
        params.metrics = JSON.parse(params.metrics);
        test.assertEquals(params.metrics._app_version, '0.0');
        test.assertEquals(params.metrics._resolution, '1024x768');
        test.assertEquals(params.metrics._locale, 'en-US');
    });
    tests.push(function (message){
        test.assertEquals(message[0], 'Sending XML HTTP request');
    });
    tests.push(function (message){
        test.assertEquals(message[0], 'Request Finished');
        var params = JSON.parse(message[1]);
        test.assertEquals(params.begin_session, 1);
        test.assertEquals(params.app_key, "YOUR_APP_KEY");
        test.assert(exists(params.device_id));
        test.assert(exists(params.timestamp));
        test.assert(exists(params.hour));
        test.assert(exists(params.dow));
        params.metrics = JSON.parse(params.metrics);
        test.assertEquals(params.metrics._app_version, '0.0');
        test.assertEquals(params.metrics._resolution, '1024x768');
        test.assertEquals(params.metrics._locale, 'en-US');
    });
    tests.push(function (message){
        test.assertEquals(message[0], 'Processing request');
        var params = JSON.parse(message[1]);
        test.assertEquals(params.app_key, "YOUR_APP_KEY");
        test.assert(exists(params.device_id));
        test.assert(exists(params.timestamp));
        test.assert(exists(params.hour));
        test.assert(exists(params.dow));
        
        params.events = JSON.parse(params.events);
        test.assertEquals(params.events[0].key, '[CLY]_view');
        test.assert(exists(params.events[0].segmentation));
        test.assert(exists(params.events[0].segmentation.name));
        test.assert(exists(params.events[0].segmentation.visit));
        test.assertEquals(params.events[0].count, 1);
    });
    tests.push(function (message){
        test.assertEquals(message[0], 'Sending XML HTTP request');
    });
    tests.push(function (message){
        test.assertEquals(message[0], 'Request Finished');
        var params = JSON.parse(message[1]);
        test.assertEquals(params.app_key, "YOUR_APP_KEY");
        test.assert(exists(params.device_id));
        test.assert(exists(params.timestamp));
        test.assert(exists(params.hour));
        test.assert(exists(params.dow));
        params.events = JSON.parse(params.events);
        test.assertEquals(params.events[0].key, '[CLY]_view');
        test.assert(exists(params.events[0].segmentation));
        test.assert(exists(params.events[0].segmentation.name));
        test.assert(exists(params.events[0].segmentation.visit));
        test.assertEquals(params.events[0].count, 1);
    });
    tests.push(function (message){
        test.assertEquals(message[0], 'Processing queued call');
        var params = JSON.parse(message[1]);
        test.assertEquals(params[0], "add_event");
        test.assertEquals(params[1].key, "buttonClick");
        test.assert(exists(params[1].segmentation));
        test.assertEquals(params[1].segmentation.id, "testButton");
    });
    tests.push(function (message){
        test.assertEquals(message[0], 'Adding event: ');
        var params = JSON.parse(message[1]);
        test.assertEquals(params.key, "buttonClick");
        test.assert(exists(params.segmentation));
        test.assertEquals(params.segmentation.id, "testButton");
        test.assertEquals(params.count, 1);
    });
    tests.push(function (message){
        test.assertEquals(message[0], 'Processing request');
        var params = JSON.parse(message[1]);
        test.assertEquals(params.app_key, "YOUR_APP_KEY");
        test.assert(exists(params.device_id));
        test.assert(exists(params.timestamp));
        test.assert(exists(params.hour));
        test.assert(exists(params.dow));
        
        params.events = JSON.parse(params.events);
        test.assertEquals(params.events[0].key, 'buttonClick');
        test.assert(exists(params.events[0].segmentation));
        test.assertEquals(params.events[0].segmentation.id, "testButton");
        test.assertEquals(params.events[0].count, 1);
    });
    tests.push(function (message){
        test.assertEquals(message[0], 'Sending XML HTTP request');
    });
    tests.push(function (message){
        test.assertEquals(message[0], 'Request Finished');
        var params = JSON.parse(message[1]);
        test.assertEquals(params.app_key, "YOUR_APP_KEY");
        test.assert(exists(params.device_id));
        test.assert(exists(params.timestamp));
        test.assert(exists(params.hour));
        test.assert(exists(params.dow));
        params.events = JSON.parse(params.events);
        test.assertEquals(params.events[0].key, 'buttonClick');
        test.assert(exists(params.events[0].segmentation));
        test.assertEquals(params.events[0].segmentation.id, "testButton");
        test.assertEquals(params.events[0].count, 1);
    });
    tests.push(function (message){
        test.assertEquals(message[0], 'Session extended');
        test.assertEquals(message[1], '61');
    });
    tests.push(function (message){
        test.assertEquals(message[0], 'Processing request');
        var params = JSON.parse(message[1]);
        test.assertEquals(params.session_duration, 61);
        test.assertEquals(params.app_key, "YOUR_APP_KEY");
        test.assert(exists(params.device_id));
        test.assert(exists(params.timestamp));
        test.assert(exists(params.hour));
        test.assert(exists(params.dow));
    });
    tests.push(function (message){
        test.assertEquals(message[0], 'Sending XML HTTP request');
    });
    tests.push(function (message){
        test.assertEquals(message[0], 'Request Finished');
        var params = JSON.parse(message[1]);
        test.assertEquals(params.session_duration, 61);
        test.assertEquals(params.app_key, "YOUR_APP_KEY");
        test.assert(exists(params.device_id));
        test.assert(exists(params.timestamp));
        test.assert(exists(params.hour));
        test.assert(exists(params.dow));
    });
    tests.push(function (message){
        test.assertEquals(message[0], 'Adding event: ');
        var params = JSON.parse(message[1]);
        test.assertEquals(params.key, "[CLY]_view");
        test.assertEquals(params.dur, 80);
        test.assert(exists(params.segmentation));
        test.assert(exists(params.segmentation.name));
        test.assert(!exists(params.segmentation.visit));
        test.assertEquals(params.count, 1);
    });
    tests.push(function (message){
        test.assertEquals(message[0], 'Session extended');
        test.assertEquals(message[1], '19');
    });
    casper.removeAllListeners('remote.message');
    casper.on('remote.message', function(message) {
        casper.echo(message);
        tests[cnt](message.split("\n"));
        cnt++;
    });
    casper.start(fs.workingDirectory+"/examples/example_async.html", function() {
        var self = this;
        setTimeout(function(){
            self.click('input'); 
        }, 1000);
    }).run(function() {
        setTimeout(function(){
            casper.clear();
            casper.clearCache();
            casper.clearMemoryCache();
            casper.open(fs.workingDirectory+"/test/files/clear.html", function() {});
            test.done();
        }, 80000);
    });
});