]>
git.proxmox.com Git - mirror_novnc.git/blob - tests/test.util.js
1 /* eslint-disable no-console */
2 const expect
= chai
.expect
;
4 import * as Log
from '../core/util/logging.js';
5 import { encodeUTF8
, decodeUTF8
} from '../core/util/strings.js';
7 describe('Utils', function () {
10 describe('logging functions', function () {
11 beforeEach(function () {
12 sinon
.spy(console
, 'log');
13 sinon
.spy(console
, 'debug');
14 sinon
.spy(console
, 'warn');
15 sinon
.spy(console
, 'error');
16 sinon
.spy(console
, 'info');
19 afterEach(function () {
20 console
.log
.restore();
21 console
.debug
.restore();
22 console
.warn
.restore();
23 console
.error
.restore();
24 console
.info
.restore();
28 it('should use noop for levels lower than the min level', function () {
29 Log
.init_logging('warn');
32 expect(console
.log
).to
.not
.have
.been
.called
;
35 it('should use console.debug for Debug', function () {
36 Log
.init_logging('debug');
38 expect(console
.debug
).to
.have
.been
.calledWith('dbg');
41 it('should use console.info for Info', function () {
42 Log
.init_logging('debug');
44 expect(console
.info
).to
.have
.been
.calledWith('inf');
47 it('should use console.warn for Warn', function () {
48 Log
.init_logging('warn');
50 expect(console
.warn
).to
.have
.been
.called
;
51 expect(console
.warn
).to
.have
.been
.calledWith('wrn');
54 it('should use console.error for Error', function () {
55 Log
.init_logging('error');
57 expect(console
.error
).to
.have
.been
.called
;
58 expect(console
.error
).to
.have
.been
.calledWith('err');
62 describe('string functions', function () {
63 it('should decode UTF-8 to DOMString correctly', function () {
64 // The capital cyrillic letter 'PE' has the hexcode 'd0 9f' in UTF-8
65 const utf8string
= String
.fromCodePoint(parseInt("d0", 16),
67 const domstring
= decodeUTF8(utf8string
);
68 expect(domstring
).to
.equal("П");
71 it('should encode DOMString to UTF-8 correctly', function () {
72 const domstring
= "åäöa";
73 const utf8string
= encodeUTF8(domstring
);
75 // The hexcode in UTF-8 for 'å' is 'c3 a5'
76 expect(utf8string
.codePointAt(0).toString(16)).to
.equal("c3");
77 expect(utf8string
.codePointAt(1).toString(16)).to
.equal("a5");
79 expect(utf8string
.codePointAt(2).toString(16)).to
.equal("c3");
80 expect(utf8string
.codePointAt(3).toString(16)).to
.equal("a4");
82 expect(utf8string
.codePointAt(4).toString(16)).to
.equal("c3");
83 expect(utf8string
.codePointAt(5).toString(16)).to
.equal("b6");
85 expect(utf8string
.codePointAt(6).toString(16)).to
.equal("61");
88 it('should keep the string intact if encoding to UTF-8 and then decoding', function() {
89 const domstring
= "κόσμε";
90 const utf8string
= encodeUTF8(domstring
);
91 expect(decodeUTF8(utf8string
)).to
.equal(domstring
);
94 it('should ignore URIErrors when UTF-8 decoding if allowLatin1 is set', function() {
95 expect(() => decodeUTF8("�")).to
.throw(URIError
);
96 expect(() => decodeUTF8("�", true)).to
.not
.throw(URIError
);
98 // Only URIError should be ignored
99 expect(() => decodeUTF8(undefVar
, true)).to
.throw(Error
);
103 // TODO(directxman12): test the conf_default and conf_defaults methods
104 // TODO(directxman12): test the event methods (addEvent, removeEvent, stopEvent)
105 // TODO(directxman12): figure out a good way to test getPosition and getEventPosition
106 // TODO(directxman12): figure out how to test the browser detection functions properly
107 // (we can't really test them against the browsers, except for Gecko
108 // via PhantomJS, the default test driver)
110 /* eslint-enable no-console */