]> git.proxmox.com Git - mirror_novnc.git/blame - tests/test.util.js
feat: add French localization strings
[mirror_novnc.git] / tests / test.util.js
CommitLineData
8727f598 1/* eslint-disable no-console */
2b5f94fa 2const expect = chai.expect;
d21cd6c1 3
dfae3209 4import * as Log from '../core/util/logging.js';
80c72e92 5import { encodeUTF8, decodeUTF8 } from '../core/util/strings.js';
dfae3209 6
2c5491e1 7describe('Utils', function () {
d21cd6c1
SR
8 "use strict";
9
d21cd6c1
SR
10 describe('logging functions', function () {
11 beforeEach(function () {
12 sinon.spy(console, 'log');
0ae5b50a 13 sinon.spy(console, 'debug');
d21cd6c1
SR
14 sinon.spy(console, 'warn');
15 sinon.spy(console, 'error');
e4fef7be 16 sinon.spy(console, 'info');
d21cd6c1
SR
17 });
18
19 afterEach(function () {
0242c032
SM
20 console.log.restore();
21 console.debug.restore();
22 console.warn.restore();
23 console.error.restore();
24 console.info.restore();
a7fe079f 25 Log.initLogging();
d21cd6c1
SR
26 });
27
28 it('should use noop for levels lower than the min level', function () {
a7fe079f 29 Log.initLogging('warn');
dfae3209
SR
30 Log.Debug('hi');
31 Log.Info('hello');
d21cd6c1
SR
32 expect(console.log).to.not.have.been.called;
33 });
34
0ae5b50a 35 it('should use console.debug for Debug', function () {
a7fe079f 36 Log.initLogging('debug');
dfae3209 37 Log.Debug('dbg');
0ae5b50a 38 expect(console.debug).to.have.been.calledWith('dbg');
e4fef7be 39 });
c464f47e 40
e4fef7be 41 it('should use console.info for Info', function () {
a7fe079f 42 Log.initLogging('debug');
dfae3209 43 Log.Info('inf');
e4fef7be 44 expect(console.info).to.have.been.calledWith('inf');
d21cd6c1
SR
45 });
46
47 it('should use console.warn for Warn', function () {
a7fe079f 48 Log.initLogging('warn');
dfae3209 49 Log.Warn('wrn');
d21cd6c1
SR
50 expect(console.warn).to.have.been.called;
51 expect(console.warn).to.have.been.calledWith('wrn');
52 });
53
54 it('should use console.error for Error', function () {
a7fe079f 55 Log.initLogging('error');
dfae3209 56 Log.Error('err');
d21cd6c1
SR
57 expect(console.error).to.have.been.called;
58 expect(console.error).to.have.been.calledWith('err');
59 });
60 });
61
80c72e92
SM
62 describe('string functions', function () {
63 it('should decode UTF-8 to DOMString correctly', function () {
64fdd336 64 const utf8string = '\xd0\x9f';
80c72e92
SM
65 const domstring = decodeUTF8(utf8string);
66 expect(domstring).to.equal("П");
67 });
68
69 it('should encode DOMString to UTF-8 correctly', function () {
70 const domstring = "åäöa";
71 const utf8string = encodeUTF8(domstring);
64fdd336 72 expect(utf8string).to.equal('\xc3\xa5\xc3\xa4\xc3\xb6\x61');
80c72e92
SM
73 });
74
64fdd336
SM
75 it('should allow Latin-1 strings if allowLatin1 is set when decoding', function () {
76 const latin1string = '\xe5\xe4\xf6';
77 expect(() => decodeUTF8(latin1string)).to.throw(Error);
78 expect(decodeUTF8(latin1string, true)).to.equal('åäö');
80c72e92
SM
79 });
80 });
81
d21cd6c1 82 // TODO(directxman12): test the conf_default and conf_defaults methods
d21cd6c1
SR
83 // TODO(directxman12): test the event methods (addEvent, removeEvent, stopEvent)
84 // TODO(directxman12): figure out a good way to test getPosition and getEventPosition
ee7d4c61 85 // TODO(directxman12): figure out how to test the browser detection functions properly
d21cd6c1
SR
86 // (we can't really test them against the browsers, except for Gecko
87 // via PhantomJS, the default test driver)
d21cd6c1 88});
8727f598 89/* eslint-enable no-console */