Browse Source

Add spec for interaction event with escape item

Kevin Sawicki 8 years ago
parent
commit
74a3a34caa
2 changed files with 16 additions and 3 deletions
  1. 4 3
      lib/browser/api/touch-bar.js
  2. 12 0
      spec/api-touch-bar-spec.js

+ 4 - 3
lib/browser/api/touch-bar.js

@@ -39,13 +39,14 @@ class TouchBar extends EventEmitter {
       items = []
     }
 
+    this.changeListener = (item) => {
+      this.emit('change', item.id, item.type)
+    }
+
     this.windowListeners = {}
     this.items = {}
     this.ordereredItems = []
     this.escapeItem = escapeItem
-    this.changeListener = (item) => {
-      this.emit('change', item.id, item.type)
-    }
 
     const registerItem = (item) => {
       this.items[item.id] = item

+ 12 - 0
spec/api-touch-bar-spec.js

@@ -90,5 +90,17 @@ describe('TouchBar module', function () {
       window.setTouchBar(touchBar)
       window.emit('-touch-bar-interaction', {}, button.id)
     })
+
+    it('calls the callback on the escape item when a window interaction event fires', function (done) {
+      const button = new TouchBarButton({
+        label: 'bar',
+        click: () => {
+          done()
+        }
+      })
+      const touchBar = new TouchBar({escapeItem: button})
+      window.setTouchBar(touchBar)
+      window.emit('-touch-bar-interaction', {}, button.id)
+    })
   })
 })