From ab64ce93a699a9affbe86237376e7f737b11400d Mon Sep 17 00:00:00 2001 From: Tree Date: Fri, 14 Nov 2014 19:53:57 +0000 Subject: [PATCH] Updated tests with change to delegate construction. --- README.md | 2 + .../specs/locationManagerSpecs.js | 103 +++++++++--------- 2 files changed, 52 insertions(+), 53 deletions(-) diff --git a/README.md b/README.md index 44bbd04..57b389d 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/test/test_www_assets/specs/locationManagerSpecs.js b/test/test_www_assets/specs/locationManagerSpecs.js index 85f3286..383f269 100644 --- a/test/test_www_assets/specs/locationManagerSpecs.js +++ b/test/test_www_assets/specs/locationManagerSpecs.js @@ -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'; @@ -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) @@ -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) @@ -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.