]>
Commit | Line | Data |
---|---|---|
e1c1b07a DI |
1 | var assert = require('chai').assert; |
2 | var Terminal = require('../src/xterm'); | |
3 | ||
4 | describe('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 = { | |
24 | value: '' | |
25 | } | |
26 | terminal = { | |
27 | element: { | |
28 | querySelector: function () { | |
29 | return { offsetLeft: 0, offsetTop: 0 }; | |
30 | } | |
31 | }, | |
32 | handler: function (text) { | |
33 | handledText += text; | |
34 | console.log('handler - ' + text); | |
35 | } | |
36 | } | |
37 | handledText = ''; | |
38 | compositionHelper = new Terminal.CompositionHelper(textarea, compositionView, terminal); | |
39 | }); | |
40 | ||
41 | describe('Public API', function () { | |
42 | it('should define CompositionHelper.prototype.compositionstart', function () { | |
43 | assert.isDefined(Terminal.CompositionHelper.prototype.compositionstart); | |
44 | }); | |
45 | it('should define CompositionHelper.prototype.compositionupdate', function () { | |
46 | assert.isDefined(Terminal.CompositionHelper.prototype.compositionupdate); | |
47 | }); | |
48 | it('should define CompositionHelper.prototype.compositionend', function () { | |
49 | assert.isDefined(Terminal.CompositionHelper.prototype.compositionend); | |
50 | }); | |
51 | it('should define CompositionHelper.prototype.finalizeComposition', function () { | |
52 | assert.isDefined(Terminal.CompositionHelper.prototype.finalizeComposition); | |
53 | }); | |
54 | it('should define CompositionHelper.prototype.handleAnyTextareaChanges', function () { | |
55 | assert.isDefined(Terminal.CompositionHelper.prototype.handleAnyTextareaChanges); | |
56 | }); | |
57 | it('should define CompositionHelper.prototype.updateCompositionViewPosition', function () { | |
58 | assert.isDefined(Terminal.CompositionHelper.prototype.updateCompositionViewPosition); | |
59 | }); | |
60 | it('should define CompositionHelper.isComposing', function () { | |
61 | assert.isDefined(compositionHelper.isComposing); | |
62 | }); | |
63 | it('should define CompositionHelper.isSendingComposition', function () { | |
64 | assert.isDefined(compositionHelper.isSendingComposition); | |
65 | }); | |
66 | }); | |
67 | ||
68 | describe('Input', function () { | |
69 | it('Should insert simple characters', function (done) { | |
70 | // First character | |
71 | compositionHelper.compositionstart(); | |
72 | compositionHelper.compositionupdate({ data: 'ㅇ' }); | |
73 | textarea.value = 'ㅇ'; | |
74 | setTimeout(function() { // wait for any textarea updates | |
75 | compositionHelper.compositionend(); | |
76 | setTimeout(function() { // wait for any textarea updates | |
77 | assert.equal(handledText, 'ㅇ'); | |
78 | // Second character | |
79 | compositionHelper.compositionstart(); | |
80 | compositionHelper.compositionupdate({ data: 'ㅇ' }); | |
81 | textarea.value = 'ㅇㅇ'; | |
82 | setTimeout(function() { // wait for any textarea updates | |
83 | compositionHelper.compositionend(); | |
84 | setTimeout(function() { // wait for any textarea updates | |
85 | assert.equal(handledText, 'ㅇㅇ'); | |
86 | done(); | |
87 | }, 0); | |
88 | }, 0); | |
89 | }, 0); | |
90 | }, 0); | |
91 | }); | |
92 | ||
93 | it('Should insert complex characters', function (done) { | |
94 | // First character | |
95 | compositionHelper.compositionstart(); | |
96 | compositionHelper.compositionupdate({ data: 'ㅇ' }); | |
97 | textarea.value = 'ㅇ'; | |
98 | setTimeout(function() { // wait for any textarea updates | |
99 | compositionHelper.compositionupdate({ data: '아' }); | |
100 | textarea.value = '아'; | |
101 | setTimeout(function() { // wait for any textarea updates | |
102 | compositionHelper.compositionupdate({ data: '앙' }); | |
103 | textarea.value = '앙'; | |
104 | setTimeout(function() { // wait for any textarea updates | |
105 | compositionHelper.compositionend(); | |
106 | setTimeout(function() { // wait for any textarea updates | |
107 | assert.equal(handledText, '앙'); | |
108 | // Second character | |
109 | compositionHelper.compositionstart(); | |
110 | compositionHelper.compositionupdate({ data: 'ㅇ' }); | |
111 | textarea.value = '앙ㅇ'; | |
112 | setTimeout(function() { // wait for any textarea updates | |
113 | compositionHelper.compositionupdate({ data: '아' }); | |
114 | textarea.value = '앙아'; | |
115 | setTimeout(function() { // wait for any textarea updates | |
116 | compositionHelper.compositionupdate({ data: '앙' }); | |
117 | textarea.value = '앙앙'; | |
118 | setTimeout(function() { // wait for any textarea updates | |
119 | compositionHelper.compositionend(); | |
120 | setTimeout(function() { // wait for any textarea updates | |
121 | assert.equal(handledText, '앙앙'); | |
122 | done(); | |
123 | }, 0); | |
124 | }, 0); | |
125 | }, 0); | |
126 | }, 0); | |
127 | }, 0); | |
128 | }, 0); | |
129 | }, 0); | |
130 | }, 0); | |
131 | }); | |
132 | ||
133 | it('Should insert complex characters that change with following character', function (done) { | |
134 | // First character | |
135 | compositionHelper.compositionstart(); | |
136 | compositionHelper.compositionupdate({ data: 'ㅇ' }); | |
137 | textarea.value = 'ㅇ'; | |
138 | setTimeout(function() { // wait for any textarea updates | |
139 | compositionHelper.compositionupdate({ data: '아' }); | |
140 | textarea.value = '아'; | |
141 | setTimeout(function() { // wait for any textarea updates | |
142 | // Start second character in first character | |
143 | compositionHelper.compositionupdate({ data: '앙' }); | |
144 | textarea.value = '앙'; | |
145 | setTimeout(function() { // wait for any textarea updates | |
146 | compositionHelper.compositionend(); | |
147 | compositionHelper.compositionstart(); | |
148 | compositionHelper.compositionupdate({ data: '아' }); | |
149 | textarea.value = '아아' | |
150 | setTimeout(function() { // wait for any textarea updates | |
151 | compositionHelper.compositionend(); | |
152 | setTimeout(function() { // wait for any textarea updates | |
153 | assert.equal(handledText, '아아'); | |
154 | done(); | |
155 | }, 0); | |
156 | }, 0); | |
157 | }, 0); | |
158 | }, 0); | |
159 | }, 0); | |
160 | }); | |
161 | ||
162 | it('Should insert multi-line charcters', function () { | |
163 | // TODO: Implement a hiragana example | |
164 | }); | |
165 | ||
166 | it('Should insert multi-line charcters that are converted to other characters', function () { | |
167 | // TODO: Implement a hiragana -> kanji example | |
168 | }); | |
169 | }); | |
170 | }); |