diff options
author | Samuel Mannehed <samuel@cendio.se> | 2017-11-13 12:12:41 +0100 |
---|---|---|
committer | Samuel Mannehed <samuel@cendio.se> | 2017-11-14 15:36:12 +0100 |
commit | 7279364c9abf7131c4cc292955e0305e5adca2b7 (patch) | |
tree | b06c5386ec5f4f58fe48ca1fb4fd3f0e0e704a47 /tests | |
parent | 689580381c9f96212213bd3dd65b94b5b4e36222 (diff) | |
download | novnc-7279364c9abf7131c4cc292955e0305e5adca2b7.tar.gz |
Move localization.js to app
Since it is no longer used in core. Also splits localization tests into
a separate file.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test.localization.js | 76 | ||||
-rw-r--r-- | tests/test.util.js | 67 |
2 files changed, 76 insertions, 67 deletions
diff --git a/tests/test.localization.js b/tests/test.localization.js new file mode 100644 index 0000000..339144a --- /dev/null +++ b/tests/test.localization.js @@ -0,0 +1,76 @@ +/* jshint expr: true */ + +var assert = chai.assert; +var expect = chai.expect; + +import l10nGet, { l10n } from '../app/localization.js'; + +describe('Localization', function() { + "use strict"; + + describe('language selection', function () { + var origNavigator; + beforeEach(function () { + // window.navigator is a protected read-only property in many + // environments, so we need to redefine it whilst running these + // tests. + origNavigator = Object.getOwnPropertyDescriptor(window, "navigator"); + if (origNavigator === undefined) { + // Object.getOwnPropertyDescriptor() doesn't work + // properly in any version of IE + this.skip(); + } + + Object.defineProperty(window, "navigator", {value: {}}); + if (window.navigator.languages !== undefined) { + // Object.defineProperty() doesn't work properly in old + // versions of Chrome + this.skip(); + } + + window.navigator.languages = []; + }); + afterEach(function () { + Object.defineProperty(window, "navigator", origNavigator); + }); + + it('should use English by default', function() { + expect(l10n.language).to.equal('en'); + }); + it('should use English if no user language matches', function() { + window.navigator.languages = ["nl", "de"]; + l10n.setup(["es", "fr"]); + expect(l10n.language).to.equal('en'); + }); + it('should use the most preferred user language', function() { + window.navigator.languages = ["nl", "de", "fr"]; + l10n.setup(["es", "fr", "de"]); + expect(l10n.language).to.equal('de'); + }); + it('should prefer sub-languages languages', function() { + window.navigator.languages = ["pt-BR"]; + l10n.setup(["pt", "pt-BR"]); + expect(l10n.language).to.equal('pt-BR'); + }); + it('should fall back to language "parents"', function() { + window.navigator.languages = ["pt-BR"]; + l10n.setup(["fr", "pt", "de"]); + expect(l10n.language).to.equal('pt'); + }); + it('should not use specific language when user asks for a generic language', function() { + window.navigator.languages = ["pt", "de"]; + l10n.setup(["fr", "pt-BR", "de"]); + expect(l10n.language).to.equal('de'); + }); + it('should handle underscore as a separator', function() { + window.navigator.languages = ["pt-BR"]; + l10n.setup(["pt_BR"]); + expect(l10n.language).to.equal('pt_BR'); + }); + it('should handle difference in case', function() { + window.navigator.languages = ["pt-br"]; + l10n.setup(["pt-BR"]); + expect(l10n.language).to.equal('pt-BR'); + }); + }); +}); diff --git a/tests/test.util.js b/tests/test.util.js index 12f41d6..1eab1e9 100644 --- a/tests/test.util.js +++ b/tests/test.util.js @@ -4,7 +4,6 @@ var assert = chai.assert; var expect = chai.expect; import * as Log from '../core/util/logging.js'; -import l10nGet, { l10n } from '../core/util/localization.js'; import sinon from '../vendor/sinon.js'; @@ -63,72 +62,6 @@ describe('Utils', function() { }); }); - describe('language selection', function () { - var origNavigator; - beforeEach(function () { - // window.navigator is a protected read-only property in many - // environments, so we need to redefine it whilst running these - // tests. - origNavigator = Object.getOwnPropertyDescriptor(window, "navigator"); - if (origNavigator === undefined) { - // Object.getOwnPropertyDescriptor() doesn't work - // properly in any version of IE - this.skip(); - } - - Object.defineProperty(window, "navigator", {value: {}}); - if (window.navigator.languages !== undefined) { - // Object.defineProperty() doesn't work properly in old - // versions of Chrome - this.skip(); - } - - window.navigator.languages = []; - }); - afterEach(function () { - Object.defineProperty(window, "navigator", origNavigator); - }); - - it('should use English by default', function() { - expect(l10n.language).to.equal('en'); - }); - it('should use English if no user language matches', function() { - window.navigator.languages = ["nl", "de"]; - l10n.setup(["es", "fr"]); - expect(l10n.language).to.equal('en'); - }); - it('should use the most preferred user language', function() { - window.navigator.languages = ["nl", "de", "fr"]; - l10n.setup(["es", "fr", "de"]); - expect(l10n.language).to.equal('de'); - }); - it('should prefer sub-languages languages', function() { - window.navigator.languages = ["pt-BR"]; - l10n.setup(["pt", "pt-BR"]); - expect(l10n.language).to.equal('pt-BR'); - }); - it('should fall back to language "parents"', function() { - window.navigator.languages = ["pt-BR"]; - l10n.setup(["fr", "pt", "de"]); - expect(l10n.language).to.equal('pt'); - }); - it('should not use specific language when user asks for a generic language', function() { - window.navigator.languages = ["pt", "de"]; - l10n.setup(["fr", "pt-BR", "de"]); - expect(l10n.language).to.equal('de'); - }); - it('should handle underscore as a separator', function() { - window.navigator.languages = ["pt-BR"]; - l10n.setup(["pt_BR"]); - expect(l10n.language).to.equal('pt_BR'); - }); - it('should handle difference in case', function() { - window.navigator.languages = ["pt-br"]; - l10n.setup(["pt-BR"]); - expect(l10n.language).to.equal('pt-BR'); - }); - }); - // TODO(directxman12): test the conf_default and conf_defaults methods // TODO(directxman12): test decodeUTF8 // TODO(directxman12): test the event methods (addEvent, removeEvent, stopEvent) |