]>
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('logging functions', function () {
11 beforeEach(function () {
12 sinon
.spy(console
, 'log');
13 sinon
.spy(console
, 'warn');
14 sinon
.spy(console
, 'error');
15 sinon
.spy(console
, 'info');
18 afterEach(function () {
19 console
.log
.restore();
20 console
.warn
.restore();
21 console
.error
.restore();
22 console
.info
.restore();
25 it('should use noop for levels lower than the min level', function () {
26 Util
.init_logging('warn');
29 expect(console
.log
).to
.not
.have
.been
.called
;
32 it('should use console.log for Debug', function () {
33 Util
.init_logging('debug');
35 expect(console
.log
).to
.have
.been
.calledWith('dbg');
38 it('should use console.info for Info', function () {
39 Util
.init_logging('debug');
41 expect(console
.info
).to
.have
.been
.calledWith('inf');
44 it('should use console.warn for Warn', function () {
45 Util
.init_logging('warn');
47 expect(console
.warn
).to
.have
.been
.called
;
48 expect(console
.warn
).to
.have
.been
.calledWith('wrn');
51 it('should use console.error for Error', function () {
52 Util
.init_logging('error');
54 expect(console
.error
).to
.have
.been
.called
;
55 expect(console
.error
).to
.have
.been
.calledWith('err');
59 describe('language selection', function () {
61 beforeEach(function () {
62 // window.navigator is a protected read-only property in many
63 // environments, so we need to redefine it whilst running these
65 origNavigator
= Object
.getOwnPropertyDescriptor(window
, "navigator");
66 Object
.defineProperty(window
, "navigator", {value
: {}});
67 window
.navigator
.languages
= [];
69 afterEach(function () {
70 Object
.defineProperty(window
, "navigator", origNavigator
);
73 it('should use English by default', function() {
74 expect(Util
.Localisation
.language
).to
.equal('en');
76 it('should use English if no user language matches', function() {
77 window
.navigator
.languages
= ["nl", "de"];
78 Util
.Localisation
.setup(["es", "fr"]);
79 expect(Util
.Localisation
.language
).to
.equal('en');
81 it('should use the most preferred user language', function() {
82 window
.navigator
.languages
= ["nl", "de", "fr"];
83 Util
.Localisation
.setup(["es", "fr", "de"]);
84 expect(Util
.Localisation
.language
).to
.equal('de');
86 it('should prefer sub-languages languages', function() {
87 window
.navigator
.languages
= ["pt-BR"];
88 Util
.Localisation
.setup(["pt", "pt-BR"]);
89 expect(Util
.Localisation
.language
).to
.equal('pt-BR');
91 it('should fall back to language "parents"', function() {
92 window
.navigator
.languages
= ["pt-BR"];
93 Util
.Localisation
.setup(["fr", "pt", "de"]);
94 expect(Util
.Localisation
.language
).to
.equal('pt');
96 it('should not use specific language when user asks for a generic language', function() {
97 window
.navigator
.languages
= ["pt", "de"];
98 Util
.Localisation
.setup(["fr", "pt-BR", "de"]);
99 expect(Util
.Localisation
.language
).to
.equal('de');
101 it('should handle underscore as a separator', function() {
102 window
.navigator
.languages
= ["pt-BR"];
103 Util
.Localisation
.setup(["pt_BR"]);
104 expect(Util
.Localisation
.language
).to
.equal('pt_BR');
106 it('should handle difference in case', function() {
107 window
.navigator
.languages
= ["pt-br"];
108 Util
.Localisation
.setup(["pt-BR"]);
109 expect(Util
.Localisation
.language
).to
.equal('pt-BR');
113 // TODO(directxman12): test the conf_default and conf_defaults methods
114 // TODO(directxman12): test decodeUTF8
115 // TODO(directxman12): test the event methods (addEvent, removeEvent, stopEvent)
116 // TODO(directxman12): figure out a good way to test getPosition and getEventPosition
117 // TODO(directxman12): figure out how to test the browser detection functions properly
118 // (we can't really test them against the browsers, except for Gecko
119 // via PhantomJS, the default test driver)