|
| 1 | +const assert = require('assert') |
| 2 | +const {BrowserWindow, TouchBar} = require('electron').remote |
| 3 | +const {closeWindow} = require('./window-helpers') |
| 4 | + |
| 5 | +const {TouchBarButton, TouchBarColorPicker, TouchBarGroup} = TouchBar |
| 6 | +const {TouchBarLabel, TouchBarPopover, TouchBarSlider, TouchBarSpacer} = TouchBar |
| 7 | + |
| 8 | +describe('TouchBar module', function () { |
| 9 | + it('throws an error when created without an items array', function () { |
| 10 | + assert.throws(() => { |
| 11 | + const touchBar = new TouchBar() |
| 12 | + touchBar.toString() |
| 13 | + }, /Must specify items array as first argument/) |
| 14 | + }) |
| 15 | + |
| 16 | + it('throws an error when created with invalid items', function () { |
| 17 | + assert.throws(() => { |
| 18 | + const touchBar = new TouchBar([1, true, {}, []]) |
| 19 | + touchBar.toString() |
| 20 | + }, /Each item must be an instance of TouchBarItem/) |
| 21 | + }) |
| 22 | + |
| 23 | + describe('BrowserWindow behavior', function () { |
| 24 | + let window |
| 25 | + |
| 26 | + beforeEach(function () { |
| 27 | + window = new BrowserWindow() |
| 28 | + }) |
| 29 | + |
| 30 | + afterEach(function () { |
| 31 | + window.setTouchBar(null) |
| 32 | + return closeWindow(window).then(function () { window = null }) |
| 33 | + }) |
| 34 | + |
| 35 | + it('can be added to and removed from a window', function () { |
| 36 | + const touchBar = new TouchBar([ |
| 37 | + new TouchBarButton({label: 'foo', backgroundColor: '#F00', click: () => {}}), |
| 38 | + new TouchBarColorPicker({selectedColor: '#F00', change: () => {}}), |
| 39 | + new TouchBarGroup({items: new TouchBar([new TouchBarLabel({label: 'hello'})])}), |
| 40 | + new TouchBarLabel({label: 'bar'}), |
| 41 | + new TouchBarPopover({items: new TouchBar([new TouchBarButton({label: 'pop'})])}), |
| 42 | + new TouchBarSlider({label: 'slide', value: 5, minValue: 2, maxValue: 75, change: () => {}}), |
| 43 | + new TouchBarSpacer({size: 'large'}) |
| 44 | + ]) |
| 45 | + window.setTouchBar(touchBar) |
| 46 | + window.setTouchBar() |
| 47 | + window.setTouchBar(new TouchBar([new TouchBarLabel({label: 'two'})])) |
| 48 | + }) |
| 49 | + }) |
| 50 | +}) |
0 commit comments