x-transition.spec.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. import { beHidden, beVisible, haveClasses, haveComputedStyle, html, notBeVisible, notHaveClasses, notHaveComputedStyle, test } from '../../utils'
  2. test('transition in',
  3. html`
  4. <style>
  5. .transition { transition-property: background-color, border-color, color, fill, stroke; transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); transition-duration: 150ms; }
  6. .duration-100 { transition-duration: 100ms; }
  7. </style>
  8. <div x-data="{ show: false }">
  9. <button x-on:click="show = ! show"></button>
  10. <span
  11. x-show="show"
  12. x-transition:enter="transition duration-100 enter"
  13. x-transition:enter-start="enter-start"
  14. x-transition:enter-end="enter-end"
  15. >thing</span>
  16. </div>
  17. `,
  18. ({ get }) => {
  19. get('span').should(beHidden())
  20. get('span').should(notHaveClasses(['enter', 'enter-start', 'enter-end']))
  21. get('button').click()
  22. get('span').should(beVisible())
  23. get('span').should(notHaveClasses(['enter-start']))
  24. get('span').should(haveClasses(['enter', 'enter-end']))
  25. }
  26. )
  27. test('transition out',
  28. html`
  29. <style>
  30. .transition { transition-property: background-color, border-color, color, fill, stroke; transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); transition-duration: 150ms; }
  31. .duration-100 { transition-duration: 100ms; }
  32. </style>
  33. <div x-data="{ show: true }">
  34. <button x-on:click="show = ! show"></button>
  35. <span
  36. x-show="show"
  37. x-transition:leave="transition duration-100 leave"
  38. x-transition:leave-start="leave-start"
  39. x-transition:leave-end="leave-end"
  40. >thing</span>
  41. </div>
  42. `,
  43. ({ get }) => {
  44. get('span').should(beVisible())
  45. get('span').should(notHaveClasses(['leave', 'leave-start', 'leave-end']))
  46. get('button').click()
  47. get('span').should(beVisible())
  48. get('span').should(notHaveClasses(['leave-start']))
  49. get('span').should(haveClasses(['leave', 'leave-end']))
  50. get('span').should(beHidden())
  51. }
  52. )
  53. test('transition:enter in nested x-show visually runs',
  54. html`
  55. <style>
  56. .transition { transition: opacity 1s ease; }
  57. .opacity-0 {opacity: 0}
  58. .opacity-1 {opacity: 1}
  59. </style>
  60. <div x-data="{ show: false }">
  61. <span x-show="show">
  62. <h1 x-show="show"
  63. x-transition:enter="transition"
  64. x-transition:enter-start="opacity-0"
  65. x-transition:enter-end="opacity-1">thing</h1>
  66. </span>
  67. <button x-on:click="show = true"></button>
  68. </div>
  69. `,
  70. ({ get }) => {
  71. get('button').click()
  72. get('span').should(beVisible())
  73. get('h1').should(notHaveComputedStyle('opacity', '1')) // We expect a value between 0 and 1
  74. get('h1').should(haveComputedStyle('opacity', '1')) // Eventually opacity will be 1
  75. }
  76. )
  77. test('transition duration and delay with and without ms syntax',
  78. html`
  79. <div x-data="{ showMs: false, showBlank: false }">
  80. <span class="ms"
  81. x-show="showMs"
  82. x-transition.delay.80ms.duration.120ms>ms syntax</span>
  83. <span class="blank"
  84. x-show="showBlank"
  85. x-transition.delay.80.duration.120>blank syntax</span>
  86. <button class="ms" x-on:click="showMs = true"></button>
  87. <button class="blank" x-on:click="showBlank = true"></button>
  88. </div>
  89. `,
  90. ({ get }) => {
  91. get('span.ms').should(notBeVisible())
  92. get('button.ms').click()
  93. get('span.ms').should(notBeVisible()) // Not visible due to delay
  94. get('span.ms').should(beVisible())
  95. get('span.ms').should(notHaveComputedStyle('opacity', '1')) // We expect a value between 0 and 1
  96. get('span.ms').should(haveComputedStyle('opacity', '1')) // Eventually opacity will be 1
  97. get('span.blank').should(notBeVisible())
  98. get('button.blank').click()
  99. get('span.blank').should(notBeVisible()) // Not visible due to delay
  100. get('span.blank').should(beVisible())
  101. get('span.blank').should(notHaveComputedStyle('opacity', '1')) // We expect a value between 0 and 1
  102. get('span.blank').should(haveComputedStyle('opacity', '1')) // Eventually opacity will be 1
  103. }
  104. )
  105. test(
  106. 'bound x-transition can handle empty string and true values',
  107. html`
  108. <script>
  109. window.transitions = () => {
  110. return {
  111. withEmptyString: {
  112. ["x-transition.opacity"]: "",
  113. },
  114. withBoolean: {
  115. ["x-transition.opacity"]: true,
  116. },
  117. };
  118. };
  119. </script>
  120. <div x-data="transitions()">
  121. <button x-bind="withEmptyString"></button>
  122. <span x-bind="withBoolean">thing</span>
  123. </div>
  124. `,
  125. ({ get }) =>
  126. {
  127. get('span').should(beVisible())
  128. get('span').should(beVisible())
  129. }
  130. );