|
| 1 | +/* eslint-disable max-statements */ |
1 | 2 | // Components |
2 | 3 | import VCombobox from '../VCombobox' |
3 | 4 |
|
@@ -578,4 +579,116 @@ describe('VCombobox.ts', () => { |
578 | 579 |
|
579 | 580 | expect(change).toHaveBeenLastCalledWith(['bar', 'foo']) |
580 | 581 | }) |
| 582 | + |
| 583 | + // example 1 in https://github.com/vuetifyjs/vuetify/issues/14194 |
| 584 | + it('should not point to a result that does not exist as in example 1', async () => { |
| 585 | + const { wrapper } = createMultipleCombobox({ |
| 586 | + items: ['a', 'aa', 'aaa', 'bar'], |
| 587 | + }) |
| 588 | + |
| 589 | + const input = wrapper.find('input') |
| 590 | + const element = input.element as HTMLInputElement |
| 591 | + |
| 592 | + const listIndexUpdate = jest.fn() |
| 593 | + wrapper.vm.$on('update:list-index', listIndexUpdate) |
| 594 | + |
| 595 | + input.trigger('focus') |
| 596 | + await wrapper.vm.$nextTick() |
| 597 | + element.value = 'a' |
| 598 | + input.trigger('input') |
| 599 | + await wrapper.vm.$nextTick() |
| 600 | + |
| 601 | + input.trigger('keydown.down') |
| 602 | + await wrapper.vm.$nextTick() |
| 603 | + |
| 604 | + input.trigger('keydown.down') |
| 605 | + await wrapper.vm.$nextTick() |
| 606 | + |
| 607 | + input.trigger('keydown.down') |
| 608 | + await wrapper.vm.$nextTick() |
| 609 | + |
| 610 | + input.trigger('keydown.down') |
| 611 | + await wrapper.vm.$nextTick() |
| 612 | + |
| 613 | + element.value = 'aa' |
| 614 | + input.trigger('input') |
| 615 | + await wrapper.vm.$nextTick() |
| 616 | + expect(listIndexUpdate.mock.calls.length === 6).toBe(true) |
| 617 | + expect(listIndexUpdate.mock.calls[0][0]).toBe(-1) |
| 618 | + expect(listIndexUpdate.mock.calls[1][0]).toBe(0) |
| 619 | + expect(listIndexUpdate.mock.calls[2][0]).toBe(1) |
| 620 | + expect(listIndexUpdate.mock.calls[3][0]).toBe(2) |
| 621 | + expect(listIndexUpdate.mock.calls[4][0]).toBe(3) |
| 622 | + expect(listIndexUpdate.mock.calls[5][0]).toBe(-1) |
| 623 | + }) |
| 624 | + |
| 625 | + // example 2 in https://github.com/vuetifyjs/vuetify/issues/14194 |
| 626 | + it('should not change selection on search input as in example 2', async () => { |
| 627 | + const { wrapper } = createMultipleCombobox({ |
| 628 | + items: ['a', 'aa', 'aaa', 'bar'], |
| 629 | + }) |
| 630 | + |
| 631 | + const input = wrapper.find('input') |
| 632 | + const element = input.element as HTMLInputElement |
| 633 | + |
| 634 | + const listIndexUpdate = jest.fn() |
| 635 | + wrapper.vm.$on('update:list-index', listIndexUpdate) |
| 636 | + |
| 637 | + input.trigger('focus') |
| 638 | + await wrapper.vm.$nextTick() |
| 639 | + element.value = 'a' |
| 640 | + input.trigger('input') |
| 641 | + await wrapper.vm.$nextTick() |
| 642 | + |
| 643 | + input.trigger('keydown.down') |
| 644 | + await wrapper.vm.$nextTick() |
| 645 | + |
| 646 | + input.trigger('keydown.down') |
| 647 | + await wrapper.vm.$nextTick() |
| 648 | + |
| 649 | + input.trigger('keydown.down') |
| 650 | + await wrapper.vm.$nextTick() |
| 651 | + |
| 652 | + element.value = 'aa' |
| 653 | + input.trigger('input') |
| 654 | + await wrapper.vm.$nextTick() |
| 655 | + |
| 656 | + expect(listIndexUpdate.mock.calls.length === 5).toBe(true) |
| 657 | + expect(listIndexUpdate.mock.calls[0][0]).toBe(-1) |
| 658 | + expect(listIndexUpdate.mock.calls[1][0]).toBe(0) |
| 659 | + expect(listIndexUpdate.mock.calls[2][0]).toBe(1) |
| 660 | + expect(listIndexUpdate.mock.calls[3][0]).toBe(2) |
| 661 | + expect(listIndexUpdate.mock.calls[4][0]).toBe(1) |
| 662 | + }) |
| 663 | + |
| 664 | + // example 3 in https://github.com/vuetifyjs/vuetify/issues/14194 |
| 665 | + it('should not point to a result that does not exist as in example 3', async () => { |
| 666 | + const { wrapper } = createMultipleCombobox({ |
| 667 | + items: ['a', 'aa', 'aaa', 'bar'], |
| 668 | + }) |
| 669 | + |
| 670 | + const input = wrapper.find('input') |
| 671 | + const element = input.element as HTMLInputElement |
| 672 | + |
| 673 | + const listIndexUpdate = jest.fn() |
| 674 | + wrapper.vm.$on('update:list-index', listIndexUpdate) |
| 675 | + |
| 676 | + input.trigger('focus') |
| 677 | + await wrapper.vm.$nextTick() |
| 678 | + element.value = 'a' |
| 679 | + input.trigger('input') |
| 680 | + await wrapper.vm.$nextTick() |
| 681 | + |
| 682 | + input.trigger('keydown.down') |
| 683 | + await wrapper.vm.$nextTick() |
| 684 | + |
| 685 | + element.value = 'aaaa' |
| 686 | + input.trigger('input') |
| 687 | + await wrapper.vm.$nextTick() |
| 688 | + |
| 689 | + expect(listIndexUpdate.mock.calls.length === 3).toBe(true) |
| 690 | + expect(listIndexUpdate.mock.calls[0][0]).toBe(-1) |
| 691 | + expect(listIndexUpdate.mock.calls[1][0]).toBe(0) |
| 692 | + expect(listIndexUpdate.mock.calls[2][0]).toBe(-1) |
| 693 | + }) |
581 | 694 | }) |
0 commit comments