tests.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. exports.defineAutoTests = function () {
  2. describe('BLE object', function () {
  3. it("ble should exist", function () {
  4. expect(ble).toBeDefined();
  5. });
  6. it("should contain a startScan function", function () {
  7. expect(typeof ble.startScan).toBeDefined();
  8. expect(typeof ble.startScan).toBe("function");
  9. });
  10. });
  11. };
  12. exports.defineManualTests = function (contentEl, createActionButton) {
  13. createActionButton('Is Bluetooth Enabled?', function() {
  14. ble.isEnabled(
  15. function() {
  16. console.log("Bluetooth is enabled");
  17. },
  18. function() {
  19. console.log("Bluetooth is *not* enabled");
  20. }
  21. );
  22. });
  23. if (cordova.platformId !== 'ios') {
  24. // not supported on iOS
  25. createActionButton('Show Bluetooth Settings', function() {
  26. ble.showBluetoothSettings();
  27. });
  28. // not supported on iOS
  29. createActionButton('Enable Bluetooth', function() {
  30. ble.enable(
  31. function() {
  32. console.log("Bluetooth is enabled");
  33. },
  34. function() {
  35. console.log("The user did *not* enable Bluetooth");
  36. }
  37. );
  38. });
  39. }
  40. createActionButton('Scan', function() {
  41. var scanSeconds = 5;
  42. console.log("Scanning for BLE peripherals for " + scanSeconds + " seconds.");
  43. ble.startScan([], function(device) {
  44. console.log(JSON.stringify(device));
  45. }, function(reason) {
  46. console.log("BLE Scan failed " + reason);
  47. });
  48. setTimeout(ble.stopScan,
  49. scanSeconds * 1000,
  50. function() { console.log("Scan complete"); },
  51. function() { console.log("stopScan failed"); }
  52. );
  53. });
  54. };