|
| 1 | +var gui = require('nw.gui'); |
| 2 | +var assert = require('assert'); |
| 3 | +require('should'); |
| 4 | + |
| 5 | +describe('Shortcut', function() { |
| 6 | + describe('.key', function() { |
| 7 | + it('should be undefined if no key specified.', function() { |
| 8 | + var shortcut; |
| 9 | + try { |
| 10 | + shortcut = new gui.Shortcut(); |
| 11 | + } catch (err) {} |
| 12 | + assert.equal(shortcut, undefined); |
| 13 | + }); |
| 14 | + |
| 15 | + it('should be an object if key specified.', function() { |
| 16 | + var shortcut; |
| 17 | + try { |
| 18 | + shortcut = new gui.Shortcut({"key": "Alt+Shift+S"}); |
| 19 | + } catch (err) {} |
| 20 | + |
| 21 | + shortcut.should.be.a.Object; |
| 22 | + assert.equal(shortcut.key, "Alt+Shift+S"); |
| 23 | + }); |
| 24 | + }); |
| 25 | + |
| 26 | + describe('.active', function() { |
| 27 | + it('should be undefined if active is not an function object.', function() { |
| 28 | + var shortcut; |
| 29 | + try { |
| 30 | + shortcut = new gui.Shortcut({key: 'Alt+Shift+S', active: "foo"}); |
| 31 | + } catch(err) {} |
| 32 | + |
| 33 | + assert.equal(shortcut, undefined); |
| 34 | + }); |
| 35 | + |
| 36 | + it('should be an object if "key" and "active" specified.', function() { |
| 37 | + var onActive = function() {}; |
| 38 | + var shortcut = new gui.Shortcut({key: 'Alt+Shift+S', active: onActive}); |
| 39 | + |
| 40 | + shortcut.should.be.a.Object; |
| 41 | + assert.equal(shortcut.active, onActive); |
| 42 | + }); |
| 43 | + }); |
| 44 | + |
| 45 | + describe('.failed', function() { |
| 46 | + it('should be undefined if "failed" is not a function object.', function() { |
| 47 | + var shortcut; |
| 48 | + try { |
| 49 | + shortcut = new gui.Shortcut({key: 'Alt+Shift+S', failed: "foo"}); |
| 50 | + } catch(err) {} |
| 51 | + |
| 52 | + assert.equal(shortcut, undefined); |
| 53 | + }); |
| 54 | + |
| 55 | + it('should be an object if "key" and "failed" specified.', function() { |
| 56 | + var onFailed = function() {}; |
| 57 | + var shortcut = new gui.Shortcut({key: 'Alt+Shift+S', failed: onFailed}); |
| 58 | + |
| 59 | + shortcut.should.be.a.Object; |
| 60 | + assert.equal(shortcut.failed, onFailed); |
| 61 | + }); |
| 62 | + }); |
| 63 | +}); |
| 64 | + |
| 65 | +describe('App.registerGlobalHotKey', function() { |
| 66 | + it('should register failed if the parameter is not an Shortcut object.', |
| 67 | + function(done) { |
| 68 | + var object = new Object(); |
| 69 | + try { |
| 70 | + gui.App.registerGlobalHotKey(object); |
| 71 | + } catch(err) { |
| 72 | + done(); |
| 73 | + } |
| 74 | + } |
| 75 | + ); |
| 76 | + |
| 77 | + it('should register failed if the same key has been registered.', |
| 78 | + function(done) { |
| 79 | + var shortcut = new gui.Shortcut({key: "Alt+Shift+S"}); |
| 80 | + shortcut.failed = function(msg) { |
| 81 | + assert.equal(msg, "Register global desktop keyboard shortcut failed."); |
| 82 | + done(); |
| 83 | + }; |
| 84 | + |
| 85 | + gui.App.registerGlobalHotKey(shortcut); |
| 86 | + gui.App.registerGlobalHotKey(shortcut); |
| 87 | + } |
| 88 | + ); |
| 89 | + |
| 90 | + it('should register failed for invalid key.', function(done) { |
| 91 | + var shortcut = new gui.Shortcut({key: "foo"}); |
| 92 | + shortcut.failed = function(msg) { |
| 93 | + done(); |
| 94 | + } |
| 95 | + gui.App.registerGlobalHotKey(shortcut); |
| 96 | + }); |
| 97 | +}); |
| 98 | + |
| 99 | +describe('App.unregisterGlobalHotKey', function() { |
| 100 | + it('should unregister failed if the parameter is not an Shortcut object.', |
| 101 | + function(done) { |
| 102 | + var object = new Object(); |
| 103 | + try { |
| 104 | + gui.App.unregisterGlobalHotKey(object); |
| 105 | + } catch(err) { |
| 106 | + done(); |
| 107 | + } |
| 108 | + } |
| 109 | + ); |
| 110 | +}); |
0 commit comments