]>
git.proxmox.com Git - mirror_novnc.git/blob - tests/test.util.js
1 // requires local modules: util
2 /* jshint expr: true */
4 var assert
= chai
.assert
;
5 var expect
= chai
.expect
;
7 describe('Utils', function() {
10 describe('Array instance methods', function () {
11 describe('push8', function () {
12 it('should push a byte on to the array', function () {
15 expect(arr
).to
.deep
.equal([1, 128]);
18 it('should only use the least significant byte of any number passed in', function () {
21 expect(arr
).to
.deep
.equal([1, 0xCD]);
25 describe('push16', function () {
26 it('should push two bytes on to the array', function () {
29 expect(arr
).to
.deep
.equal([1, 0xAB, 0xCD]);
32 it('should only use the two least significant bytes of any number passed in', function () {
35 expect(arr
).to
.deep
.equal([1, 0xCD, 0xEF]);
39 describe('push32', function () {
40 it('should push four bytes on to the array', function () {
42 arr
.push32(0xABCDEF12);
43 expect(arr
).to
.deep
.equal([1, 0xAB, 0xCD, 0xEF, 0x12]);
46 it('should only use the four least significant bytes of any number passed in', function () {
48 arr
.push32(0xABCDEF1234);
49 expect(arr
).to
.deep
.equal([1, 0xCD, 0xEF, 0x12, 0x34]);
54 describe('logging functions', function () {
55 beforeEach(function () {
56 sinon
.spy(console
, 'log');
57 sinon
.spy(console
, 'warn');
58 sinon
.spy(console
, 'error');
61 afterEach(function () {
62 console
.log
.restore();
63 console
.warn
.restore();
64 console
.error
.restore();
67 it('should use noop for levels lower than the min level', function () {
68 Util
.init_logging('warn');
71 expect(console
.log
).to
.not
.have
.been
.called
;
74 it('should use console.log for Debug and Info', function () {
75 Util
.init_logging('debug');
78 expect(console
.log
).to
.have
.been
.calledWith('dbg');
79 expect(console
.log
).to
.have
.been
.calledWith('inf');
82 it('should use console.warn for Warn', function () {
83 Util
.init_logging('warn');
85 expect(console
.warn
).to
.have
.been
.called
;
86 expect(console
.warn
).to
.have
.been
.calledWith('wrn');
89 it('should use console.error for Error', function () {
90 Util
.init_logging('error');
92 expect(console
.error
).to
.have
.been
.called
;
93 expect(console
.error
).to
.have
.been
.calledWith('err');
97 // TODO(directxman12): test the conf_default and conf_defaults methods
98 // TODO(directxman12): test decodeUTF8
99 // TODO(directxman12): test the event methods (addEvent, removeEvent, stopEvent)
100 // TODO(directxman12): figure out a good way to test getPosition and getEventPosition
101 // TODO(directxman12): figure out how to test the browser detection functions properly
102 // (we can't really test them against the browsers, except for Gecko
103 // via PhantomJS, the default test driver)
104 // TODO(directxman12): figure out how to test Util.Flash