Files
noVNC/tests/test.util.js
T

90 lines
3.3 KiB
JavaScript
Raw Normal View History

2018-05-24 00:25:44 +03:00
/* eslint-disable no-console */
2018-05-24 00:27:09 +03:00
const expect = chai.expect;
2014-05-21 14:54:28 -04:00
2017-02-05 12:34:47 -05:00
import * as Log from '../core/util/logging.js';
import { encodeUTF8, decodeUTF8 } from '../core/util/strings.js';
2017-02-05 12:34:47 -05:00
2018-09-06 17:34:15 +02:00
describe('Utils', function () {
2014-05-21 14:54:28 -04:00
"use strict";
describe('logging functions', function () {
beforeEach(function () {
sinon.spy(console, 'log');
sinon.spy(console, 'debug');
2014-05-21 14:54:28 -04:00
sinon.spy(console, 'warn');
sinon.spy(console, 'error');
2016-09-03 13:58:32 -04:00
sinon.spy(console, 'info');
2014-05-21 14:54:28 -04:00
});
afterEach(function () {
2017-09-28 14:11:44 +02:00
console.log.restore();
console.debug.restore();
console.warn.restore();
console.error.restore();
console.info.restore();
Log.init_logging();
2014-05-21 14:54:28 -04:00
});
it('should use noop for levels lower than the min level', function () {
2017-02-05 12:34:47 -05:00
Log.init_logging('warn');
Log.Debug('hi');
Log.Info('hello');
2014-05-21 14:54:28 -04:00
expect(console.log).to.not.have.been.called;
});
it('should use console.debug for Debug', function () {
2017-02-05 12:34:47 -05:00
Log.init_logging('debug');
Log.Debug('dbg');
expect(console.debug).to.have.been.calledWith('dbg');
2016-09-03 13:58:32 -04:00
});
2017-05-13 01:45:23 +02:00
2016-09-03 13:58:32 -04:00
it('should use console.info for Info', function () {
2017-02-05 12:34:47 -05:00
Log.init_logging('debug');
Log.Info('inf');
2016-09-03 13:58:32 -04:00
expect(console.info).to.have.been.calledWith('inf');
2014-05-21 14:54:28 -04:00
});
it('should use console.warn for Warn', function () {
2017-02-05 12:34:47 -05:00
Log.init_logging('warn');
Log.Warn('wrn');
2014-05-21 14:54:28 -04:00
expect(console.warn).to.have.been.called;
expect(console.warn).to.have.been.calledWith('wrn');
});
it('should use console.error for Error', function () {
2017-02-05 12:34:47 -05:00
Log.init_logging('error');
Log.Error('err');
2014-05-21 14:54:28 -04:00
expect(console.error).to.have.been.called;
expect(console.error).to.have.been.calledWith('err');
});
});
describe('string functions', function () {
it('should decode UTF-8 to DOMString correctly', function () {
2020-01-03 10:41:34 +01:00
const utf8string = '\xd0\x9f';
const domstring = decodeUTF8(utf8string);
expect(domstring).to.equal("П");
});
it('should encode DOMString to UTF-8 correctly', function () {
const domstring = "åäöa";
const utf8string = encodeUTF8(domstring);
2020-01-03 10:41:34 +01:00
expect(utf8string).to.equal('\xc3\xa5\xc3\xa4\xc3\xb6\x61');
});
2020-01-03 10:41:34 +01:00
it('should allow Latin-1 strings if allowLatin1 is set when decoding', function () {
const latin1string = '\xe5\xe4\xf6';
expect(() => decodeUTF8(latin1string)).to.throw(Error);
expect(decodeUTF8(latin1string, true)).to.equal('åäö');
});
});
2014-05-21 14:54:28 -04:00
// TODO(directxman12): test the conf_default and conf_defaults methods
// TODO(directxman12): test the event methods (addEvent, removeEvent, stopEvent)
// TODO(directxman12): figure out a good way to test getPosition and getEventPosition
2014-05-21 15:12:20 -04:00
// TODO(directxman12): figure out how to test the browser detection functions properly
2014-05-21 14:54:28 -04:00
// (we can't really test them against the browsers, except for Gecko
// via PhantomJS, the default test driver)
});
2018-05-24 00:25:44 +03:00
/* eslint-enable no-console */