12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- import { haveText, test, html } from '../../utils'
- test('can intersect',
- [html`
- <div x-data="{ count: 0 }">
- <span x-text="count"></span>
- <div x-intersect="count++" style="margin-top: 100vh;" id="1">hi</div>
- </div>
- `],
- ({ get }) => {
- get('span').should(haveText('0'))
- get('#1').scrollIntoView({duration: 100})
- get('span').should(haveText('1'))
- get('span').scrollIntoView({duration: 100})
- get('span').should(haveText('1'))
- get('#1').scrollIntoView({duration: 100})
- get('span').should(haveText('2'))
- },
- )
- test('It should evaluate with ":enter" only when the component is intersected',
- [html`
- <div x-data="{ count: 0 }">
- <span x-text="count"></span>
- <div x-intersect:enter="count++" style="margin-top: 100vh;" id="1">hi</div>
- </div>
- `],
- ({ get }) => {
- get('span').should(haveText('0'))
- get('#1').scrollIntoView({duration: 100})
- get('span').should(haveText('1'))
- get('span').scrollIntoView({duration: 100})
- get('span').should(haveText('1'))
- get('#1').scrollIntoView({duration: 100})
- get('span').should(haveText('2'))
- },
- )
- test('It should evaluate with ":leave" only when the component is not intersected',
- [html`
- <div x-data="{ count: 0 }">
- <span x-text="count"></span>
- <div x-intersect:leave="count++" style="margin-top: 100vh;" id="1">hi</div>
- </div>
- `],
- ({ get }) => {
- get('span').should(haveText('1'))
- get('#1').scrollIntoView({duration: 100})
- get('span').should(haveText('1'))
- get('span').scrollIntoView({duration: 100})
- get('span').should(haveText('2'))
- get('#1').scrollIntoView({duration: 100})
- get('span').should(haveText('2'))
- get('span').scrollIntoView({duration: 100})
- get('span').should(haveText('3'))
- },
- )
- test('.once',
- [html`
- <div x-data="{ count: 0 }" x-init="setTimeout(() => count++, 300)">
- <span x-text="count"></span>
- <div x-intersect.once="count++" style="margin-top: 100vh;" id="1">hi</div>
- </div>
- `],
- ({ get }) => {
- get('span').should(haveText('0'))
- get('#1').scrollIntoView({duration: 100})
- get('span').should(haveText('1'))
- get('span').scrollIntoView({duration: 100})
- get('span').should(haveText('1'))
- get('#1').scrollIntoView({duration: 100})
- get('span').should(haveText('2'))
- },
- )
|