Skip to content

Commit

Permalink
Updated tests with change to delegate construction.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrtree1 committed Nov 14, 2014
1 parent 5931845 commit ab64ce9
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 53 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ Since version 2, the main ```IBeacon``` facade of the DOM is called ```LocationM
Another important change of version 2 is that it no longer pollutes the global namespace, instead all the model classes and utilities are accessible
through the ```cordova.plugins.locationManager``` reference chain.

Since version 3.2 the Klass dependency has been removed and therefore means creation of the delegate has changed.

#### iOS 8 Permissions

On iOS 8, you have to request permissions from the user of your app explicitly. You can do this through the plugin's API.
Expand Down
103 changes: 50 additions & 53 deletions test/test_www_assets/specs/locationManagerSpecs.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,11 @@ describe('LocationManager', function() {

it('starts the ranging of beacon regions', function(done) {

var delegate = new cordova.plugins.locationManager.Delegate().implement({
var delegate = new cordova.plugins.locationManager.Delegate();

didRangeBeaconsInRegion: function (pluginResult) {
console.debug('[DOM] didRangeBeaconsInRegion: ' + JSON.stringify(pluginResult.region));
}

});
delegate.didRangeBeaconsInRegion = function (pluginResult) {
console.debug('[DOM] didRangeBeaconsInRegion: ' + JSON.stringify(pluginResult.region));
};

var uuid = 'DA5336AE-2042-453A-A57F-F80DD34DFCD9';
var identifier = 'beaconOnTheMacBooksShelf';
Expand All @@ -76,23 +74,23 @@ describe('LocationManager', function() {
expect(charingCross).toBeDefined();
expect(charingCross instanceof CircularRegion).toBe(true);

var delegate = new Delegate().implement({
didDetermineStateForRegion: function(pluginResult) {
expect(Delegate['didDetermineStateForRegion']).toHaveBeenCalled();
expect(pluginResult).toBeDefined();
expect(pluginResult.region).toBeDefined();
locationManager.appendToDeviceLog('[DOM] didDetermineStateForRegion: '
+ JSON.stringify(pluginResult.region));
},
didStartMonitoringForRegion: function(pluginResult) {
console.log('didStartMonitoringForRegion:', pluginResult);

var region = pluginResult.region;
expect(region).toBeDefined();
expect(region instanceof Region).toBe(true);
done();
}
});
var delegate = new Delegate();
delegate.didDetermineStateForRegion = function(pluginResult) {
expect(Delegate['didDetermineStateForRegion']).toHaveBeenCalled();
expect(pluginResult).toBeDefined();
expect(pluginResult.region).toBeDefined();
locationManager.appendToDeviceLog('[DOM] didDetermineStateForRegion: '
+ JSON.stringify(pluginResult.region));
};
delegate.didStartMonitoringForRegion = function(pluginResult) {
console.log('didStartMonitoringForRegion:', pluginResult);

var region = pluginResult.region;
expect(region).toBeDefined();
expect(region instanceof Region).toBe(true);
done();
};


locationManager.setDelegate(delegate);
locationManager.startMonitoringForRegion(charingCross)
Expand All @@ -115,23 +113,22 @@ describe('LocationManager', function() {
expect(appleHq).toBeDefined();
expect(appleHq instanceof CircularRegion).toBe(true);

var delegate = new Delegate().implement({
didDetermineStateForRegion: function(pluginResult) {
expect(Delegate['didDetermineStateForRegion']).toHaveBeenCalled();
expect(pluginResult).toBeDefined();
expect(pluginResult.region).toBeDefined();
locationManager.appendToDeviceLog('[DOM] didDetermineStateForRegion: '
+ JSON.stringify(pluginResult.region));
},
didStartMonitoringForRegion: function(pluginResult) {
console.log('didStartMonitoringForRegion:', pluginResult);

var region = pluginResult.region;
expect(region).toBeDefined();
expect(region instanceof Region).toBe(true);
done();
}
});
var delegate = new Delegate();
delegate.didDetermineStateForRegion = function(pluginResult) {
expect(Delegate['didDetermineStateForRegion']).toHaveBeenCalled();
expect(pluginResult).toBeDefined();
expect(pluginResult.region).toBeDefined();
locationManager.appendToDeviceLog('[DOM] didDetermineStateForRegion: '
+ JSON.stringify(pluginResult.region));
};
delegate.didStartMonitoringForRegion = function(pluginResult) {
console.log('didStartMonitoringForRegion:', pluginResult);

var region = pluginResult.region;
expect(region).toBeDefined();
expect(region instanceof Region).toBe(true);
done();
};

locationManager.setDelegate(delegate);
locationManager.startMonitoringForRegion(appleHq)
Expand Down Expand Up @@ -242,19 +239,19 @@ describe('LocationManager', function() {

it('starts advertising as a beacon', function () {

var delegate = new cordova.plugins.locationManager.Delegate().implement({

// Event when advertising starts (there may be a short delay after the request)
// The property 'region' provides details of the broadcasting Beacon
peripheralManagerDidStartAdvertising: function(pluginResult) {
console.log('peripheralManagerDidStartAdvertising: '+ JSON.stringify(pluginResult.region));
},
// Event when bluetooth transmission state changes
// If 'state' is not set to BluetoothManagerStatePoweredOn when advertising cannot start
peripheralManagerDidUpdateState: function(pluginResult) {
console.log('peripheralManagerDidUpdateState: '+ pluginResult.state);
}
});
var delegate = new cordova.plugins.locationManager.Delegate();

// Event when advertising starts (there may be a short delay after the request)
// The property 'region' provides details of the broadcasting Beacon
delegate.peripheralManagerDidStartAdvertising = function(pluginResult) {
console.log('peripheralManagerDidStartAdvertising: '+ JSON.stringify(pluginResult.region));
};
// Event when bluetooth transmission state changes
// If 'state' is not set to BluetoothManagerStatePoweredOn when advertising cannot start
delegate.peripheralManagerDidUpdateState = function(pluginResult) {
console.log('peripheralManagerDidUpdateState: '+ pluginResult.state);
};

cordova.plugins.locationManager.setDelegate(delegate);

// You can't test the iBeacon monitoring properly in the emulator, thus the crippled test.
Expand Down

0 comments on commit ab64ce9

Please sign in to comment.