Debian Codegraph @

closure-library/closure/goog/ui/bidiinput_test.js

raw
1 // Copyright 2012 The Closure Library Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS-IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 goog.provide('goog.ui.BidiInputTest');
16 goog.setTestOnly('goog.ui.BidiInputTest');
17
18 goog.require('goog.dom');
19 goog.require('goog.testing.jsunit');
20 goog.require('goog.ui.BidiInput');
21
22 function setUp() {
23 document.body.focus();
24 }
25
26 function tearDown() {
27 document.getElementById('emptyText').value = '';
28 document.getElementById('bidiText').value = 'hello, world!';
29 }
30
31 function testEmptyInput() {
32 var bidiInput = new goog.ui.BidiInput();
33 var emptyText = goog.dom.getElement('emptyText');
34 bidiInput.decorate(emptyText);
35 assertEquals('', bidiInput.getValue());
36 bidiInput.setValue('hello!');
37 assertEquals('hello!', bidiInput.getValue());
38 }
39
40 function testSetDirection() {
41 var shalomInHebrew = '\u05e9\u05dc\u05d5\u05dd';
42 var isAGoodLanguageInHebrew =
43 '\u05d4\u05d9\u05d0 \u05e9\u05e4\u05d4 \u05d8\u05d5\u05d1\u05d4';
44 var learnInHebrew = '\u05dc\u05de\u05d3';
45
46 var bidiInput = new goog.ui.BidiInput();
47 var bidiText = goog.dom.getElement('bidiText');
48 bidiInput.decorate(bidiText);
49 assertEquals('ltr', bidiInput.getDirection());
50
51 bidiInput.setValue(shalomInHebrew);
52 assertEquals('rtl', bidiInput.getDirection());
53
54 bidiInput.setValue('hello!');
55 assertEquals('ltr', bidiInput.getDirection());
56
57 bidiInput.setValue(':) , ? ! ' + shalomInHebrew);
58 assertEquals('rtl', bidiInput.getDirection());
59
60 bidiInput.setValue(':) , ? ! hello!');
61 assertEquals('ltr', bidiInput.getDirection());
62
63 bidiInput.setValue(' ;) ');
64 assertEquals(null, bidiInput.getDirection());
65
66 bidiInput.setValue(shalomInHebrew + ', how are you today?');
67 assertEquals('ltr', bidiInput.getDirection());
68
69 bidiInput.setValue('Hello is ' + shalomInHebrew + ' in Hebrew');
70 assertEquals('ltr', bidiInput.getDirection());
71
72 bidiInput.setValue('JavaScript ' + isAGoodLanguageInHebrew);
73 assertEquals('rtl', bidiInput.getDirection());
74
75 bidiInput.setValue(learnInHebrew + ' JavaScript');
76 assertEquals('rtl', bidiInput.getDirection());
77
78 bidiInput.setValue('');
79 assertEquals(null, bidiInput.getDirection());
80 }
81
82 function testSetDirection_inContenteditableDiv() {
83 var shalomInHebrew = '\u05e9\u05dc\u05d5\u05dd';
84 var isAGoodLanguageInHebrew =
85 '\u05d4\u05d9\u05d0 \u05e9\u05e4\u05d4 \u05d8\u05d5\u05d1\u05d4';
86 var learnInHebrew = '\u05dc\u05de\u05d3';
87
88 var bidiInput = new goog.ui.BidiInput();
89 var bidiTextDiv = goog.dom.getElement('bidiTextDiv');
90 bidiInput.decorate(bidiTextDiv);
91 assertEquals('ltr', bidiInput.getDirection());
92
93 bidiInput.setValue(shalomInHebrew);
94 assertEquals('rtl', bidiInput.getDirection());
95
96 bidiInput.setValue('hello!');
97 assertEquals('ltr', bidiInput.getDirection());
98
99 bidiInput.setValue(':) , ? ! ' + shalomInHebrew);
100 assertEquals('rtl', bidiInput.getDirection());
101
102 bidiInput.setValue(':) , ? ! hello!');
103 assertEquals('ltr', bidiInput.getDirection());
104
105 bidiInput.setValue(' ;) ');
106 assertEquals(null, bidiInput.getDirection());
107
108 bidiInput.setValue(shalomInHebrew + ', how are you today?');
109 assertEquals('ltr', bidiInput.getDirection());
110
111 bidiInput.setValue('Hello is ' + shalomInHebrew + ' in Hebrew');
112 assertEquals('ltr', bidiInput.getDirection());
113
114 bidiInput.setValue('JavaScript ' + isAGoodLanguageInHebrew);
115 assertEquals('rtl', bidiInput.getDirection());
116
117 bidiInput.setValue(learnInHebrew + ' JavaScript');
118 assertEquals('rtl', bidiInput.getDirection());
119
120 bidiInput.setValue('');
121 assertEquals(null, bidiInput.getDirection());
122 }