resize.spec.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { haveText, test, html, notHaveText } from '../../utils'
  2. test('can react to the resizing of an element',
  3. [html`
  4. <div x-data="{ width: 0, height: 0 }">
  5. <h1 x-text="width"></h1>
  6. <h2 x-text="height"></h2>
  7. <div x-ref="target" x-resize="width = $width; height = $height" style="width: 100px; height: 100px; background: red">
  8. </div>
  9. <button id="1" x-on:click="$refs.target.style.width = 50 + 'px'">resize width</button>
  10. <button id="2" x-on:click="$refs.target.style.height = 50 + 'px'">resize height</button>
  11. </div>
  12. `],
  13. ({ get }) => {
  14. get('h1').should(haveText('100'))
  15. get('h2').should(haveText('100'))
  16. get('button#1').click()
  17. get('h1').should(haveText('50'))
  18. get('h2').should(haveText('100'))
  19. get('button#2').click()
  20. get('h1').should(haveText('50'))
  21. get('h2').should(haveText('50'))
  22. },
  23. )
  24. test('can react to the resizing of the document',
  25. [html`
  26. <div x-data="{ width: 0, height: 0 }">
  27. <h1 x-text="width"></h1>
  28. <h2 x-text="height"></h2>
  29. <div x-ref="target" x-resize.document="width = $width; height = $height" style="width: 100px; height: 100px; background: red">
  30. </div>
  31. `],
  32. ({ get }) => {
  33. get('h1').should(notHaveText('0'))
  34. get('h2').should(notHaveText('0'))
  35. get('h1').should(notHaveText('100'))
  36. get('h2').should(notHaveText('100'))
  37. cy.viewport(550, 750)
  38. get('h1').should(haveText('550'))
  39. get('h2').should(haveText('750'))
  40. },
  41. )