mirror of
https://github.com/cupcakearmy/fight-of-the-mobiles.git
synced 2026-04-02 18:25:23 +00:00
cordova
This commit is contained in:
83
src/cordova/plugins/phonegap-plugin-barcodescanner/spec/helper/cordova.js
vendored
Normal file
83
src/cordova/plugins/phonegap-plugin-barcodescanner/spec/helper/cordova.js
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
/* 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);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/* globals require */
|
||||
|
||||
/*!
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var cordova = require('./helper/cordova'),
|
||||
BarcodeScanner = require('../www/barcodescanner'),
|
||||
execSpy,
|
||||
execWin,
|
||||
options;
|
||||
|
||||
/*!
|
||||
* Specification.
|
||||
*/
|
||||
|
||||
describe('phonegap-plugin-barcodescanner', function () {
|
||||
beforeEach(function () {
|
||||
execWin = jasmine.createSpy();
|
||||
execSpy = spyOn(cordova.required, 'cordova/exec').andCallFake(execWin);
|
||||
});
|
||||
|
||||
describe('BarcodeScanner', function () {
|
||||
it("BarcodeScanner plugin should exist", function() {
|
||||
expect(BarcodeScanner).toBeDefined();
|
||||
expect(typeof BarcodeScanner == 'object').toBe(true);
|
||||
});
|
||||
|
||||
it("should contain a scan function", function() {
|
||||
expect(BarcodeScanner.scan).toBeDefined();
|
||||
expect(typeof BarcodeScanner.scan == 'function').toBe(true);
|
||||
});
|
||||
|
||||
it("should contain an encode function", function() {
|
||||
expect(BarcodeScanner.encode).toBeDefined();
|
||||
expect(typeof BarcodeScanner.encode == 'function').toBe(true);
|
||||
});
|
||||
|
||||
it("should contain three DestinationType constants", function() {
|
||||
expect(BarcodeScanner.Encode.TEXT_TYPE).toBe("TEXT_TYPE");
|
||||
expect(BarcodeScanner.Encode.EMAIL_TYPE).toBe("EMAIL_TYPE");
|
||||
expect(BarcodeScanner.Encode.PHONE_TYPE).toBe("PHONE_TYPE");
|
||||
expect(BarcodeScanner.Encode.SMS_TYPE).toBe("SMS_TYPE");
|
||||
});
|
||||
});
|
||||
|
||||
describe('BarcodeScanner instance', function () {
|
||||
describe('cordova.exec', function () {
|
||||
it('should call cordova.exec on next process tick', function (done) {
|
||||
BarcodeScanner.scan(function() {}, function() {}, {});
|
||||
setTimeout(function () {
|
||||
expect(execSpy).toHaveBeenCalledWith(
|
||||
jasmine.any(Function),
|
||||
jasmine.any(Function),
|
||||
'BarcodeScanner',
|
||||
'scan',
|
||||
jasmine.any(Object)
|
||||
);
|
||||
done();
|
||||
}, 100);
|
||||
});
|
||||
|
||||
it('should call cordova.exec on next process tick', function (done) {
|
||||
BarcodeScanner.encode("", "",function() {}, function() {}, {});
|
||||
setTimeout(function () {
|
||||
expect(execSpy).toHaveBeenCalledWith(
|
||||
jasmine.any(Function),
|
||||
jasmine.any(Function),
|
||||
'BarcodeScanner',
|
||||
'encode',
|
||||
jasmine.any(Object)
|
||||
);
|
||||
done();
|
||||
}, 100);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user