|
1 |
| -import { beChecked, notBeChecked, haveAttribute, haveData, haveText, test, beVisible, notBeVisible, html } from '../../utils' |
| 1 | +import { beChecked, contain, notBeChecked, haveAttribute, haveData, haveText, test, beVisible, notBeVisible, html } from '../../utils' |
2 | 2 |
|
3 | 3 | test('data modified in event listener updates affected attribute bindings',
|
4 | 4 | html`
|
@@ -671,3 +671,159 @@ test('handles await in handlers with invalid right hand expressions',
|
671 | 671 | get('span').should(haveText('new string'))
|
672 | 672 | }
|
673 | 673 | )
|
| 674 | + |
| 675 | +test( |
| 676 | + "handles system modifier keys on key events", |
| 677 | + html` |
| 678 | + <div x-data="{ keys: { |
| 679 | + shift: false, |
| 680 | + ctrl: false, |
| 681 | + meta: false, |
| 682 | + alt: false, |
| 683 | + cmd: false |
| 684 | + } }"> |
| 685 | + <input type="text" |
| 686 | + @keydown.capture="Object.keys(keys).forEach(key => keys[key] = false)" |
| 687 | + @keydown.meta.space="keys.meta = true" |
| 688 | + @keydown.ctrl.space="keys.ctrl = true" |
| 689 | + @keydown.shift.space="keys.shift = true" |
| 690 | + @keydown.alt.space="keys.alt = true" |
| 691 | + @keydown.cmd.space="keys.cmd = true" |
| 692 | + /> |
| 693 | + <template x-for="key in Object.keys(keys)" :key="key"> |
| 694 | + <input type="checkbox" :name="key" x-model="keys[key]"> |
| 695 | + </template> |
| 696 | + </div> |
| 697 | + `,({ get }) => { |
| 698 | + get("input[name=shift]").as('shift').should(notBeChecked()); |
| 699 | + get("input[name=ctrl]").as('ctrl').should(notBeChecked()); |
| 700 | + get("input[name=meta]").as('meta').should(notBeChecked()); |
| 701 | + get("input[name=alt]").as('alt').should(notBeChecked()); |
| 702 | + get("input[name=cmd]").as('cmd').should(notBeChecked()); |
| 703 | + get("input[type=text]").as('input').trigger("keydown", { key: 'space', shiftKey: true }); |
| 704 | + get('@shift').should(beChecked()); |
| 705 | + get("@input").trigger("keydown", { key: 'space', ctrlKey: true }); |
| 706 | + get("@shift").should(notBeChecked()); |
| 707 | + get("@ctrl").should(beChecked()); |
| 708 | + get("@input").trigger("keydown", { key: 'space', metaKey: true }); |
| 709 | + get("@ctrl").should(notBeChecked()); |
| 710 | + get("@meta").should(beChecked()); |
| 711 | + get("@cmd").should(beChecked()); |
| 712 | + get("@input").trigger("keydown", { key: 'space', altKey: true }); |
| 713 | + get("@meta").should(notBeChecked()); |
| 714 | + get("@cmd").should(notBeChecked()); |
| 715 | + get("@alt").should(beChecked()); |
| 716 | + get("@input").trigger("keydown", { key: 'space' }); |
| 717 | + get("@alt").should(notBeChecked()); |
| 718 | + get("@input").trigger("keydown", { key: 'space', |
| 719 | + ctrlKey: true, shiftKey: true, metaKey: true, altKey: true }); |
| 720 | + get("input[name=shift]").as("shift").should(beChecked()); |
| 721 | + get("input[name=ctrl]").as("ctrl").should(beChecked()); |
| 722 | + get("input[name=meta]").as("meta").should(beChecked()); |
| 723 | + get("input[name=alt]").as("alt").should(beChecked()); |
| 724 | + get("input[name=cmd]").as("cmd").should(beChecked()); |
| 725 | + } |
| 726 | +); |
| 727 | + |
| 728 | +test( |
| 729 | + "handles system modifier keys on mouse events", |
| 730 | + html` |
| 731 | + <div x-data="{ keys: { |
| 732 | + shift: false, |
| 733 | + ctrl: false, |
| 734 | + meta: false, |
| 735 | + alt: false, |
| 736 | + cmd: false |
| 737 | + } }"> |
| 738 | + <button type=button |
| 739 | + @click.capture="Object.keys(keys).forEach(key => keys[key] = false)" |
| 740 | + @click.shift="keys.shift = true" |
| 741 | + @click.ctrl="keys.ctrl = true" |
| 742 | + @click.meta="keys.meta = true" |
| 743 | + @click.alt="keys.alt = true" |
| 744 | + @click.cmd="keys.cmd = true"> |
| 745 | + change |
| 746 | + </button> |
| 747 | + <template x-for="key in Object.keys(keys)" :key="key"> |
| 748 | + <input type="checkbox" :name="key" x-model="keys[key]"> |
| 749 | + </template> |
| 750 | + </div> |
| 751 | + `,({ get }) => { |
| 752 | + get("input[name=shift]").as('shift').should(notBeChecked()); |
| 753 | + get("input[name=ctrl]").as('ctrl').should(notBeChecked()); |
| 754 | + get("input[name=meta]").as('meta').should(notBeChecked()); |
| 755 | + get("input[name=alt]").as('alt').should(notBeChecked()); |
| 756 | + get("input[name=cmd]").as('cmd').should(notBeChecked()); |
| 757 | + get("button").as('button').trigger("click", { shiftKey: true }); |
| 758 | + get('@shift').should(beChecked()); |
| 759 | + get("@button").trigger("click", { ctrlKey: true }); |
| 760 | + get("@shift").should(notBeChecked()); |
| 761 | + get("@ctrl").should(beChecked()); |
| 762 | + get("@button").trigger("click", { metaKey: true }); |
| 763 | + get("@ctrl").should(notBeChecked()); |
| 764 | + get("@meta").should(beChecked()); |
| 765 | + get("@cmd").should(beChecked()); |
| 766 | + get("@button").trigger("click", { altKey: true }); |
| 767 | + get("@meta").should(notBeChecked()); |
| 768 | + get("@cmd").should(notBeChecked()); |
| 769 | + get("@alt").should(beChecked()); |
| 770 | + get("@button").trigger("click", {}); |
| 771 | + get("@alt").should(notBeChecked()); |
| 772 | + get("@button").trigger("click", { ctrlKey: true, shiftKey: true, metaKey: true, altKey: true }); |
| 773 | + get("@shift").as("shift").should(beChecked()); |
| 774 | + get("@ctrl").as("ctrl").should(beChecked()); |
| 775 | + get("@meta").as("meta").should(beChecked()); |
| 776 | + get("@alt").as("alt").should(beChecked()); |
| 777 | + get("@cmd").as("cmd").should(beChecked()); |
| 778 | + } |
| 779 | +); |
| 780 | + |
| 781 | +test( |
| 782 | + "handles all mouse events with modifiers", |
| 783 | + html` |
| 784 | + <div x-data="{ keys: { |
| 785 | + shift: false, |
| 786 | + ctrl: false, |
| 787 | + meta: false, |
| 788 | + alt: false, |
| 789 | + cmd: false |
| 790 | + } }"> |
| 791 | + <button type=button |
| 792 | + @click.capture="Object.keys(keys).forEach(key => keys[key] = false)" |
| 793 | + @contextmenu.prevent.shift="keys.shift = true" |
| 794 | + @auxclick.ctrl="keys.ctrl = true" |
| 795 | + @dblclick.meta="keys.meta = true" |
| 796 | + @mouseenter.alt="keys.alt = true" |
| 797 | + @mousemove.cmd="keys.cmd = true"> |
| 798 | + change |
| 799 | + </button> |
| 800 | + <template x-for="key in Object.keys(keys)" :key="key"> |
| 801 | + <input type="checkbox" :name="key" x-model="keys[key]"> |
| 802 | + </template> |
| 803 | + </div> |
| 804 | + `,({ get }) => { |
| 805 | + get("input[name=shift]").as('shift').should(notBeChecked()); |
| 806 | + get("input[name=ctrl]").as('ctrl').should(notBeChecked()); |
| 807 | + get("input[name=meta]").as('meta').should(notBeChecked()); |
| 808 | + get("input[name=alt]").as('alt').should(notBeChecked()); |
| 809 | + get("input[name=cmd]").as('cmd').should(notBeChecked()); |
| 810 | + get("button").as('button').trigger("contextmenu", { shiftKey: true }); |
| 811 | + get('@shift').should(beChecked()); |
| 812 | + get("@button").trigger("click"); |
| 813 | + get("@button").trigger("auxclick", { ctrlKey: true }); |
| 814 | + get("@shift").should(notBeChecked()); |
| 815 | + get("@ctrl").should(beChecked()); |
| 816 | + get("@button").trigger("click"); |
| 817 | + get("@button").trigger("dblclick", { metaKey: true }); |
| 818 | + get("@ctrl").should(notBeChecked()); |
| 819 | + get("@meta").should(beChecked()); |
| 820 | + get("@button").trigger("click"); |
| 821 | + get("@button").trigger("mouseenter", { altKey: true }); |
| 822 | + get("@meta").should(notBeChecked()); |
| 823 | + get("@alt").should(beChecked()); |
| 824 | + get("@button").trigger("click"); |
| 825 | + get("@button").trigger("mousemove", { metaKey: true }); |
| 826 | + get("@alt").should(notBeChecked()); |
| 827 | + get("@cmd").should(beChecked()); |
| 828 | + } |
| 829 | +); |
0 commit comments