|
2 | 2 |
|
3 | 3 | import bigList from "./utils/bigList.json"; |
4 | 4 |
|
5 | | -import { |
6 | | - clearDom, |
7 | | - createDomElement, |
8 | | - fillIn, |
9 | | - simulateMouseClick |
10 | | -} from "./utils/dom-helpers"; |
| 5 | +import {clearDom, createDomElement, fillIn, simulateMouseClick, simulateElementScroll} from './utils/dom-helpers'; |
11 | 6 |
|
12 | 7 | import { attachTribute, detachTribute } from "./utils/tribute-helpers"; |
13 | 8 |
|
@@ -892,3 +887,88 @@ describe("Tribute disabled items cases", function() { |
892 | 887 | }); |
893 | 888 |
|
894 | 889 | }); |
| 890 | + |
| 891 | + |
| 892 | +describe('closeOnScroll tests', function() { |
| 893 | + afterEach(function () { |
| 894 | + clearDom(); |
| 895 | + }); |
| 896 | + |
| 897 | + it('Tribute should close when the window is scrolled', () => { |
| 898 | + let input = createDomElement(); |
| 899 | + |
| 900 | + let collectionObject = { |
| 901 | + trigger: '@', |
| 902 | + closeOnScroll: true, |
| 903 | + values: [ |
| 904 | + { key: 'Jordan Humphreys', value: 'Jordan Humphreys', email: 'getstarted@zurb.com' }, |
| 905 | + { key: 'Sir Walter Riley', value: 'Sir Walter Riley', email: 'getstarted+riley@zurb.com' } |
| 906 | + ], |
| 907 | + }; |
| 908 | + |
| 909 | + let tribute = attachTribute(collectionObject, input.id); |
| 910 | + fillIn(input, '@'); |
| 911 | + |
| 912 | + expect(tribute.isActive).toBe(true); |
| 913 | + simulateElementScroll(window); |
| 914 | + |
| 915 | + // Need a slight delay otherwise we'll check for the result to fast |
| 916 | + setTimeout(() => { |
| 917 | + expect(tribute.isActive).toBe(false); |
| 918 | + }, 50) |
| 919 | + |
| 920 | + detachTribute(tribute, input.id); |
| 921 | + }); |
| 922 | + |
| 923 | + it('Tribute should close when the container is scrolled', () => { |
| 924 | + let input = createDomElement(); |
| 925 | + let container = document.createElement('div'); |
| 926 | + |
| 927 | + let collectionObject = { |
| 928 | + trigger: '@', |
| 929 | + closeOnScroll: container, |
| 930 | + values: [ |
| 931 | + { key: 'Jordan Humphreys', value: 'Jordan Humphreys', email: 'getstarted@zurb.com' }, |
| 932 | + { key: 'Sir Walter Riley', value: 'Sir Walter Riley', email: 'getstarted+riley@zurb.com' } |
| 933 | + ], |
| 934 | + }; |
| 935 | + |
| 936 | + let tribute = attachTribute(collectionObject, input.id); |
| 937 | + fillIn(input, '@'); |
| 938 | + |
| 939 | + expect(tribute.isActive).toBe(true); |
| 940 | + simulateElementScroll(container); |
| 941 | + |
| 942 | + // Need a slight delay otherwise we'll check for the result to fast |
| 943 | + setTimeout(() => { |
| 944 | + expect(tribute.isActive).toBe(false); |
| 945 | + }, 50) |
| 946 | + |
| 947 | + detachTribute(tribute, input.id); |
| 948 | + }); |
| 949 | + |
| 950 | + it('Tribute should not close when scrolled without the closeOnScroll set', () => { |
| 951 | + let input = createDomElement(); |
| 952 | + |
| 953 | + let collectionObject = { |
| 954 | + trigger: '@', |
| 955 | + values: [ |
| 956 | + { key: 'Jordan Humphreys', value: 'Jordan Humphreys', email: 'getstarted@zurb.com' }, |
| 957 | + { key: 'Sir Walter Riley', value: 'Sir Walter Riley', email: 'getstarted+riley@zurb.com' } |
| 958 | + ], |
| 959 | + }; |
| 960 | + |
| 961 | + let tribute = attachTribute(collectionObject, input.id); |
| 962 | + fillIn(input, '@'); |
| 963 | + |
| 964 | + expect(tribute.isActive).toBe(true); |
| 965 | + simulateElementScroll(window); |
| 966 | + |
| 967 | + // Need a slight delay otherwise we'll check for the result to fast |
| 968 | + setTimeout(() => { |
| 969 | + expect(tribute.isActive).toBe(true); |
| 970 | + }, 50) |
| 971 | + |
| 972 | + detachTribute(tribute, input.id); |
| 973 | + }); |
| 974 | +}); |
0 commit comments