collapse.spec.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { haveAttribute, haveComputedStyle, html, test } from '../../utils'
  2. test('can collapse and expand element',
  3. [html`
  4. <div x-data="{ expanded: false }">
  5. <button @click="expanded = ! expanded">toggle</button>
  6. <h1 x-show="expanded" x-collapse>contents</h1>
  7. </div>
  8. `],
  9. ({ get }, reload) => {
  10. get('h1').should(haveComputedStyle('height', '0px'))
  11. get('button').click()
  12. get('h1').should(haveAttribute('style', 'overflow: hidden; height: auto;'))
  13. get('button').click()
  14. get('h1').should(haveComputedStyle('height', '0px'))
  15. },
  16. )
  17. test('@click.away with x-collapse (prevent race condition)',
  18. html`
  19. <div x-data="{ show: false }">
  20. <button @click="show = true">Show</button>
  21. <h1 x-show="show" @click.away="show = false" x-collapse>h1</h1>
  22. </div>
  23. `,
  24. ({ get }) => {
  25. get('h1').should(haveComputedStyle('height', '0px'))
  26. get('button').click()
  27. get('h1').should(haveAttribute('style', 'overflow: hidden; height: auto;'))
  28. }
  29. )
  30. test('@click.away with x-collapse and borders (prevent race condition)',
  31. html`
  32. <div x-data="{ show: false }">
  33. <button @click="show = true">Show</button>
  34. <h1 style="border: 1x solid" x-show="show" @click.away="show = false" x-collapse>h1</h1>
  35. </div>
  36. `,
  37. ({ get }) => {
  38. get('h1').should(haveComputedStyle('height', '0px'))
  39. get('button').click()
  40. get('h1').should(haveAttribute('style', 'overflow: hidden; height: auto;'))
  41. }
  42. )