You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mohemmionic5/Mohem/plugins_/cordova-plugin-ble-central/tests/tests.js

72 lines
1.8 KiB
JavaScript

exports.defineAutoTests = function () {
describe('BLE object', function () {
it("ble should exist", function () {
expect(ble).toBeDefined();
});
it("should contain a startScan function", function () {
expect(typeof ble.startScan).toBeDefined();
expect(typeof ble.startScan).toBe("function");
});
});
};
exports.defineManualTests = function (contentEl, createActionButton) {
createActionButton('Is Bluetooth Enabled?', function() {
ble.isEnabled(
function() {
console.log("Bluetooth is enabled");
},
function() {
console.log("Bluetooth is *not* enabled");
}
);
});
if (cordova.platformId !== 'ios') {
// not supported on iOS
createActionButton('Show Bluetooth Settings', function() {
ble.showBluetoothSettings();
});
// not supported on iOS
createActionButton('Enable Bluetooth', function() {
ble.enable(
function() {
console.log("Bluetooth is enabled");
},
function() {
console.log("The user did *not* enable Bluetooth");
}
);
});
}
createActionButton('Scan', function() {
var scanSeconds = 5;
console.log("Scanning for BLE peripherals for " + scanSeconds + " seconds.");
ble.startScan([], function(device) {
console.log(JSON.stringify(device));
}, function(reason) {
console.log("BLE Scan failed " + reason);
});
setTimeout(ble.stopScan,
scanSeconds * 1000,
function() { console.log("Scan complete"); },
function() { console.log("stopScan failed"); }
);
});
};