]> git.proxmox.com Git - mirror_xterm.js.git/blame - test/composition-helper-test.js
Merge pull request #249 from sourcelair/Tyriar-patch-3
[mirror_xterm.js.git] / test / composition-helper-test.js
CommitLineData
e1c1b07a
DI
1var assert = require('chai').assert;
2var Terminal = require('../src/xterm');
3
4describe('CompositionHelper', function () {
5 var terminal;
6 var compositionHelper;
7 var compositionView;
8 var textarea;
9 var handledText;
10
11 beforeEach(function () {
12 compositionView = {
13 classList: {
14 add: function () {},
15 remove: function () {},
16 },
c24ae84b
DI
17 getBoundingClientRect: function () {
18 return { width: 0 }
19 },
e1c1b07a
DI
20 style: {
21 left: 0,
22 top: 0
23 },
24 textContent: ''
7048f6ed 25 };
e1c1b07a 26 textarea = {
89d29bbc
DI
27 value: '',
28 style: {
29 left: 0,
30 top: 0
31 }
7048f6ed 32 };
e1c1b07a
DI
33 terminal = {
34 element: {
35 querySelector: function () {
36 return { offsetLeft: 0, offsetTop: 0 };
37 }
38 },
39 handler: function (text) {
40 handledText += text;
e1c1b07a 41 }
7048f6ed 42 };
e1c1b07a
DI
43 handledText = '';
44 compositionHelper = new Terminal.CompositionHelper(textarea, compositionView, terminal);
45 });
46
47 describe('Public API', function () {
48 it('should define CompositionHelper.prototype.compositionstart', function () {
49 assert.isDefined(Terminal.CompositionHelper.prototype.compositionstart);
50 });
51 it('should define CompositionHelper.prototype.compositionupdate', function () {
52 assert.isDefined(Terminal.CompositionHelper.prototype.compositionupdate);
53 });
54 it('should define CompositionHelper.prototype.compositionend', function () {
55 assert.isDefined(Terminal.CompositionHelper.prototype.compositionend);
56 });
57 it('should define CompositionHelper.prototype.finalizeComposition', function () {
58 assert.isDefined(Terminal.CompositionHelper.prototype.finalizeComposition);
59 });
60 it('should define CompositionHelper.prototype.handleAnyTextareaChanges', function () {
61 assert.isDefined(Terminal.CompositionHelper.prototype.handleAnyTextareaChanges);
62 });
89d29bbc
DI
63 it('should define CompositionHelper.prototype.updateCompositionElements', function () {
64 assert.isDefined(Terminal.CompositionHelper.prototype.updateCompositionElements);
e1c1b07a
DI
65 });
66 it('should define CompositionHelper.isComposing', function () {
67 assert.isDefined(compositionHelper.isComposing);
68 });
69 it('should define CompositionHelper.isSendingComposition', function () {
70 assert.isDefined(compositionHelper.isSendingComposition);
71 });
72 });
73
74 describe('Input', function () {
75 it('Should insert simple characters', function (done) {
14a62c0f 76 // First character 'ㅇ'
e1c1b07a
DI
77 compositionHelper.compositionstart();
78 compositionHelper.compositionupdate({ data: 'ㅇ' });
79 textarea.value = 'ㅇ';
80 setTimeout(function() { // wait for any textarea updates
81 compositionHelper.compositionend();
82 setTimeout(function() { // wait for any textarea updates
83 assert.equal(handledText, 'ㅇ');
14a62c0f 84 // Second character 'ㅇ'
e1c1b07a
DI
85 compositionHelper.compositionstart();
86 compositionHelper.compositionupdate({ data: 'ㅇ' });
87 textarea.value = 'ㅇㅇ';
88 setTimeout(function() { // wait for any textarea updates
89 compositionHelper.compositionend();
90 setTimeout(function() { // wait for any textarea updates
91 assert.equal(handledText, 'ㅇㅇ');
92 done();
93 }, 0);
94 }, 0);
95 }, 0);
96 }, 0);
97 });
98
99 it('Should insert complex characters', function (done) {
14a62c0f 100 // First character '앙'
e1c1b07a
DI
101 compositionHelper.compositionstart();
102 compositionHelper.compositionupdate({ data: 'ㅇ' });
103 textarea.value = 'ㅇ';
104 setTimeout(function() { // wait for any textarea updates
105 compositionHelper.compositionupdate({ data: '아' });
106 textarea.value = '아';
107 setTimeout(function() { // wait for any textarea updates
108 compositionHelper.compositionupdate({ data: '앙' });
109 textarea.value = '앙';
110 setTimeout(function() { // wait for any textarea updates
111 compositionHelper.compositionend();
112 setTimeout(function() { // wait for any textarea updates
113 assert.equal(handledText, '앙');
14a62c0f 114 // Second character '앙'
e1c1b07a
DI
115 compositionHelper.compositionstart();
116 compositionHelper.compositionupdate({ data: 'ㅇ' });
117 textarea.value = '앙ㅇ';
118 setTimeout(function() { // wait for any textarea updates
119 compositionHelper.compositionupdate({ data: '아' });
120 textarea.value = '앙아';
121 setTimeout(function() { // wait for any textarea updates
122 compositionHelper.compositionupdate({ data: '앙' });
123 textarea.value = '앙앙';
124 setTimeout(function() { // wait for any textarea updates
125 compositionHelper.compositionend();
126 setTimeout(function() { // wait for any textarea updates
127 assert.equal(handledText, '앙앙');
128 done();
129 }, 0);
130 }, 0);
131 }, 0);
132 }, 0);
133 }, 0);
134 }, 0);
135 }, 0);
136 }, 0);
137 });
138
139 it('Should insert complex characters that change with following character', function (done) {
14a62c0f 140 // First character '아'
e1c1b07a
DI
141 compositionHelper.compositionstart();
142 compositionHelper.compositionupdate({ data: 'ㅇ' });
143 textarea.value = 'ㅇ';
144 setTimeout(function() { // wait for any textarea updates
145 compositionHelper.compositionupdate({ data: '아' });
146 textarea.value = '아';
147 setTimeout(function() { // wait for any textarea updates
14a62c0f 148 // Start second character '아' in first character
e1c1b07a
DI
149 compositionHelper.compositionupdate({ data: '앙' });
150 textarea.value = '앙';
151 setTimeout(function() { // wait for any textarea updates
152 compositionHelper.compositionend();
153 compositionHelper.compositionstart();
154 compositionHelper.compositionupdate({ data: '아' });
155 textarea.value = '아아'
156 setTimeout(function() { // wait for any textarea updates
157 compositionHelper.compositionend();
158 setTimeout(function() { // wait for any textarea updates
159 assert.equal(handledText, '아아');
160 done();
161 }, 0);
162 }, 0);
163 }, 0);
164 }, 0);
165 }, 0);
166 });
167
14a62c0f
DI
168 it('Should insert multi-characters compositions', function (done) {
169 // First character 'だ'
170 compositionHelper.compositionstart();
171 compositionHelper.compositionupdate({ data: 'd' });
172 textarea.value = 'd';
173 setTimeout(function() { // wait for any textarea updates
174 compositionHelper.compositionupdate({ data: 'だ' });
175 textarea.value = 'だ';
176 setTimeout(function() { // wait for any textarea updates
177 // Second character 'あ'
178 compositionHelper.compositionupdate({ data: 'だあ' });
179 textarea.value = 'だあ';
180 setTimeout(function() { // wait for any textarea updates
181 compositionHelper.compositionend();
182 setTimeout(function() { // wait for any textarea updates
183 assert.equal(handledText, 'だあ');
184 done();
185 }, 0);
186 }, 0);
187 }, 0);
188 }, 0);
e1c1b07a
DI
189 });
190
14a62c0f
DI
191 it('Should insert multi-character compositions that are converted to other characters with the same length', function (done) {
192 // First character 'だ'
193 compositionHelper.compositionstart();
194 compositionHelper.compositionupdate({ data: 'd' });
195 textarea.value = 'd';
196 setTimeout(function() { // wait for any textarea updates
197 compositionHelper.compositionupdate({ data: 'だ' });
198 textarea.value = 'だ';
199 setTimeout(function() { // wait for any textarea updates
200 // Second character 'ー'
201 compositionHelper.compositionupdate({ data: 'だー' });
202 textarea.value = 'だー';
203 setTimeout(function() { // wait for any textarea updates
204 // Convert to katakana 'ダー'
205 compositionHelper.compositionupdate({ data: 'ダー' });
206 textarea.value = 'ダー';
207 setTimeout(function() { // wait for any textarea updates
208 compositionHelper.compositionend();
209 setTimeout(function() { // wait for any textarea updates
210 assert.equal(handledText, 'ダー');
211 done();
212 }, 0);
213 }, 0);
214 }, 0);
215 }, 0);
216 }, 0);
217 })
218
219 it('Should insert multi-character compositions that are converted to other characters with different lengths', function (done) {
220 // First character 'い'
221 compositionHelper.compositionstart();
222 compositionHelper.compositionupdate({ data: 'い' });
223 textarea.value = 'い';
224 setTimeout(function() { // wait for any textarea updates
225 // Second character 'ま'
226 compositionHelper.compositionupdate({ data: 'いm' });
227 textarea.value = 'いm';
228 setTimeout(function() { // wait for any textarea updates
229 compositionHelper.compositionupdate({ data: 'いま' });
230 textarea.value = 'いま';
231 setTimeout(function() { // wait for any textarea updates
232 // Convert to kanji '今'
233 compositionHelper.compositionupdate({ data: '今' });
234 textarea.value = '今';
235 setTimeout(function() { // wait for any textarea updates
236 compositionHelper.compositionend();
237 setTimeout(function() { // wait for any textarea updates
238 assert.equal(handledText, '今');
239 done();
240 }, 0);
241 }, 0);
242 }, 0);
243 }, 0);
244 }, 0);
e1c1b07a 245 });
89d29bbc 246
14a62c0f
DI
247 it('Should insert non-composition characters input immediately after composition characters', function (done) {
248 // First character 'ㅇ'
89d29bbc
DI
249 compositionHelper.compositionstart();
250 compositionHelper.compositionupdate({ data: 'ㅇ' });
251 textarea.value = 'ㅇ';
252 setTimeout(function() { // wait for any textarea updates
253 compositionHelper.compositionend();
14a62c0f 254 // Second character '1' (a non-composition character)
89d29bbc
DI
255 textarea.value = 'ㅇ1';
256 setTimeout(function() { // wait for any textarea updates
257 assert.equal(handledText, 'ㅇ1');
258 done();
259 }, 0);
260 }, 0);
261 });
e1c1b07a
DI
262 });
263});