Commit 85191ee7 authored by Simon MacDonald's avatar Simon MacDonald
Browse files

Update test specs

[spec] Revamp test
[spec] Fix "[Error: Cannot find module '../www']"
[spec] Add missing 'typeof' to the assetions.
[git] Ignore the node_modules/ directory.
[spec] fix failing tests
parent d1a39fb1
Loading
Loading
Loading
Loading
+1 −0
Changes for .gitignore: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
*.iml
.idea
.DS_Store
/node_modules/

spec/genericpush.tests.js

deleted100644 → 0
+0 −46
Changes for spec/genericpush.tests.js: 0 added lines, 46 removed lines.
Original line number Diff line number Diff line
/*
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
*/

describe('Plugin object (window.plugins)', function () {
	it("should exist", function() {
        expect(window.plugins).toBeDefined();
	});

	it("should contain a pushNotification object", function() {
        expect(window.plugins.pushNotification).toBeDefined();
		expect(typeof window.plugins.pushNotification == 'object').toBe(true);
	});

    it("should contain a register function", function() {
        expect(window.plugins.pushNotification.register).toBeDefined();
        expect(typeof window.plugins.pushNotification.register == 'function').toBe(true);
    });
    
    it("should contain an unregister function", function() {
        expect(window.plugins.pushNotification.unregister).toBeDefined();
        expect(typeof window.plugins.pushNotification.unregister == 'function').toBe(true);
    });
    
    it("should contain a setApplicationIconBadgeNumber function", function() {
        expect(window.plugins.pushNotification.setApplicationIconBadgeNumber).toBeDefined();
        expect(typeof window.plugins.pushNotification.setApplicationIconBadgeNumber == 'function').toBe(true);
    });
});

spec/helper/cordova.js

0 → 100644
+83 −0
Changes for spec/helper/cordova.js: 83 added lines, 0 removed lines.
Original line number Diff line number Diff line
/* global cordova:true */

/*!
 * Module dependencies.
 */

/**
 * cordova.js for node.
 *
 * Think of this as cordova-node, which would be simliar to cordova-android
 * or cordova-browser. The purpose of this module is to enable testing
 * of a plugin's JavaScript interface.
 *
 * When this module is first required, it will insert a global cordova
 * instance, which can hijack cordova-specific commands within the pluin's
 * implementation.
 *
 * Remember to require this module before the plugin that you want to test.
 *
 * Example:
 *
 *     var cordova = require('./helper/cordova'),
 *         myPlugin = require('../www/myPlugin');
 */

module.exports = global.cordova = cordova = {

    /**
     * cordova.require Mock.
     *
     * Hijacks all cordova.requires. By default, it returns an empty function.
     * You can define your own implementation of each required module before
     * or after it has been required.
     *
     * See `cordova.required` to learn how to add your own module implemtnation.
     */

    require: function(moduleId) {
        // define a default function if it doesn't exist
        if (!cordova.required[moduleId]) {
            cordova.required[moduleId] = function() {};
        }
        // create a new module mapping between the module Id and cordova.required.
        return new ModuleMap(moduleId);
    },

    /**
     * Cordova module implementations.
     *
     * A key-value hash, where the key is the module such as 'cordova/exec'
     * and the value is the function or object returned.
     *
     * For example:
     *
     *     var exec = require('cordova/exec');
     *
     * Will map to:
     *
     *     cordova.required['cordova/exec'];
     */

    required: {
        // populated at runtime
    }
};

/**
 * Module Mapper.
 *
 * Returns a function that when executed will lookup the implementation
 * in cordova.required[id].
 *
 * @param {String} moduleId is the module name/path, such as 'cordova/exec'
 * @return {Function}.
 */

function ModuleMap(moduleId) {
    return function() {
        // lookup and execute the module's mock implementation, passing
        // in any parameters that were provided.
        return cordova.required[moduleId].apply(this, arguments);
    };
}

spec/html/HtmlReporter.js

deleted100644 → 0
+0 −101
Changes for spec/html/HtmlReporter.js: 0 added lines, 101 removed lines.
Original line number Diff line number Diff line
jasmine.HtmlReporter = function(_doc) {
  var self = this;
  var doc = _doc || window.document;

  var reporterView;

  var dom = {};

  // Jasmine Reporter Public Interface
  self.logRunningSpecs = false;

  self.reportRunnerStarting = function(runner) {
    var specs = runner.specs() || [];

    if (specs.length == 0) {
      return;
    }

    createReporterDom(runner.env.versionString());
    doc.body.appendChild(dom.reporter);

    reporterView = new jasmine.HtmlReporter.ReporterView(dom);
    reporterView.addSpecs(specs, self.specFilter);
  };

  self.reportRunnerResults = function(runner) {
    reporterView && reporterView.complete();
  };

  self.reportSuiteResults = function(suite) {
    reporterView.suiteComplete(suite);
  };

  self.reportSpecStarting = function(spec) {
    if (self.logRunningSpecs) {
      self.log('>> Jasmine Running ' + spec.suite.description + ' ' + spec.description + '...');
    }
  };

  self.reportSpecResults = function(spec) {
    reporterView.specComplete(spec);
  };

  self.log = function() {
    var console = jasmine.getGlobal().console;
    if (console && console.log) {
      if (console.log.apply) {
        console.log.apply(console, arguments);
      } else {
        console.log(arguments); // ie fix: console.log.apply doesn't exist on ie
      }
    }
  };

  self.specFilter = function(spec) {
    if (!focusedSpecName()) {
      return true;
    }

    return spec.getFullName().indexOf(focusedSpecName()) === 0;
  };

  return self;

  function focusedSpecName() {
    var specName;

    (function memoizeFocusedSpec() {
      if (specName) {
        return;
      }

      var paramMap = [];
      var params = doc.location.search.substring(1).split('&');

      for (var i = 0; i < params.length; i++) {
        var p = params[i].split('=');
        paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
      }

      specName = paramMap.spec;
    })();

    return specName;
  }

  function createReporterDom(version) {
    dom.reporter = self.createDom('div', { id: 'HTMLReporter', className: 'jasmine_reporter' },
      dom.banner = self.createDom('div', { className: 'banner' },
        self.createDom('span', { className: 'title' }, "Jasmine "),
        self.createDom('span', { className: 'version' }, version)),

      dom.symbolSummary = self.createDom('ul', {className: 'symbolSummary'}),
      dom.alert = self.createDom('div', {className: 'alert'}),
      dom.results = self.createDom('div', {className: 'results'},
        dom.summary = self.createDom('div', { className: 'summary' }),
        dom.details = self.createDom('div', { id: 'details' }))
    );
  }
};
jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter);

spec/html/HtmlReporterHelpers.js

deleted100644 → 0
+0 −60
Changes for spec/html/HtmlReporterHelpers.js: 0 added lines, 60 removed lines.
Original line number Diff line number Diff line
jasmine.HtmlReporterHelpers = {};

jasmine.HtmlReporterHelpers.createDom = function(type, attrs, childrenVarArgs) {
  var el = document.createElement(type);

  for (var i = 2; i < arguments.length; i++) {
    var child = arguments[i];

    if (typeof child === 'string') {
      el.appendChild(document.createTextNode(child));
    } else {
      if (child) {
        el.appendChild(child);
      }
    }
  }

  for (var attr in attrs) {
    if (attr == "className") {
      el[attr] = attrs[attr];
    } else {
      el.setAttribute(attr, attrs[attr]);
    }
  }

  return el;
};

jasmine.HtmlReporterHelpers.getSpecStatus = function(child) {
  var results = child.results();
  var status = results.passed() ? 'passed' : 'failed';
  if (results.skipped) {
    status = 'skipped';
  }

  return status;
};

jasmine.HtmlReporterHelpers.appendToSummary = function(child, childElement) {
  var parentDiv = this.dom.summary;
  var parentSuite = (typeof child.parentSuite == 'undefined') ? 'suite' : 'parentSuite';
  var parent = child[parentSuite];

  if (parent) {
    if (typeof this.views.suites[parent.id] == 'undefined') {
      this.views.suites[parent.id] = new jasmine.HtmlReporter.SuiteView(parent, this.dom, this.views);
    }
    parentDiv = this.views.suites[parent.id].element;
  }

  parentDiv.appendChild(childElement);
};


jasmine.HtmlReporterHelpers.addHelpers = function(ctor) {
  for(var fn in jasmine.HtmlReporterHelpers) {
    ctor.prototype[fn] = jasmine.HtmlReporterHelpers[fn];
  }
};
Loading