sort.spec.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. import { haveText, html, test } from '../../utils'
  2. /**
  3. * Skipping all these tests because they are flaky in CI.
  4. * They should all pass locally though...
  5. */
  6. test.skip('basic drag sorting works',
  7. [html`
  8. <div x-data>
  9. <ul x-sort>
  10. <li id="1">foo</li>
  11. <li id="2">bar</li>
  12. <li id="3">baz</li>
  13. </ul>
  14. </div>
  15. `],
  16. ({ get }) => {
  17. get('ul li').eq(0).should(haveText('foo'))
  18. get('ul li').eq(1).should(haveText('bar'))
  19. get('ul li').eq(2).should(haveText('baz'))
  20. // Unfortunately, github actions doesn't like "async/await" here
  21. // so we need to use .then() throughout this entire test...
  22. get('#1').drag('#3').then(() => {
  23. get('ul li').eq(0).should(haveText('bar'))
  24. get('ul li').eq(1).should(haveText('baz'))
  25. get('ul li').eq(2).should(haveText('foo'))
  26. get('#3').drag('#1').then(() => {
  27. get('ul li').eq(0).should(haveText('bar'))
  28. get('ul li').eq(1).should(haveText('foo'))
  29. get('ul li').eq(2).should(haveText('baz'))
  30. })
  31. })
  32. },
  33. )
  34. test.skip('can use a custom handle',
  35. [html`
  36. <div x-data>
  37. <ul x-sort>
  38. <li id="1"><span x-sort:handle>handle</span> - foo</li>
  39. <li id="2"><span x-sort:handle>handle</span> - bar</li>
  40. </ul>
  41. </div>
  42. `],
  43. ({ get }) => {
  44. get('ul li').eq(0).should(haveText('handle - foo'))
  45. get('ul li').eq(1).should(haveText('handle - bar'))
  46. get('#1 span').drag('#2').then(() => {
  47. get('ul li').eq(0).should(haveText('handle - bar'))
  48. get('ul li').eq(1).should(haveText('handle - foo'))
  49. })
  50. },
  51. )
  52. test.skip('can move items between groups',
  53. [html`
  54. <div x-data>
  55. <ul x-sort x-sort:group="one">
  56. <li id="1">foo</li>
  57. <li id="2">bar</li>
  58. </ul>
  59. <ol x-sort x-sort:group="one">
  60. <li id="3">oof</li>
  61. <li id="4">rab</li>
  62. </ol>
  63. </div>
  64. `],
  65. ({ get }) => {
  66. get('ul li').eq(0).should(haveText('foo'))
  67. get('ul li').eq(1).should(haveText('bar'))
  68. get('ol li').eq(0).should(haveText('oof'))
  69. get('ol li').eq(1).should(haveText('rab'))
  70. get('#1').drag('#4').then(() => {
  71. get('ul li').eq(0).should(haveText('bar'))
  72. get('ol li').eq(0).should(haveText('oof'))
  73. get('ol li').eq(1).should(haveText('foo'))
  74. get('ol li').eq(2).should(haveText('rab'))
  75. })
  76. },
  77. )
  78. test.skip('sort handle method',
  79. [html`
  80. <div x-data="{ handle(key, position) { $refs.outlet.textContent = key+'-'+position } }">
  81. <ul x-sort="handle">
  82. <li x-sort:key="1" id="1">foo</li>
  83. <li x-sort:key="2" id="2">bar</li>
  84. <li x-sort:key="3" id="3">baz</li>
  85. </ul>
  86. <h1 x-ref="outlet"></h1>
  87. </div>
  88. `],
  89. ({ get }) => {
  90. get('#1').drag('#3').then(() => {
  91. get('h1').should(haveText('1-2'))
  92. get('#3').drag('#1').then(() => {
  93. get('h1').should(haveText('3-2'))
  94. })
  95. })
  96. },
  97. )
  98. test.skip('item is also supported for the key in the sort handle method',
  99. [html`
  100. <div x-data="{ handle(item, position) { $refs.outlet.textContent = item+'-'+position } }">
  101. <ul x-sort="handle">
  102. <li x-sort:item="1" id="1">foo</li>
  103. <li x-sort:item="2" id="2">bar</li>
  104. <li x-sort:item="3" id="3">baz</li>
  105. </ul>
  106. <h1 x-ref="outlet"></h1>
  107. </div>
  108. `],
  109. ({ get }) => {
  110. get('#1').drag('#3').then(() => {
  111. get('h1').should(haveText('1-2'))
  112. get('#3').drag('#1').then(() => {
  113. get('h1').should(haveText('3-2'))
  114. })
  115. })
  116. },
  117. )
  118. test.skip('can access key and position in handler',
  119. [html`
  120. <div x-data="{ handle(key, position) { $refs.outlet.textContent = key+'-'+position } }">
  121. <ul x-sort="handle($position, $key)">
  122. <li x-sort:key="1" id="1">foo</li>
  123. <li x-sort:key="2" id="2">bar</li>
  124. <li x-sort:key="3" id="3">baz</li>
  125. </ul>
  126. <h1 x-ref="outlet"></h1>
  127. </div>
  128. `],
  129. ({ get }) => {
  130. get('#1').drag('#3').then(() => {
  131. get('h1').should(haveText('2-1'))
  132. get('#3').drag('#1').then(() => {
  133. get('h1').should(haveText('2-3'))
  134. })
  135. })
  136. },
  137. )
  138. test.skip('can access $item instead of $key',
  139. [html`
  140. <div x-data="{ handle(key, position) { $refs.outlet.textContent = key+'-'+position } }">
  141. <ul x-sort="handle($position, $item)">
  142. <li x-sort:key="1" id="1">foo</li>
  143. <li x-sort:key="2" id="2">bar</li>
  144. <li x-sort:key="3" id="3">baz</li>
  145. </ul>
  146. <h1 x-ref="outlet"></h1>
  147. </div>
  148. `],
  149. ({ get }) => {
  150. get('#1').drag('#3').then(() => {
  151. get('h1').should(haveText('2-1'))
  152. get('#3').drag('#1').then(() => {
  153. get('h1').should(haveText('2-3'))
  154. })
  155. })
  156. },
  157. )
  158. test.skip('can use custom sortablejs configuration',
  159. [html`
  160. <div x-data>
  161. <ul x-sort x-sort:config="{ filter: '[data-ignore]' }">
  162. <li id="1" data-ignore>foo</li>
  163. <li id="2">bar</li>
  164. <li id="3">baz</li>
  165. </ul>
  166. </div>
  167. `],
  168. ({ get }) => {
  169. get('ul li').eq(0).should(haveText('foo'))
  170. get('ul li').eq(1).should(haveText('bar'))
  171. get('ul li').eq(2).should(haveText('baz'))
  172. get('#1').drag('#3').then(() => {
  173. get('ul li').eq(0).should(haveText('foo'))
  174. get('ul li').eq(1).should(haveText('bar'))
  175. get('ul li').eq(2).should(haveText('baz'))
  176. get('#3').drag('#1').then(() => {
  177. get('ul li').eq(0).should(haveText('baz'))
  178. get('ul li').eq(1).should(haveText('foo'))
  179. get('ul li').eq(2).should(haveText('bar'))
  180. })
  181. })
  182. },
  183. )
  184. test.skip('works with Livewire morphing',
  185. [html`
  186. <div x-data>
  187. <ul x-sort>
  188. <!-- [if BLOCK]><![endif] -->
  189. <li id="1">foo</li>
  190. <li id="2">bar</li>
  191. <li id="3">baz</li>
  192. <!-- [if ENDBLOCK]><![endif] -->
  193. </ul>
  194. </div>
  195. `],
  196. ({ get }) => {
  197. get('#1').drag('#3').then(() => {
  198. // This is the easiest way I can think of to assert the order of HTML comments doesn't change...
  199. get('ul').should('have.html', `\n <!-- [if BLOCK]><![endif] -->\n \n <li id="2" style="">bar</li>\n <li id="3" style="">baz</li>\n \n <li id="1" draggable="false" class="" style="opacity: 1;">foo</li><!-- [if ENDBLOCK]><![endif] -->`)
  200. })
  201. },
  202. )
  203. test.skip('x-sort:item can be used as a filter',
  204. [html`
  205. <div x-data>
  206. <ul x-sort>
  207. <li x-sort:item id="1">foo</li>
  208. <li id="2">bar</li>
  209. <li x-sort:item id="3">baz</li>
  210. </ul>
  211. </div>
  212. `],
  213. ({ get }) => {
  214. get('ul li').eq(0).should(haveText('foo'))
  215. get('ul li').eq(1).should(haveText('bar'))
  216. get('ul li').eq(2).should(haveText('baz'))
  217. // Unfortunately, github actions doesn't like "async/await" here
  218. // so we need to use .then() throughout this entire test...
  219. get('#1').drag('#3').then(() => {
  220. get('ul li').eq(0).should(haveText('bar'))
  221. get('ul li').eq(1).should(haveText('baz'))
  222. get('ul li').eq(2).should(haveText('foo'))
  223. get('#2').drag('#1').then(() => {
  224. get('ul li').eq(0).should(haveText('bar'))
  225. get('ul li').eq(1).should(haveText('baz'))
  226. get('ul li').eq(2).should(haveText('foo'))
  227. })
  228. })
  229. },
  230. )