]> git.proxmox.com Git - mirror_novnc.git/blob - tests/test.util.js
201acc8bb0d25c5e652ce2fbe777984d2d038c97
[mirror_novnc.git] / tests / test.util.js
1 /* eslint-disable no-console */
2 const expect = chai.expect;
3
4 import * as Log from '../core/util/logging.js';
5
6 describe('Utils', function () {
7 "use strict";
8
9 describe('logging functions', function () {
10 beforeEach(function () {
11 sinon.spy(console, 'log');
12 sinon.spy(console, 'debug');
13 sinon.spy(console, 'warn');
14 sinon.spy(console, 'error');
15 sinon.spy(console, 'info');
16 });
17
18 afterEach(function () {
19 console.log.restore();
20 console.debug.restore();
21 console.warn.restore();
22 console.error.restore();
23 console.info.restore();
24 Log.init_logging();
25 });
26
27 it('should use noop for levels lower than the min level', function () {
28 Log.init_logging('warn');
29 Log.Debug('hi');
30 Log.Info('hello');
31 expect(console.log).to.not.have.been.called;
32 });
33
34 it('should use console.debug for Debug', function () {
35 Log.init_logging('debug');
36 Log.Debug('dbg');
37 expect(console.debug).to.have.been.calledWith('dbg');
38 });
39
40 it('should use console.info for Info', function () {
41 Log.init_logging('debug');
42 Log.Info('inf');
43 expect(console.info).to.have.been.calledWith('inf');
44 });
45
46 it('should use console.warn for Warn', function () {
47 Log.init_logging('warn');
48 Log.Warn('wrn');
49 expect(console.warn).to.have.been.called;
50 expect(console.warn).to.have.been.calledWith('wrn');
51 });
52
53 it('should use console.error for Error', function () {
54 Log.init_logging('error');
55 Log.Error('err');
56 expect(console.error).to.have.been.called;
57 expect(console.error).to.have.been.calledWith('err');
58 });
59 });
60
61 // TODO(directxman12): test the conf_default and conf_defaults methods
62 // TODO(directxman12): test decodeUTF8
63 // TODO(directxman12): test the event methods (addEvent, removeEvent, stopEvent)
64 // TODO(directxman12): figure out a good way to test getPosition and getEventPosition
65 // TODO(directxman12): figure out how to test the browser detection functions properly
66 // (we can't really test them against the browsers, except for Gecko
67 // via PhantomJS, the default test driver)
68 });
69 /* eslint-enable no-console */