| 15403 |
manish.sha |
1 |
/* jshint esnext: true, evil: true, sub: true */
|
|
|
2 |
|
|
|
3 |
var wd = require('yiewd'),
|
|
|
4 |
colors = require('colors'),
|
|
|
5 |
expect = require('chai').expect,
|
|
|
6 |
_ = require('underscore'),
|
|
|
7 |
f = require('util').format,
|
|
|
8 |
env = process.env;
|
|
|
9 |
|
|
|
10 |
var browser, caps;
|
|
|
11 |
|
|
|
12 |
browser = (process.env.BROWSER || 'chrome').split(':');
|
|
|
13 |
|
|
|
14 |
caps = {
|
|
|
15 |
name: f('[%s] typeahead.js ui', browser.join(' , ')),
|
|
|
16 |
browserName: browser[0]
|
|
|
17 |
};
|
|
|
18 |
|
|
|
19 |
setIf(caps, 'version', browser[1]);
|
|
|
20 |
setIf(caps, 'platform', browser[2]);
|
|
|
21 |
setIf(caps, 'tunnel-identifier', env['TRAVIS_JOB_NUMBER']);
|
|
|
22 |
setIf(caps, 'build', env['TRAVIS_BUILD_NUMBER']);
|
|
|
23 |
setIf(caps, 'tags', env['CI'] ? ['CI'] : ['local']);
|
|
|
24 |
|
|
|
25 |
function setIf(obj, key, val) {
|
|
|
26 |
val && (obj[key] = val);
|
|
|
27 |
}
|
|
|
28 |
|
|
|
29 |
describe('jquery-typeahead.js', function() {
|
|
|
30 |
var driver, body, input, hint, dropdown, allPassed = true;
|
|
|
31 |
|
|
|
32 |
this.timeout(300000);
|
|
|
33 |
|
|
|
34 |
before(function(done) {
|
|
|
35 |
var host = 'ondemand.saucelabs.com', port = 80, username, password;
|
|
|
36 |
|
|
|
37 |
if (env['CI']) {
|
|
|
38 |
host = 'localhost';
|
|
|
39 |
port = 4445;
|
|
|
40 |
username = env['SAUCE_USERNAME'];
|
|
|
41 |
password = env['SAUCE_ACCESS_KEY'];
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
driver = wd.remote(host, port, username, password);
|
|
|
45 |
driver.configureHttp({
|
|
|
46 |
timeout: 30000,
|
|
|
47 |
retries: 5,
|
|
|
48 |
retryDelay: 200
|
|
|
49 |
});
|
|
|
50 |
|
|
|
51 |
driver.on('status', function(info) {
|
|
|
52 |
console.log(info.cyan);
|
|
|
53 |
});
|
|
|
54 |
|
|
|
55 |
driver.on('command', function(meth, path, data) {
|
|
|
56 |
console.log(' > ' + meth.yellow, path.grey, data || '');
|
|
|
57 |
});
|
|
|
58 |
|
|
|
59 |
driver.run(function*() {
|
|
|
60 |
yield this.init(caps);
|
|
|
61 |
yield this.get('http://localhost:8888/test/integration/test.html');
|
|
|
62 |
|
|
|
63 |
body = this.elementByTagName('body');
|
|
|
64 |
input = yield this.elementById('states');
|
|
|
65 |
hint = yield this.elementByClassName('tt-hint');
|
|
|
66 |
dropdown = yield this.elementByClassName('tt-dropdown-menu');
|
|
|
67 |
|
|
|
68 |
done();
|
|
|
69 |
});
|
|
|
70 |
});
|
|
|
71 |
|
|
|
72 |
beforeEach(function(done) {
|
|
|
73 |
driver.run(function*() {
|
|
|
74 |
yield body.click();
|
|
|
75 |
yield this.execute('window.jQuery("#states").typeahead("val", "")');
|
|
|
76 |
done();
|
|
|
77 |
});
|
|
|
78 |
});
|
|
|
79 |
|
|
|
80 |
afterEach(function() {
|
|
|
81 |
allPassed = allPassed && (this.currentTest.state === 'passed');
|
|
|
82 |
});
|
|
|
83 |
|
|
|
84 |
after(function(done) {
|
|
|
85 |
driver.run(function*() {
|
|
|
86 |
yield this.quit();
|
|
|
87 |
yield driver.sauceJobStatus(allPassed);
|
|
|
88 |
done();
|
|
|
89 |
});
|
|
|
90 |
});
|
|
|
91 |
|
|
|
92 |
describe('on blur', function() {
|
|
|
93 |
it('should close dropdown', function(done) {
|
|
|
94 |
driver.run(function*() {
|
|
|
95 |
yield input.click();
|
|
|
96 |
yield input.type('mi');
|
|
|
97 |
expect(yield dropdown.isDisplayed()).to.equal(true);
|
|
|
98 |
|
|
|
99 |
yield body.click();
|
|
|
100 |
expect(yield dropdown.isDisplayed()).to.equal(false);
|
|
|
101 |
|
|
|
102 |
done();
|
|
|
103 |
});
|
|
|
104 |
});
|
|
|
105 |
|
|
|
106 |
it('should clear hint', function(done) {
|
|
|
107 |
driver.run(function*() {
|
|
|
108 |
yield input.click();
|
|
|
109 |
yield input.type('mi');
|
|
|
110 |
expect(yield hint.getValue()).to.equal('michigan');
|
|
|
111 |
|
|
|
112 |
yield body.click();
|
|
|
113 |
expect(yield hint.getValue()).to.equal('');
|
|
|
114 |
|
|
|
115 |
done();
|
|
|
116 |
});
|
|
|
117 |
});
|
|
|
118 |
});
|
|
|
119 |
|
|
|
120 |
describe('on query change', function() {
|
|
|
121 |
it('should open dropdown if suggestions', function(done) {
|
|
|
122 |
driver.run(function*() {
|
|
|
123 |
yield input.click();
|
|
|
124 |
yield input.type('mi');
|
|
|
125 |
|
|
|
126 |
expect(yield dropdown.isDisplayed()).to.equal(true);
|
|
|
127 |
|
|
|
128 |
done();
|
|
|
129 |
});
|
|
|
130 |
});
|
|
|
131 |
|
|
|
132 |
it('should close dropdown if no suggestions', function(done) {
|
|
|
133 |
driver.run(function*() {
|
|
|
134 |
yield input.click();
|
|
|
135 |
yield input.type('huh?');
|
|
|
136 |
|
|
|
137 |
expect(yield dropdown.isDisplayed()).to.equal(false);
|
|
|
138 |
|
|
|
139 |
done();
|
|
|
140 |
});
|
|
|
141 |
});
|
|
|
142 |
|
|
|
143 |
it('should render suggestions if suggestions', function(done) {
|
|
|
144 |
driver.run(function*() {
|
|
|
145 |
var suggestions;
|
|
|
146 |
|
|
|
147 |
yield input.click();
|
|
|
148 |
yield input.type('mi');
|
|
|
149 |
|
|
|
150 |
suggestions = yield dropdown.elementsByClassName('tt-suggestion');
|
|
|
151 |
|
|
|
152 |
expect(suggestions).to.have.length('4');
|
|
|
153 |
expect(yield suggestions[0].text()).to.equal('Michigan');
|
|
|
154 |
expect(yield suggestions[1].text()).to.equal('Minnesota');
|
|
|
155 |
expect(yield suggestions[2].text()).to.equal('Mississippi');
|
|
|
156 |
expect(yield suggestions[3].text()).to.equal('Missouri');
|
|
|
157 |
|
|
|
158 |
done();
|
|
|
159 |
});
|
|
|
160 |
});
|
|
|
161 |
|
|
|
162 |
it('should show hint if top suggestion is a match', function(done) {
|
|
|
163 |
driver.run(function*() {
|
|
|
164 |
yield input.click();
|
|
|
165 |
yield input.type('mi');
|
|
|
166 |
|
|
|
167 |
expect(yield hint.getValue()).to.equal('michigan');
|
|
|
168 |
|
|
|
169 |
done();
|
|
|
170 |
});
|
|
|
171 |
});
|
|
|
172 |
|
|
|
173 |
it('should match hint to query', function(done) {
|
|
|
174 |
driver.run(function*() {
|
|
|
175 |
yield input.click();
|
|
|
176 |
yield input.type('NeW JE');
|
|
|
177 |
|
|
|
178 |
expect(yield hint.getValue()).to.equal('NeW JErsey');
|
|
|
179 |
|
|
|
180 |
done();
|
|
|
181 |
});
|
|
|
182 |
});
|
|
|
183 |
|
|
|
184 |
it('should not show hint if top suggestion is not a match', function(done) {
|
|
|
185 |
driver.run(function*() {
|
|
|
186 |
yield input.click();
|
|
|
187 |
yield input.type('ham');
|
|
|
188 |
|
|
|
189 |
expect(yield hint.getValue()).to.equal('');
|
|
|
190 |
|
|
|
191 |
done();
|
|
|
192 |
});
|
|
|
193 |
});
|
|
|
194 |
|
|
|
195 |
it('should not show hint if there is query overflow', function(done) {
|
|
|
196 |
driver.run(function*() {
|
|
|
197 |
yield input.click();
|
|
|
198 |
yield input.type('this is a very long value so ');
|
|
|
199 |
|
|
|
200 |
expect(yield hint.getValue()).to.equal('');
|
|
|
201 |
|
|
|
202 |
done();
|
|
|
203 |
});
|
|
|
204 |
});
|
|
|
205 |
});
|
|
|
206 |
|
|
|
207 |
describe('on up arrow', function() {
|
|
|
208 |
it('should cycle through suggestions', function(done) {
|
|
|
209 |
driver.run(function*() {
|
|
|
210 |
var suggestions;
|
|
|
211 |
|
|
|
212 |
yield input.click();
|
|
|
213 |
yield input.type('mi');
|
|
|
214 |
|
|
|
215 |
suggestions = yield dropdown.elementsByClassName('tt-suggestion');
|
|
|
216 |
|
|
|
217 |
yield input.type(wd.SPECIAL_KEYS['Up arrow']);
|
|
|
218 |
expect(yield input.getValue()).to.equal('Missouri');
|
|
|
219 |
expect(yield suggestions[3].getAttribute('class')).to.equal('tt-suggestion tt-cursor');
|
|
|
220 |
|
|
|
221 |
yield input.type(wd.SPECIAL_KEYS['Up arrow']);
|
|
|
222 |
expect(yield input.getValue()).to.equal('Mississippi');
|
|
|
223 |
expect(yield suggestions[2].getAttribute('class')).to.equal('tt-suggestion tt-cursor');
|
|
|
224 |
|
|
|
225 |
yield input.type(wd.SPECIAL_KEYS['Up arrow']);
|
|
|
226 |
expect(yield input.getValue()).to.equal('Minnesota');
|
|
|
227 |
expect(yield suggestions[1].getAttribute('class')).to.equal('tt-suggestion tt-cursor');
|
|
|
228 |
|
|
|
229 |
yield input.type(wd.SPECIAL_KEYS['Up arrow']);
|
|
|
230 |
expect(yield input.getValue()).to.equal('Michigan');
|
|
|
231 |
expect(yield suggestions[0].getAttribute('class')).to.equal('tt-suggestion tt-cursor');
|
|
|
232 |
|
|
|
233 |
yield input.type(wd.SPECIAL_KEYS['Up arrow']);
|
|
|
234 |
expect(yield input.getValue()).to.equal('mi');
|
|
|
235 |
expect(yield suggestions[0].getAttribute('class')).to.equal('tt-suggestion');
|
|
|
236 |
expect(yield suggestions[1].getAttribute('class')).to.equal('tt-suggestion');
|
|
|
237 |
expect(yield suggestions[2].getAttribute('class')).to.equal('tt-suggestion');
|
|
|
238 |
expect(yield suggestions[3].getAttribute('class')).to.equal('tt-suggestion');
|
|
|
239 |
|
|
|
240 |
done();
|
|
|
241 |
});
|
|
|
242 |
});
|
|
|
243 |
});
|
|
|
244 |
|
|
|
245 |
describe('on down arrow', function() {
|
|
|
246 |
it('should cycle through suggestions', function(done) {
|
|
|
247 |
driver.run(function*() {
|
|
|
248 |
var suggestions;
|
|
|
249 |
|
|
|
250 |
yield input.click();
|
|
|
251 |
yield input.type('mi');
|
|
|
252 |
|
|
|
253 |
suggestions = yield dropdown.elementsByClassName('tt-suggestion');
|
|
|
254 |
|
|
|
255 |
yield input.type(wd.SPECIAL_KEYS['Down arrow']);
|
|
|
256 |
expect(yield input.getValue()).to.equal('Michigan');
|
|
|
257 |
expect(yield suggestions[0].getAttribute('class')).to.equal('tt-suggestion tt-cursor');
|
|
|
258 |
|
|
|
259 |
yield input.type(wd.SPECIAL_KEYS['Down arrow']);
|
|
|
260 |
expect(yield input.getValue()).to.equal('Minnesota');
|
|
|
261 |
expect(yield suggestions[1].getAttribute('class')).to.equal('tt-suggestion tt-cursor');
|
|
|
262 |
|
|
|
263 |
yield input.type(wd.SPECIAL_KEYS['Down arrow']);
|
|
|
264 |
expect(yield input.getValue()).to.equal('Mississippi');
|
|
|
265 |
expect(yield suggestions[2].getAttribute('class')).to.equal('tt-suggestion tt-cursor');
|
|
|
266 |
|
|
|
267 |
yield input.type(wd.SPECIAL_KEYS['Down arrow']);
|
|
|
268 |
expect(yield input.getValue()).to.equal('Missouri');
|
|
|
269 |
expect(yield suggestions[3].getAttribute('class')).to.equal('tt-suggestion tt-cursor');
|
|
|
270 |
|
|
|
271 |
yield input.type(wd.SPECIAL_KEYS['Down arrow']);
|
|
|
272 |
expect(yield input.getValue()).to.equal('mi');
|
|
|
273 |
expect(yield suggestions[0].getAttribute('class')).to.equal('tt-suggestion');
|
|
|
274 |
expect(yield suggestions[1].getAttribute('class')).to.equal('tt-suggestion');
|
|
|
275 |
expect(yield suggestions[2].getAttribute('class')).to.equal('tt-suggestion');
|
|
|
276 |
expect(yield suggestions[3].getAttribute('class')).to.equal('tt-suggestion');
|
|
|
277 |
|
|
|
278 |
done();
|
|
|
279 |
});
|
|
|
280 |
});
|
|
|
281 |
});
|
|
|
282 |
|
|
|
283 |
describe('on escape', function() {
|
|
|
284 |
it('should close dropdown', function(done) {
|
|
|
285 |
driver.run(function*() {
|
|
|
286 |
yield input.click();
|
|
|
287 |
yield input.type('mi');
|
|
|
288 |
expect(yield dropdown.isDisplayed()).to.equal(true);
|
|
|
289 |
|
|
|
290 |
yield input.type(wd.SPECIAL_KEYS['Escape']);
|
|
|
291 |
expect(yield dropdown.isDisplayed()).to.equal(false);
|
|
|
292 |
|
|
|
293 |
done();
|
|
|
294 |
});
|
|
|
295 |
});
|
|
|
296 |
|
|
|
297 |
it('should clear hint', function(done) {
|
|
|
298 |
driver.run(function*() {
|
|
|
299 |
yield input.click();
|
|
|
300 |
yield input.type('mi');
|
|
|
301 |
expect(yield hint.getValue()).to.equal('michigan');
|
|
|
302 |
|
|
|
303 |
yield input.type(wd.SPECIAL_KEYS['Escape']);
|
|
|
304 |
expect(yield hint.getValue()).to.equal('');
|
|
|
305 |
|
|
|
306 |
done();
|
|
|
307 |
});
|
|
|
308 |
});
|
|
|
309 |
});
|
|
|
310 |
|
|
|
311 |
describe('on tab', function() {
|
|
|
312 |
it('should autocomplete if hint is present', function(done) {
|
|
|
313 |
driver.run(function*() {
|
|
|
314 |
yield input.click();
|
|
|
315 |
yield input.type('mi');
|
|
|
316 |
|
|
|
317 |
yield input.type(wd.SPECIAL_KEYS['Tab']);
|
|
|
318 |
expect(yield input.getValue()).to.equal('Michigan');
|
|
|
319 |
|
|
|
320 |
done();
|
|
|
321 |
});
|
|
|
322 |
});
|
|
|
323 |
|
|
|
324 |
it('should select if cursor is on suggestion', function(done) {
|
|
|
325 |
driver.run(function*() {
|
|
|
326 |
var suggestions;
|
|
|
327 |
|
|
|
328 |
yield input.click();
|
|
|
329 |
yield input.type('mi');
|
|
|
330 |
|
|
|
331 |
suggestions = yield dropdown.elementsByClassName('tt-suggestion');
|
|
|
332 |
yield input.type(wd.SPECIAL_KEYS['Down arrow']);
|
|
|
333 |
yield input.type(wd.SPECIAL_KEYS['Down arrow']);
|
|
|
334 |
yield input.type(wd.SPECIAL_KEYS['Tab']);
|
|
|
335 |
|
|
|
336 |
expect(yield dropdown.isDisplayed()).to.equal(false);
|
|
|
337 |
expect(yield input.getValue()).to.equal('Minnesota');
|
|
|
338 |
|
|
|
339 |
done();
|
|
|
340 |
});
|
|
|
341 |
});
|
|
|
342 |
});
|
|
|
343 |
|
|
|
344 |
describe('on right arrow', function() {
|
|
|
345 |
it('should autocomplete if hint is present', function(done) {
|
|
|
346 |
driver.run(function*() {
|
|
|
347 |
yield input.click();
|
|
|
348 |
yield input.type('mi');
|
|
|
349 |
|
|
|
350 |
yield input.type(wd.SPECIAL_KEYS['Right arrow']);
|
|
|
351 |
expect(yield input.getValue()).to.equal('Michigan');
|
|
|
352 |
|
|
|
353 |
done();
|
|
|
354 |
});
|
|
|
355 |
});
|
|
|
356 |
});
|
|
|
357 |
|
|
|
358 |
describe('on suggestion click', function() {
|
|
|
359 |
it('should select suggestion', function(done) {
|
|
|
360 |
driver.run(function*() {
|
|
|
361 |
var suggestions;
|
|
|
362 |
|
|
|
363 |
yield input.click();
|
|
|
364 |
yield input.type('mi');
|
|
|
365 |
|
|
|
366 |
suggestions = yield dropdown.elementsByClassName('tt-suggestion');
|
|
|
367 |
yield suggestions[1].click();
|
|
|
368 |
|
|
|
369 |
expect(yield dropdown.isDisplayed()).to.equal(false);
|
|
|
370 |
expect(yield input.getValue()).to.equal('Minnesota');
|
|
|
371 |
|
|
|
372 |
done();
|
|
|
373 |
});
|
|
|
374 |
});
|
|
|
375 |
});
|
|
|
376 |
|
|
|
377 |
describe('on enter', function() {
|
|
|
378 |
it('should select if cursor is on suggestion', function(done) {
|
|
|
379 |
driver.run(function*() {
|
|
|
380 |
var suggestions;
|
|
|
381 |
|
|
|
382 |
yield input.click();
|
|
|
383 |
yield input.type('mi');
|
|
|
384 |
|
|
|
385 |
suggestions = yield dropdown.elementsByClassName('tt-suggestion');
|
|
|
386 |
yield input.type(wd.SPECIAL_KEYS['Down arrow']);
|
|
|
387 |
yield input.type(wd.SPECIAL_KEYS['Down arrow']);
|
|
|
388 |
yield input.type(wd.SPECIAL_KEYS['Return']);
|
|
|
389 |
|
|
|
390 |
expect(yield dropdown.isDisplayed()).to.equal(false);
|
|
|
391 |
expect(yield input.getValue()).to.equal('Minnesota');
|
|
|
392 |
|
|
|
393 |
done();
|
|
|
394 |
});
|
|
|
395 |
});
|
|
|
396 |
});
|
|
|
397 |
});
|