From 9a9c509e7657e3d24a3c2f53bab95f4a4cdff143 Mon Sep 17 00:00:00 2001
From: Christopher Willis-Ford <cwillisf@media.mit.edu>
Date: Fri, 28 Apr 2017 14:50:57 -0700
Subject: [PATCH] Implement a few tests for io/deviceManager

---
 src/io/deviceManager.js       |  5 +++-
 test/unit/io_deviceManager.js | 46 +++++++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+), 1 deletion(-)
 create mode 100644 test/unit/io_deviceManager.js

diff --git a/src/io/deviceManager.js b/src/io/deviceManager.js
index c603ccc9f..3895af341 100644
--- a/src/io/deviceManager.js
+++ b/src/io/deviceManager.js
@@ -161,7 +161,10 @@ class DeviceFinder {
     _getList () {
         this._deviceManager
             .list(this._extensionName, this._deviceType, this._deviceSpec)
-            .then(listResult => this._listResultHandler(listResult));
+            .then(
+                listResult => this._listResultHandler(listResult),
+                () => this._listResultHandler(null)
+            );
     }
 
     /**
diff --git a/test/unit/io_deviceManager.js b/test/unit/io_deviceManager.js
new file mode 100644
index 000000000..89127e31d
--- /dev/null
+++ b/test/unit/io_deviceManager.js
@@ -0,0 +1,46 @@
+const test = require('tap').test;
+const DeviceManager = require('../../src/io/deviceManager');
+
+test('spec', t => {
+    const deviceManager = new DeviceManager();
+
+    t.type(DeviceManager, 'function');
+    t.type(deviceManager, 'object');
+    t.type(deviceManager.list, 'function');
+    t.type(deviceManager.open, 'function');
+    t.type(deviceManager.searchAndConnect, 'function');
+    t.type(deviceManager.isConnected, 'boolean');
+    t.end();
+});
+
+test('default connected', t => {
+    const deviceManager = new DeviceManager();
+
+    t.strictEqual(deviceManager.isConnected, true);
+    t.end();
+});
+
+test('cancel searchAndConnect', t => {
+    const deviceManager = new DeviceManager();
+
+    const finder = deviceManager.searchAndConnect('test extension', 'test device');
+
+    let resolved = false;
+    let rejected = false;
+    const testPromise = finder.promise
+        .then(
+            () => {
+                resolved = true;
+            },
+            () => {
+                rejected = true;
+            }
+        )
+        .then(() => {
+            t.strictEqual(resolved, false);
+            t.strictEqual(rejected, true);
+        });
+    finder.cancel();
+
+    return testPromise;
+});