]> git.proxmox.com Git - mirror_xterm.js.git/blame - test/composition-helper-test.js
Fix non-composition char input after composition char + test
[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 },
17 style: {
18 left: 0,
19 top: 0
20 },
21 textContent: ''
22 }
23 textarea = {
89d29bbc
DI
24 value: '',
25 style: {
26 left: 0,
27 top: 0
28 }
e1c1b07a
DI
29 }
30 terminal = {
31 element: {
32 querySelector: function () {
33 return { offsetLeft: 0, offsetTop: 0 };
34 }
35 },
36 handler: function (text) {
37 handledText += text;
38 console.log('handler - ' + text);
39 }
40 }
41 handledText = '';
42 compositionHelper = new Terminal.CompositionHelper(textarea, compositionView, terminal);
43 });
44
45 describe('Public API', function () {
46 it('should define CompositionHelper.prototype.compositionstart', function () {
47 assert.isDefined(Terminal.CompositionHelper.prototype.compositionstart);
48 });
49 it('should define CompositionHelper.prototype.compositionupdate', function () {
50 assert.isDefined(Terminal.CompositionHelper.prototype.compositionupdate);
51 });
52 it('should define CompositionHelper.prototype.compositionend', function () {
53 assert.isDefined(Terminal.CompositionHelper.prototype.compositionend);
54 });
55 it('should define CompositionHelper.prototype.finalizeComposition', function () {
56 assert.isDefined(Terminal.CompositionHelper.prototype.finalizeComposition);
57 });
58 it('should define CompositionHelper.prototype.handleAnyTextareaChanges', function () {
59 assert.isDefined(Terminal.CompositionHelper.prototype.handleAnyTextareaChanges);
60 });
89d29bbc
DI
61 it('should define CompositionHelper.prototype.updateCompositionElements', function () {
62 assert.isDefined(Terminal.CompositionHelper.prototype.updateCompositionElements);
e1c1b07a
DI
63 });
64 it('should define CompositionHelper.isComposing', function () {
65 assert.isDefined(compositionHelper.isComposing);
66 });
67 it('should define CompositionHelper.isSendingComposition', function () {
68 assert.isDefined(compositionHelper.isSendingComposition);
69 });
70 });
71
72 describe('Input', function () {
73 it('Should insert simple characters', function (done) {
74 // First character
75 compositionHelper.compositionstart();
76 compositionHelper.compositionupdate({ data: 'ㅇ' });
77 textarea.value = 'ㅇ';
78 setTimeout(function() { // wait for any textarea updates
79 compositionHelper.compositionend();
80 setTimeout(function() { // wait for any textarea updates
81 assert.equal(handledText, 'ㅇ');
82 // Second character
83 compositionHelper.compositionstart();
84 compositionHelper.compositionupdate({ data: 'ㅇ' });
85 textarea.value = 'ㅇㅇ';
86 setTimeout(function() { // wait for any textarea updates
87 compositionHelper.compositionend();
88 setTimeout(function() { // wait for any textarea updates
89 assert.equal(handledText, 'ㅇㅇ');
90 done();
91 }, 0);
92 }, 0);
93 }, 0);
94 }, 0);
95 });
96
97 it('Should insert complex characters', function (done) {
98 // First character
99 compositionHelper.compositionstart();
100 compositionHelper.compositionupdate({ data: 'ㅇ' });
101 textarea.value = 'ㅇ';
102 setTimeout(function() { // wait for any textarea updates
103 compositionHelper.compositionupdate({ data: '아' });
104 textarea.value = '아';
105 setTimeout(function() { // wait for any textarea updates
106 compositionHelper.compositionupdate({ data: '앙' });
107 textarea.value = '앙';
108 setTimeout(function() { // wait for any textarea updates
109 compositionHelper.compositionend();
110 setTimeout(function() { // wait for any textarea updates
111 assert.equal(handledText, '앙');
112 // Second character
113 compositionHelper.compositionstart();
114 compositionHelper.compositionupdate({ data: 'ㅇ' });
115 textarea.value = '앙ㅇ';
116 setTimeout(function() { // wait for any textarea updates
117 compositionHelper.compositionupdate({ data: '아' });
118 textarea.value = '앙아';
119 setTimeout(function() { // wait for any textarea updates
120 compositionHelper.compositionupdate({ data: '앙' });
121 textarea.value = '앙앙';
122 setTimeout(function() { // wait for any textarea updates
123 compositionHelper.compositionend();
124 setTimeout(function() { // wait for any textarea updates
125 assert.equal(handledText, '앙앙');
126 done();
127 }, 0);
128 }, 0);
129 }, 0);
130 }, 0);
131 }, 0);
132 }, 0);
133 }, 0);
134 }, 0);
135 });
136
137 it('Should insert complex characters that change with following character', function (done) {
138 // First character
139 compositionHelper.compositionstart();
140 compositionHelper.compositionupdate({ data: 'ㅇ' });
141 textarea.value = 'ㅇ';
142 setTimeout(function() { // wait for any textarea updates
143 compositionHelper.compositionupdate({ data: '아' });
144 textarea.value = '아';
145 setTimeout(function() { // wait for any textarea updates
146 // Start second character in first character
147 compositionHelper.compositionupdate({ data: '앙' });
148 textarea.value = '앙';
149 setTimeout(function() { // wait for any textarea updates
150 compositionHelper.compositionend();
151 compositionHelper.compositionstart();
152 compositionHelper.compositionupdate({ data: '아' });
153 textarea.value = '아아'
154 setTimeout(function() { // wait for any textarea updates
155 compositionHelper.compositionend();
156 setTimeout(function() { // wait for any textarea updates
157 assert.equal(handledText, '아아');
158 done();
159 }, 0);
160 }, 0);
161 }, 0);
162 }, 0);
163 }, 0);
164 });
165
166 it('Should insert multi-line charcters', function () {
167 // TODO: Implement a hiragana example
168 });
169
170 it('Should insert multi-line charcters that are converted to other characters', function () {
171 // TODO: Implement a hiragana -> kanji example
172 });
89d29bbc
DI
173
174 it('Should insert non-composition charcters input immediately after composition characters', function () {
175 // First character
176 compositionHelper.compositionstart();
177 compositionHelper.compositionupdate({ data: 'ㅇ' });
178 textarea.value = 'ㅇ';
179 setTimeout(function() { // wait for any textarea updates
180 compositionHelper.compositionend();
181 // Second character is non-composition character (1)
182 textarea.value = 'ㅇ1';
183 setTimeout(function() { // wait for any textarea updates
184 assert.equal(handledText, 'ㅇ1');
185 done();
186 }, 0);
187 }, 0);
188 });
e1c1b07a
DI
189 });
190});