Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(233)

Side by Side Diff: remoting/webapp/unittests/l10n_unittest.js

Issue 399273003: Add unit test for l10n.js (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/remoting_webapp_files.gypi ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 (function() {
6
7 'use strict';
8
9 module('l10n', {
10 setup: function() {
11 chrome.i18n = chrome.i18n || {};
12 chrome.i18n.getMessage = chrome.i18n.getMessage || function() {};
Jamie 2014/07/18 02:04:50 The use of || here doesn't feel right. It's genera
kelvinp 2014/07/21 17:46:22 Done.
13 sinon.stub(chrome.i18n, 'getMessage');
14 },
15 teardown: function() {
16 chrome.i18n.getMessage.restore();
17 }
18 });
19
20 test('getTranslationOrError(tag) should return tag on error', function() {
21 var translation = l10n.getTranslationOrError('not_existing_tag');
Jamie 2014/07/18 02:04:51 s/no_existing/non_existent/?
kelvinp 2014/07/21 17:46:22 Done.
22 equal(translation, 'not_existing_tag');
23 });
24
25 test('localizeElementFromTag() should replace innerText by default',
26 function() {
27 var element = document.createElement('div');
28 chrome.i18n.getMessage.withArgs('tag').returns('<b>Hello World</b>');
29
30 l10n.localizeElementFromTag(element, 'tag');
31
32 equal(element.innerText, '<b>Hello World</b>');
33 equal(element.innerHTML, '&lt;b&gt;Hello World&lt;/b&gt;');
Jamie 2014/07/18 02:04:51 Why test both of these? Doesn't the first test imp
kelvinp 2014/07/21 17:46:22 Done.
34 });
35
36 test('localizeElementFromTag() should replace innerHTML if flag is set',
37 function() {
38 var element = document.createElement('div');
39 chrome.i18n.getMessage.withArgs('tag').returns('<b>Hello World</b>');
40
41 l10n.localizeElementFromTag(element, 'tag', null, true);
42
43 equal(element.innerText, 'Hello World');
44 equal(element.innerHTML, '<b>Hello World</b>');
45 });
46
47 test(
48 'localizeElement() should replace innerText using the "i18n-content" ' +
49 'attribute as the tag',
50 function() {
51 var element = document.createElement('div');
52 element.setAttribute('i18n-content', 'tag');
53 chrome.i18n.getMessage.withArgs('tag').returns('<b>Hello World</b>');
54
55 l10n.localizeElement(element);
56
57 equal(element.innerText, '<b>Hello World</b>');
58 equal(element.innerHTML, '&lt;b&gt;Hello World&lt;/b&gt;');
59 });
60
61 test(
62 'localize() should replace element title using the "i18n-title" ' +
63 'attribute as the tag',
64 function() {
65 var fixture = document.getElementById('qunit-fixture');
66 fixture.innerHTML = '<div class="target" i18n-title="tag"></div>';
67 chrome.i18n.getMessage.withArgs('tag').returns('localized title');
68
69 l10n.localize();
70
71 var target = document.querySelector('.target');
72 equal(target.title, 'localized title');
73 });
74
75 test('localize() should support string substitutions', function() {
76 var fixture = document.getElementById('qunit-fixture');
Jamie 2014/07/18 02:04:51 Nit: indentation.
kelvinp 2014/07/21 17:46:22 Done.
77 fixture.innerHTML = '<div class="target" i18n-content="tag"' +
78 ' i18n-value-1="param1" i18n-value-2="param2"></div>';
Jamie 2014/07/18 02:04:50 For inline HTML that's too long for one line, I th
kelvinp 2014/07/21 17:46:22 Done.
79
80 chrome.i18n.getMessage.withArgs('tag', ['param1', 'param2'])
81 .returns('localized');
82
83 l10n.localize();
84
85 var target = document.querySelector('.target');
86 equal(target.innerText, 'localized');
87 });
88
89 test('localize() should support tag substitutions', function() {
90 var fixture = document.getElementById('qunit-fixture');
91 fixture.innerHTML =
92 '<div class="target" i18n-content="tag"' +
93 ' i18n-value-name-1="tag1" i18n-value-name-2="tag2"></div>';
94
95 var getMessage = chrome.i18n.getMessage;
96 getMessage.withArgs('tag1').returns('param1');
97 getMessage.withArgs('tag2').returns('param2');
98 getMessage.withArgs('tag', ['param1', 'param2']).returns('localized');
99
100 l10n.localize();
101
102 var target = document.querySelector('.target');
103 equal(target.innerText, 'localized');
104 });
105
106 })();
OLDNEW
« no previous file with comments | « remoting/remoting_webapp_files.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698