|
1 | 1 | (function() {
|
2 | 2 |
|
3 | 3 | var click = function(el, cb) {
|
4 |
| - syn.click(el).delay(350, cb); |
| 4 | + syn.click(el).delay(1, cb); |
| 5 | + }; |
| 6 | + |
| 7 | + var tabTo = function(elem) { |
| 8 | + // emulating keyboard tabbing using focus |
| 9 | + // TODO: it would be better to use something like puppeteer instead, then we could simulate real keyboard interactions |
| 10 | + // syn.key() is not reliable enough for tabbing |
| 11 | + elem.focus(); |
| 12 | + return new Promise((resolve) => window.setTimeout(resolve)); |
5 | 13 | };
|
6 | 14 |
|
7 | 15 | // These tests are functional simulations of
|
|
41 | 49 | });
|
42 | 50 | });
|
43 | 51 | });
|
44 |
| - |
| 52 | + |
45 | 53 | it('should reopen dropdown if clicked after being closed by closeAfterSelect: true', function(done) {
|
46 | 54 | var test = setup_test('<select multiple>' +
|
47 | 55 | '<option value="a">A</option>' +
|
|
413 | 421 | });
|
414 | 422 | });
|
415 | 423 |
|
| 424 | + describe('simulate tabbing using native focus()', function() { |
| 425 | + |
| 426 | + describe('defaults', function() { |
| 427 | + var test, input1, input2; |
| 428 | + |
| 429 | + before(function(done) { |
| 430 | + test = setup_test('<select>' + |
| 431 | + '<option value="">No selection</option>' + |
| 432 | + '<option value="a">A</option>' + |
| 433 | + '<option value="b">B</option>' + |
| 434 | + '</select>', {}); |
| 435 | + input1 = $('<input type="text" class="first">'); |
| 436 | + input2 = $('<input type="text" class="last">'); |
| 437 | + test.$select.parent().prepend(input1); |
| 438 | + test.$select.parent().append(input2); |
| 439 | + done(); |
| 440 | + }); |
| 441 | + |
| 442 | + after(function() { |
| 443 | + input1.remove(); |
| 444 | + input2.remove(); |
| 445 | + }); |
| 446 | + |
| 447 | + it('should give the control focus', async function() { |
| 448 | + await tabTo(input1[0]); |
| 449 | + expect(test.selectize.isFocused).to.be.equal(false); |
| 450 | + await tabTo(test.selectize.$control_input[0]); |
| 451 | + expect(test.selectize.isFocused).to.be.equal(true); |
| 452 | + }); |
| 453 | + |
| 454 | + it('should remove the control focus', async function() { |
| 455 | + await tabTo(test.selectize.$control_input[0]); |
| 456 | + expect(test.selectize.isFocused).to.be.equal(true); |
| 457 | + await tabTo(input2[0]); |
| 458 | + expect(test.selectize.isFocused).to.be.equal(false); |
| 459 | + }); |
| 460 | + |
| 461 | + it('should open the control', async function() { |
| 462 | + await tabTo(input1[0]); |
| 463 | + expect(test.selectize.isOpen).to.be.equal(false); |
| 464 | + await tabTo(test.selectize.$control_input[0]); |
| 465 | + expect(test.selectize.isOpen).to.be.equal(true); |
| 466 | + }); |
| 467 | + |
| 468 | + it('should close the control', async function() { |
| 469 | + await tabTo(test.selectize.$control_input[0]); |
| 470 | + expect(test.selectize.isOpen).to.be.equal(true); |
| 471 | + await tabTo(input2[0]); |
| 472 | + expect(test.selectize.isOpen).to.be.equal(false); |
| 473 | + }); |
| 474 | + |
| 475 | + // TODO: this would work if tabTo was using actual keyboard interactions, |
| 476 | + // and not just focus() |
| 477 | + xit('should select the first value on blur', async function() { |
| 478 | + await tabTo(test.selectize.$control_input[0]); |
| 479 | + await tabTo(input2[0]); |
| 480 | + expect(test.selectize.getValue()).to.be.equal('a'); |
| 481 | + }); |
| 482 | + }); |
| 483 | + |
| 484 | + describe('openOnFocus is false', function() { |
| 485 | + var test, input1, input2; |
| 486 | + |
| 487 | + before(function(done) { |
| 488 | + test = setup_test('<select>' + |
| 489 | + '<option value="">No selection</option>' + |
| 490 | + '<option value="a">A</option>' + |
| 491 | + '<option value="b">B</option>' + |
| 492 | + '</select>', { openOnFocus: false }); |
| 493 | + input1 = $('<input type="text" class="first">'); |
| 494 | + input2 = $('<input type="text" class="last">'); |
| 495 | + test.$select.parent().prepend(input1); |
| 496 | + test.$select.parent().append(input2); |
| 497 | + done(); |
| 498 | + }); |
| 499 | + |
| 500 | + after(function() { |
| 501 | + input1.remove(); |
| 502 | + input2.remove(); |
| 503 | + }); |
| 504 | + |
| 505 | + it('should give the control focus', async function() { |
| 506 | + await tabTo(input1[0]); |
| 507 | + expect(test.selectize.isFocused).to.be.equal(false); |
| 508 | + await tabTo(test.selectize.$control_input[0]); |
| 509 | + expect(test.selectize.isFocused).to.be.equal(true); |
| 510 | + }); |
| 511 | + |
| 512 | + it('should not open the control', async function() { |
| 513 | + await tabTo(input1[0]); |
| 514 | + expect(test.selectize.isOpen).to.be.equal(false); |
| 515 | + await tabTo(test.selectize.$control_input[0]); |
| 516 | + expect(test.selectize.isOpen).to.be.equal(false); |
| 517 | + }); |
| 518 | + }); |
| 519 | + }); |
| 520 | + |
416 | 521 | });
|
417 | 522 |
|
418 | 523 | })();
|
0 commit comments