1
0

collapse.spec.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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('h1').should(haveAttribute('style', 'height: 0px; overflow: hidden;'))
  12. get('button').click()
  13. get('h1').should(haveAttribute('style', 'height: auto;'))
  14. get('button').click()
  15. get('h1').should(haveComputedStyle('height', '0px'))
  16. },
  17. )
  18. test('@click.away with x-collapse (prevent race condition)',
  19. html`
  20. <div x-data="{ show: false }">
  21. <button @click="show = true">Show</button>
  22. <h1 x-show="show" @click.away="show = false" x-collapse>h1</h1>
  23. </div>
  24. `,
  25. ({ get }) => {
  26. get('h1').should(haveComputedStyle('height', '0px'))
  27. get('button').click()
  28. get('h1').should(haveAttribute('style', 'height: auto;'))
  29. }
  30. )
  31. test('@click.away with x-collapse and borders (prevent race condition)',
  32. html`
  33. <div x-data="{ show: false }">
  34. <button @click="show = true">Show</button>
  35. <h1 style="border: 1x solid" x-show="show" @click.away="show = false" x-collapse>h1</h1>
  36. </div>
  37. `,
  38. ({ get }) => {
  39. get('h1').should(haveComputedStyle('height', '0px'))
  40. get('button').click()
  41. get('h1').should(haveAttribute('style', 'height: auto;'))
  42. }
  43. )