combobox.spec.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867
  1. import { beVisible, beHidden, haveAttribute, haveClasses, notHaveClasses, haveText, html, notBeVisible, notHaveAttribute, notExist, haveFocus, test} from '../../../utils'
  2. test.only('it works with x-model',
  3. [html`
  4. <div
  5. x-data="{ active: null, people: [
  6. { id: 1, name: 'Wade Cooper' },
  7. { id: 2, name: 'Arlene Mccoy' },
  8. { id: 3, name: 'Devon Webb' },
  9. { id: 4, name: 'Tom Cook' },
  10. { id: 5, name: 'Tanya Fox', disabled: true },
  11. { id: 6, name: 'Hellen Schmidt' },
  12. { id: 7, name: 'Caroline Schultz' },
  13. { id: 8, name: 'Mason Heaney' },
  14. { id: 9, name: 'Claudie Smitham' },
  15. { id: 10, name: 'Emil Schaefer' },
  16. ]}"
  17. x-combobox
  18. x-model="active"
  19. >
  20. <label x-combobox:label>Assigned to</label>
  21. <input x-combobox:input x-text="active ? active.name : 'Select Person'" type="text">
  22. <button x-combobox:button x-text="active ? active.name : 'Select Person'"></button>
  23. <ul x-combobox:options>
  24. <template x-for="person in people" :key="person.id">
  25. <li
  26. x-combobox:option
  27. :value="person"
  28. :disabled="person.disabled"
  29. :option="person.id"
  30. >
  31. <span x-text="person.name"></span>
  32. </li>
  33. </template>
  34. </ul>
  35. </div>
  36. `],
  37. ({ get }) => {
  38. get('ul').should(notBeVisible())
  39. get('button')
  40. .should(haveText('Select Person'))
  41. .click()
  42. get('ul').should(beVisible())
  43. get('button').click()
  44. get('ul').should(notBeVisible())
  45. get('button').click()
  46. get('[option="2"]').click()
  47. get('ul').should(notBeVisible())
  48. get('button').should(haveText('Arlene Mccoy'))
  49. },
  50. )
  51. // test('it works with internal state',
  52. // [html`
  53. // <div
  54. // x-data="{ people: [
  55. // { id: 1, name: 'Wade Cooper' },
  56. // { id: 2, name: 'Arlene Mccoy' },
  57. // { id: 3, name: 'Devon Webb' },
  58. // { id: 4, name: 'Tom Cook' },
  59. // { id: 5, name: 'Tanya Fox', disabled: true },
  60. // { id: 6, name: 'Hellen Schmidt' },
  61. // { id: 7, name: 'Caroline Schultz' },
  62. // { id: 8, name: 'Mason Heaney' },
  63. // { id: 9, name: 'Claudie Smitham' },
  64. // { id: 10, name: 'Emil Schaefer' },
  65. // ]}"
  66. // x-combobox
  67. // >
  68. // <label x-combobox:label>Assigned to</label>
  69. // <button x-combobox:button x-text="$combobox.selected ? $combobox.selected.name : 'Select Person'"></button>
  70. // <ul x-combobox:options>
  71. // <template x-for="person in people" :key="person.id">
  72. // <li
  73. // :option="person.id"
  74. // x-combobox:option
  75. // :value="person"
  76. // :disabled="person.disabled"
  77. // >
  78. // <span x-text="person.name"></span>
  79. // </li>
  80. // </template>
  81. // </ul>
  82. // </div>
  83. // `],
  84. // ({ get }) => {
  85. // get('ul').should(notBeVisible())
  86. // get('button')
  87. // .should(haveText('Select Person'))
  88. // .click()
  89. // get('ul').should(beVisible())
  90. // get('button').click()
  91. // get('ul').should(notBeVisible())
  92. // get('button').click()
  93. // get('[option="2"]').click()
  94. // get('ul').should(notBeVisible())
  95. // get('button').should(haveText('Arlene Mccoy'))
  96. // },
  97. // )
  98. // test('$combobox/$comboboxOption',
  99. // [html`
  100. // <div
  101. // x-data="{ people: [
  102. // { id: 1, name: 'Wade Cooper' },
  103. // { id: 2, name: 'Arlene Mccoy' },
  104. // { id: 3, name: 'Devon Webb' },
  105. // { id: 4, name: 'Tom Cook' },
  106. // { id: 5, name: 'Tanya Fox', disabled: true },
  107. // { id: 6, name: 'Hellen Schmidt' },
  108. // { id: 7, name: 'Caroline Schultz' },
  109. // { id: 8, name: 'Mason Heaney' },
  110. // { id: 9, name: 'Claudie Smitham' },
  111. // { id: 10, name: 'Emil Schaefer' },
  112. // ]}"
  113. // x-combobox
  114. // >
  115. // <label x-combobox:label>Assigned to</label>
  116. // <button x-combobox:button x-text="$combobox.selected ? $combobox.selected.name : 'Select Person'"></button>
  117. // <article x-text="$combobox.active?.name"></article>
  118. // <ul x-combobox:options>
  119. // <template x-for="person in people" :key="person.id">
  120. // <li
  121. // :option="person.id"
  122. // x-combobox:option
  123. // :value="person"
  124. // :disabled="person.disabled"
  125. // :class="{
  126. // 'selected': $comboboxOption.isSelected,
  127. // 'active': $comboboxOption.isActive,
  128. // 'disabled': $comboboxOption.isDisabled,
  129. // }"
  130. // >
  131. // <span x-text="person.name"></span>
  132. // </li>
  133. // </template>
  134. // </ul>
  135. // </div>
  136. // `],
  137. // ({ get }) => {
  138. // get('article').should(haveText(''))
  139. // get('[option="5"]').should(haveClasses(['disabled']))
  140. // get('button')
  141. // .should(haveText('Select Person'))
  142. // .click()
  143. // get('article').should(haveText('Wade Cooper'))
  144. // get('[option="1"]').should(haveClasses(['active']))
  145. // get('ul').type('{downarrow}')
  146. // get('article').should(haveText('Arlene Mccoy'))
  147. // get('[option="2"]').should(haveClasses(['active']))
  148. // get('button').should(haveText('Select Person'))
  149. // get('[option="2"]').click()
  150. // get('button').should(haveText('Arlene Mccoy'))
  151. // get('[option="2"]').should(haveClasses(['selected']))
  152. // },
  153. // )
  154. // test('"name" prop',
  155. // [html`
  156. // <div
  157. // x-data="{ people: [
  158. // { id: 1, name: 'Wade Cooper' },
  159. // { id: 2, name: 'Arlene Mccoy' },
  160. // { id: 3, name: 'Devon Webb' },
  161. // { id: 4, name: 'Tom Cook' },
  162. // { id: 5, name: 'Tanya Fox', disabled: true },
  163. // { id: 6, name: 'Hellen Schmidt' },
  164. // { id: 7, name: 'Caroline Schultz' },
  165. // { id: 8, name: 'Mason Heaney' },
  166. // { id: 9, name: 'Claudie Smitham' },
  167. // { id: 10, name: 'Emil Schaefer' },
  168. // ]}"
  169. // x-combobox
  170. // name="person"
  171. // >
  172. // <label x-combobox:label>Assigned to</label>
  173. // <button x-combobox:button x-text="$combobox.selected ? $combobox.selected : 'Select Person'"></button>
  174. // <ul x-combobox:options>
  175. // <template x-for="person in people" :key="person.id">
  176. // <li
  177. // :option="person.id"
  178. // x-combobox:option
  179. // :value="person.id"
  180. // :disabled="person.disabled"
  181. // :class="{
  182. // 'selected': $comboboxOption.isSelected,
  183. // 'active': $comboboxOption.isActive,
  184. // }"
  185. // >
  186. // <span x-text="person.name"></span>
  187. // </li>
  188. // </template>
  189. // </ul>
  190. // </div>
  191. // `],
  192. // ({ get }) => {
  193. // get('input').should(haveAttribute('value', 'null'))
  194. // get('button').click()
  195. // get('input').should(haveAttribute('value', 'null'))
  196. // get('[option="2"]').click()
  197. // get('input').should(beHidden())
  198. // .should(haveAttribute('name', 'person'))
  199. // .should(haveAttribute('value', '2'))
  200. // .should(haveAttribute('type', 'hidden'))
  201. // get('button').click()
  202. // get('[option="4"]').click()
  203. // get('input').should(beHidden())
  204. // .should(haveAttribute('name', 'person'))
  205. // .should(haveAttribute('value', '4'))
  206. // .should(haveAttribute('type', 'hidden'))
  207. // },
  208. // );
  209. // test('"name" prop with object value',
  210. // [html`
  211. // <div
  212. // x-data="{ people: [
  213. // { id: 1, name: 'Wade Cooper' },
  214. // { id: 2, name: 'Arlene Mccoy' },
  215. // { id: 3, name: 'Devon Webb' },
  216. // { id: 4, name: 'Tom Cook' },
  217. // { id: 5, name: 'Tanya Fox', disabled: true },
  218. // { id: 6, name: 'Hellen Schmidt' },
  219. // { id: 7, name: 'Caroline Schultz' },
  220. // { id: 8, name: 'Mason Heaney' },
  221. // { id: 9, name: 'Claudie Smitham' },
  222. // { id: 10, name: 'Emil Schaefer' },
  223. // ]}"
  224. // x-combobox
  225. // name="person"
  226. // >
  227. // <label x-combobox:label>Assigned to</label>
  228. // <button x-combobox:button x-text="$combobox.selected ? $combobox.selected.name : 'Select Person'"></button>
  229. // <ul x-combobox:options>
  230. // <template x-for="person in people" :key="person.id">
  231. // <li
  232. // :option="person.id"
  233. // x-combobox:option
  234. // :value="person"
  235. // :disabled="person.disabled"
  236. // :class="{
  237. // 'selected': $comboboxOption.isSelected,
  238. // 'active': $comboboxOption.isActive,
  239. // }"
  240. // >
  241. // <span x-text="person.name"></span>
  242. // </li>
  243. // </template>
  244. // </ul>
  245. // </div>
  246. // `],
  247. // ({ get }) => {
  248. // get('input[name="person"]').should(haveAttribute('value', 'null'))
  249. // get('button').click()
  250. // get('[name="person[id]"]').should(notExist())
  251. // get('[option="2"]').click()
  252. // get('input[name="person"]').should(notExist())
  253. // get('[name="person[id]"]').should(beHidden())
  254. // .should(haveAttribute('value', '2'))
  255. // .should(haveAttribute('type', 'hidden'))
  256. // get('[name="person[name]"]').should(beHidden())
  257. // .should(haveAttribute('value', 'Arlene Mccoy'))
  258. // .should(haveAttribute('type', 'hidden'))
  259. // get('button').click()
  260. // get('[option="4"]').click()
  261. // get('[name="person[id]"]').should(beHidden())
  262. // .should(haveAttribute('value', '4'))
  263. // .should(haveAttribute('type', 'hidden'))
  264. // get('[name="person[name]"]').should(beHidden())
  265. // .should(haveAttribute('value', 'Tom Cook'))
  266. // .should(haveAttribute('type', 'hidden'))
  267. // },
  268. // );
  269. // test('"default-value" prop',
  270. // [html`
  271. // <div
  272. // x-data="{ people: [
  273. // { id: 1, name: 'Wade Cooper' },
  274. // { id: 2, name: 'Arlene Mccoy' },
  275. // { id: 3, name: 'Devon Webb' },
  276. // { id: 4, name: 'Tom Cook' },
  277. // { id: 5, name: 'Tanya Fox', disabled: true },
  278. // { id: 6, name: 'Hellen Schmidt' },
  279. // { id: 7, name: 'Caroline Schultz' },
  280. // { id: 8, name: 'Mason Heaney' },
  281. // { id: 9, name: 'Claudie Smitham' },
  282. // { id: 10, name: 'Emil Schaefer' },
  283. // ]}"
  284. // x-combobox
  285. // name="person"
  286. // default-value="2"
  287. // >
  288. // <label x-combobox:label>Assigned to</label>
  289. // <button x-combobox:button x-text="$combobox.selected ? $combobox.selected : 'Select Person'"></button>
  290. // <ul x-combobox:options>
  291. // <template x-for="person in people" :key="person.id">
  292. // <li
  293. // :option="person.id"
  294. // x-combobox:option
  295. // :value="person.id"
  296. // :disabled="person.disabled"
  297. // :class="{
  298. // 'selected': $comboboxOption.isSelected,
  299. // 'active': $comboboxOption.isActive,
  300. // }"
  301. // >
  302. // <span x-text="person.name"></span>
  303. // </li>
  304. // </template>
  305. // </ul>
  306. // </div>
  307. // `],
  308. // ({ get }) => {
  309. // get('input').should(beHidden())
  310. // .should(haveAttribute('name', 'person'))
  311. // .should(haveAttribute('value', '2'))
  312. // .should(haveAttribute('type', 'hidden'))
  313. // },
  314. // );
  315. // test('"multiple" prop',
  316. // [html`
  317. // <div
  318. // x-data="{
  319. // people: [
  320. // { id: 1, name: 'Wade Cooper' },
  321. // { id: 2, name: 'Arlene Mccoy' },
  322. // { id: 3, name: 'Devon Webb' },
  323. // { id: 4, name: 'Tom Cook' },
  324. // { id: 5, name: 'Tanya Fox', disabled: true },
  325. // { id: 6, name: 'Hellen Schmidt' },
  326. // { id: 7, name: 'Caroline Schultz' },
  327. // { id: 8, name: 'Mason Heaney' },
  328. // { id: 9, name: 'Claudie Smitham' },
  329. // { id: 10, name: 'Emil Schaefer' },
  330. // ]
  331. // }"
  332. // x-combobox
  333. // multiple
  334. // >
  335. // <label x-combobox:label>Assigned to</label>
  336. // <button x-combobox:button x-text="$combobox.selected ? $combobox.selected.join(',') : 'Select People'"></button>
  337. // <ul x-combobox:options>
  338. // <template x-for="person in people" :key="person.id">
  339. // <li
  340. // :option="person.id"
  341. // x-combobox:option
  342. // :value="person.id"
  343. // :disabled="person.disabled"
  344. // :class="{
  345. // 'selected': $comboboxOption.isSelected,
  346. // 'active': $comboboxOption.isActive,
  347. // }"
  348. // >
  349. // <span x-text="person.name"></span>
  350. // </li>
  351. // </template>
  352. // </ul>
  353. // </div>
  354. // `],
  355. // ({ get }) => {
  356. // get('button').click()
  357. // get('[option="2"]').click()
  358. // get('ul').should(beVisible())
  359. // get('button').should(haveText('2'))
  360. // get('[option="4"]').click()
  361. // get('button').should(haveText('2,4'))
  362. // get('ul').should(beVisible())
  363. // get('[option="4"]').click()
  364. // get('button').should(haveText('2'))
  365. // get('ul').should(beVisible())
  366. // },
  367. // );
  368. // test('"multiple" and "name" props together',
  369. // [html`
  370. // <div
  371. // x-data="{
  372. // people: [
  373. // { id: 1, name: 'Wade Cooper' },
  374. // { id: 2, name: 'Arlene Mccoy' },
  375. // { id: 3, name: 'Devon Webb' },
  376. // { id: 4, name: 'Tom Cook' },
  377. // { id: 5, name: 'Tanya Fox', disabled: true },
  378. // { id: 6, name: 'Hellen Schmidt' },
  379. // { id: 7, name: 'Caroline Schultz' },
  380. // { id: 8, name: 'Mason Heaney' },
  381. // { id: 9, name: 'Claudie Smitham' },
  382. // { id: 10, name: 'Emil Schaefer' },
  383. // ]
  384. // }"
  385. // x-combobox
  386. // multiple
  387. // name="people"
  388. // >
  389. // <label x-combobox:label>Assigned to</label>
  390. // <button x-combobox:button x-text="$combobox.selected ? $combobox.selected.map(p => p.id).join(',') : 'Select People'"></button>
  391. // <ul x-combobox:options>
  392. // <template x-for="person in people" :key="person.id">
  393. // <li
  394. // :option="person.id"
  395. // x-combobox:option
  396. // :value="person"
  397. // :disabled="person.disabled"
  398. // :class="{
  399. // 'selected': $comboboxOption.isSelected,
  400. // 'active': $comboboxOption.isActive,
  401. // }"
  402. // >
  403. // <span x-text="person.name"></span>
  404. // </li>
  405. // </template>
  406. // </ul>
  407. // </div>
  408. // `],
  409. // ({ get }) => {
  410. // get('input[name="people"]').should(haveAttribute('value', 'null'))
  411. // get('button').click()
  412. // get('[name="people[0][id]"]').should(notExist())
  413. // get('[option="2"]').click()
  414. // get('ul').should(beVisible())
  415. // get('button').should(haveText('2'))
  416. // get('input[name="people"]').should(notExist())
  417. // get('[name="people[0][id]"]').should(beHidden())
  418. // .should(haveAttribute('value', '2'))
  419. // .should(haveAttribute('type', 'hidden'))
  420. // get('[name="people[0][name]"]').should(beHidden())
  421. // .should(haveAttribute('value', 'Arlene Mccoy'))
  422. // .should(haveAttribute('type', 'hidden'))
  423. // get('[option="4"]').click()
  424. // get('[name="people[0][id]"]').should(beHidden())
  425. // .should(haveAttribute('value', '2'))
  426. // .should(haveAttribute('type', 'hidden'))
  427. // get('[name="people[0][name]"]').should(beHidden())
  428. // .should(haveAttribute('value', 'Arlene Mccoy'))
  429. // .should(haveAttribute('type', 'hidden'))
  430. // get('[name="people[1][id]"]').should(beHidden())
  431. // .should(haveAttribute('value', '4'))
  432. // .should(haveAttribute('type', 'hidden'))
  433. // get('[name="people[1][name]"]').should(beHidden())
  434. // .should(haveAttribute('value', 'Tom Cook'))
  435. // .should(haveAttribute('type', 'hidden'))
  436. // get('button').should(haveText('2,4'))
  437. // get('ul').should(beVisible())
  438. // get('[option="4"]').click()
  439. // get('[name="people[0][id]"]').should(beHidden())
  440. // .should(haveAttribute('value', '2'))
  441. // .should(haveAttribute('type', 'hidden'))
  442. // get('[name="people[0][name]"]').should(beHidden())
  443. // .should(haveAttribute('value', 'Arlene Mccoy'))
  444. // .should(haveAttribute('type', 'hidden'))
  445. // get('[name="people[1][id]"]').should(notExist())
  446. // get('[name="people[1][name]"]').should(notExist())
  447. // get('button').should(haveText('2'))
  448. // get('ul').should(beVisible())
  449. // },
  450. // );
  451. // test('keyboard controls',
  452. // [html`
  453. // <div
  454. // x-data="{ active: null, people: [
  455. // { id: 1, name: 'Wade Cooper' },
  456. // { id: 2, name: 'Arlene Mccoy' },
  457. // { id: 3, name: 'Devon Webb', disabled: true },
  458. // { id: 4, name: 'Tom Cook' },
  459. // { id: 5, name: 'Tanya Fox', disabled: true },
  460. // { id: 6, name: 'Hellen Schmidt' },
  461. // { id: 7, name: 'Caroline Schultz' },
  462. // { id: 8, name: 'Mason Heaney' },
  463. // { id: 9, name: 'Claudie Smitham' },
  464. // { id: 10, name: 'Emil Schaefer' },
  465. // ]}"
  466. // x-combobox
  467. // x-model="active"
  468. // >
  469. // <label x-combobox:label>Assigned to</label>
  470. // <button x-combobox:button x-text="active ? active.name : 'Select Person'"></button>
  471. // <ul x-combobox:options options>
  472. // <template x-for="person in people" :key="person.id">
  473. // <li
  474. // :option="person.id"
  475. // x-combobox:option
  476. // :value="person"
  477. // :disabled="person.disabled"
  478. // :class="{
  479. // 'selected': $comboboxOption.isSelected,
  480. // 'active': $comboboxOption.isActive,
  481. // }"
  482. // >
  483. // <span x-text="person.name"></span>
  484. // </li>
  485. // </template>
  486. // </ul>
  487. // </div>
  488. // `],
  489. // ({ get }) => {
  490. // get('.active').should(notExist())
  491. // get('button').focus().type(' ')
  492. // get('[options]')
  493. // .should(beVisible())
  494. // .should(haveFocus())
  495. // get('[option="1"]')
  496. // .should(haveClasses(['active']))
  497. // get('[options]')
  498. // .type('{downarrow}')
  499. // get('[option="2"]')
  500. // .should(haveClasses(['active']))
  501. // get('[options]')
  502. // .type('{downarrow}')
  503. // get('[option="4"]')
  504. // .should(haveClasses(['active']))
  505. // get('[options]')
  506. // .type('{uparrow}')
  507. // get('[option="2"]')
  508. // .should(haveClasses(['active']))
  509. // get('[options]')
  510. // .type('{home}')
  511. // get('[option="1"]')
  512. // .should(haveClasses(['active']))
  513. // get('[options]')
  514. // .type('{end}')
  515. // get('[option="10"]')
  516. // .should(haveClasses(['active']))
  517. // get('[options]')
  518. // .type('{pageUp}')
  519. // get('[option="1"]')
  520. // .should(haveClasses(['active']))
  521. // get('[options]')
  522. // .type('{pageDown}')
  523. // get('[option="10"]')
  524. // .should(haveClasses(['active']))
  525. // get('[options]')
  526. // .tab()
  527. // .should(haveFocus())
  528. // .should(beVisible())
  529. // .tab({ shift: true })
  530. // .should(haveFocus())
  531. // .should(beVisible())
  532. // .type('{esc}')
  533. // .should(notBeVisible())
  534. // },
  535. // )
  536. // test('"horizontal" keyboard controls',
  537. // [html`
  538. // <div
  539. // x-data="{ active: null, people: [
  540. // { id: 1, name: 'Wade Cooper' },
  541. // { id: 2, name: 'Arlene Mccoy' },
  542. // { id: 3, name: 'Devon Webb', disabled: true },
  543. // { id: 4, name: 'Tom Cook' },
  544. // { id: 5, name: 'Tanya Fox', disabled: true },
  545. // { id: 6, name: 'Hellen Schmidt' },
  546. // { id: 7, name: 'Caroline Schultz' },
  547. // { id: 8, name: 'Mason Heaney' },
  548. // { id: 9, name: 'Claudie Smitham' },
  549. // { id: 10, name: 'Emil Schaefer' },
  550. // ]}"
  551. // x-combobox
  552. // x-model="active"
  553. // horizontal
  554. // >
  555. // <label x-combobox:label>Assigned to</label>
  556. // <button x-combobox:button x-text="active ? active.name : 'Select Person'"></button>
  557. // <ul x-combobox:options options>
  558. // <template x-for="person in people" :key="person.id">
  559. // <li
  560. // :option="person.id"
  561. // x-combobox:option
  562. // :value="person"
  563. // :disabled="person.disabled"
  564. // :class="{
  565. // 'selected': $comboboxOption.isSelected,
  566. // 'active': $comboboxOption.isActive,
  567. // }"
  568. // >
  569. // <span x-text="person.name"></span>
  570. // </li>
  571. // </template>
  572. // </ul>
  573. // </div>
  574. // `],
  575. // ({ get }) => {
  576. // get('.active').should(notExist())
  577. // get('button').focus().type(' ')
  578. // get('[options]')
  579. // .should(haveAttribute('aria-orientation', 'horizontal'))
  580. // .should(beVisible())
  581. // .should(haveFocus())
  582. // get('[option="1"]')
  583. // .should(haveClasses(['active']))
  584. // get('[options]')
  585. // .type('{rightarrow}')
  586. // get('[option="2"]')
  587. // .should(haveClasses(['active']))
  588. // get('[options]')
  589. // .type('{rightarrow}')
  590. // get('[option="4"]')
  591. // .should(haveClasses(['active']))
  592. // get('[options]')
  593. // .type('{leftarrow}')
  594. // get('[option="2"]')
  595. // .should(haveClasses(['active']))
  596. // },
  597. // )
  598. // test('search',
  599. // [html`
  600. // <div
  601. // x-data="{ active: null, people: [
  602. // { id: 1, name: 'Wade Cooper' },
  603. // { id: 2, name: 'Arlene Mccoy' },
  604. // { id: 3, name: 'Devon Webb', disabled: true },
  605. // { id: 4, name: 'Tom Cook' },
  606. // { id: 5, name: 'Tanya Fox', disabled: true },
  607. // { id: 6, name: 'Hellen Schmidt' },
  608. // { id: 7, name: 'Caroline Schultz' },
  609. // { id: 8, name: 'Mason Heaney' },
  610. // { id: 9, name: 'Claudie Smitham' },
  611. // { id: 10, name: 'Emil Schaefer' },
  612. // ]}"
  613. // x-combobox
  614. // x-model="active"
  615. // >
  616. // <label x-combobox:label>Assigned to</label>
  617. // <button x-combobox:button x-text="active ? active.name : 'Select Person'"></button>
  618. // <ul x-combobox:options options>
  619. // <template x-for="person in people" :key="person.id">
  620. // <li
  621. // :option="person.id"
  622. // x-combobox:option
  623. // :value="person"
  624. // :disabled="person.disabled"
  625. // :class="{
  626. // 'selected': $comboboxOption.isSelected,
  627. // 'active': $comboboxOption.isActive,
  628. // }"
  629. // >
  630. // <span x-text="person.name"></span>
  631. // </li>
  632. // </template>
  633. // </ul>
  634. // </div>
  635. // `],
  636. // ({ get, wait }) => {
  637. // get('.active').should(notExist())
  638. // get('button').click()
  639. // get('[options]')
  640. // .type('ar')
  641. // get('[option="2"]')
  642. // .should(haveClasses(['active']))
  643. // wait(500)
  644. // get('[options]')
  645. // .type('ma')
  646. // get('[option="8"]')
  647. // .should(haveClasses(['active']))
  648. // },
  649. // )
  650. // test('changing value manually changes internal state',
  651. // [html`
  652. // <div
  653. // x-data="{ active: null, people: [
  654. // { id: 1, name: 'Wade Cooper' },
  655. // { id: 2, name: 'Arlene Mccoy' },
  656. // { id: 3, name: 'Devon Webb', disabled: true },
  657. // { id: 4, name: 'Tom Cook' },
  658. // { id: 5, name: 'Tanya Fox', disabled: true },
  659. // { id: 6, name: 'Hellen Schmidt' },
  660. // { id: 7, name: 'Caroline Schultz' },
  661. // { id: 8, name: 'Mason Heaney' },
  662. // { id: 9, name: 'Claudie Smitham' },
  663. // { id: 10, name: 'Emil Schaefer' },
  664. // ]}"
  665. // x-combobox
  666. // x-model="active"
  667. // >
  668. // <label x-combobox:label>Assigned to</label>
  669. // <button toggle x-combobox:button x-text="$combobox.selected ? $combobox.selected : 'Select Person'"></button>
  670. // <button select-tim @click="active = 4">Select Tim</button>
  671. // <ul x-combobox:options options>
  672. // <template x-for="person in people" :key="person.id">
  673. // <li
  674. // :option="person.id"
  675. // x-combobox:option
  676. // :value="person.id"
  677. // :disabled="person.disabled"
  678. // :class="{
  679. // 'selected': $comboboxOption.isSelected,
  680. // 'active': $comboboxOption.isActive,
  681. // }"
  682. // >
  683. // <span x-text="person.name"></span>
  684. // </li>
  685. // </template>
  686. // </ul>
  687. // </div>
  688. // `],
  689. // ({ get }) => {
  690. // get('[select-tim]').click()
  691. // get('[option="4"]').should(haveClasses(['selected']))
  692. // get('[option="1"]').should(notHaveClasses(['selected']))
  693. // get('[toggle]').should(haveText('4'))
  694. // },
  695. // )
  696. // test('has accessibility attributes',
  697. // [html`
  698. // <div
  699. // x-data="{ active: null, people: [
  700. // { id: 1, name: 'Wade Cooper' },
  701. // { id: 2, name: 'Arlene Mccoy' },
  702. // { id: 3, name: 'Devon Webb', disabled: true },
  703. // { id: 4, name: 'Tom Cook' },
  704. // { id: 5, name: 'Tanya Fox', disabled: true },
  705. // { id: 6, name: 'Hellen Schmidt' },
  706. // { id: 7, name: 'Caroline Schultz' },
  707. // { id: 8, name: 'Mason Heaney' },
  708. // { id: 9, name: 'Claudie Smitham' },
  709. // { id: 10, name: 'Emil Schaefer' },
  710. // ]}"
  711. // x-combobox
  712. // x-model="active"
  713. // >
  714. // <label x-combobox:label>Assigned to</label>
  715. // <button x-combobox:button x-text="active ? active.name : 'Select Person'"></button>
  716. // <ul x-combobox:options options>
  717. // <template x-for="person in people" :key="person.id">
  718. // <li
  719. // :option="person.id"
  720. // x-combobox:option
  721. // :value="person"
  722. // :disabled="person.disabled"
  723. // :class="{
  724. // 'selected': $comboboxOption.isSelected,
  725. // 'active': $comboboxOption.isActive,
  726. // }"
  727. // >
  728. // <span x-text="person.name"></span>
  729. // </li>
  730. // </template>
  731. // </ul>
  732. // </div>
  733. // `],
  734. // ({ get }) => {
  735. // get('button')
  736. // .should(haveAttribute('aria-haspopup', 'true'))
  737. // .should(haveAttribute('aria-labelledby', 'alpine-combobox-label-1'))
  738. // .should(haveAttribute('aria-expanded', 'false'))
  739. // .should(notHaveAttribute('aria-controls'))
  740. // .should(haveAttribute('id', 'alpine-combobox-button-1'))
  741. // .click()
  742. // .should(haveAttribute('aria-expanded', 'true'))
  743. // .should(haveAttribute('aria-controls', 'alpine-combobox-options-1'))
  744. // get('[options]')
  745. // .should(haveAttribute('aria-orientation', 'vertical'))
  746. // .should(haveAttribute('role', 'combobox'))
  747. // .should(haveAttribute('id', 'alpine-combobox-options-1'))
  748. // .should(haveAttribute('aria-labelledby', 'alpine-combobox-button-1'))
  749. // .should(notHaveAttribute('aria-activedescendant'))
  750. // .should(haveAttribute('tabindex', '0'))
  751. // .should(haveAttribute('aria-activedescendant', 'alpine-combobox-option-1'))
  752. // get('[option="1"]')
  753. // .should(haveAttribute('role', 'option'))
  754. // .should(haveAttribute('id', 'alpine-combobox-option-1'))
  755. // .should(haveAttribute('tabindex', '-1'))
  756. // .should(haveAttribute('aria-selected', 'false'))
  757. // get('[option="2"]')
  758. // .should(haveAttribute('role', 'option'))
  759. // .should(haveAttribute('id', 'alpine-combobox-option-2'))
  760. // .should(haveAttribute('tabindex', '-1'))
  761. // .should(haveAttribute('aria-selected', 'false'))
  762. // get('[options]')
  763. // .type('{downarrow}')
  764. // .should(haveAttribute('aria-activedescendant', 'alpine-combobox-option-2'))
  765. // get('[option="2"]')
  766. // .click()
  767. // .should(haveAttribute('aria-selected', 'true'))
  768. // },
  769. // )
  770. // test('"static" prop',
  771. // [html`
  772. // <div
  773. // x-data="{ active: null, show: false, people: [
  774. // { id: 1, name: 'Wade Cooper' },
  775. // { id: 2, name: 'Arlene Mccoy' },
  776. // { id: 3, name: 'Devon Webb' },
  777. // { id: 4, name: 'Tom Cook' },
  778. // { id: 5, name: 'Tanya Fox', disabled: true },
  779. // { id: 6, name: 'Hellen Schmidt' },
  780. // { id: 7, name: 'Caroline Schultz' },
  781. // { id: 8, name: 'Mason Heaney' },
  782. // { id: 9, name: 'Claudie Smitham' },
  783. // { id: 10, name: 'Emil Schaefer' },
  784. // ]}"
  785. // x-combobox
  786. // x-model="active"
  787. // >
  788. // <label x-combobox:label>Assigned to</label>
  789. // <button normal-toggle x-combobox:button x-text="active ? active.name : 'Select Person'"></button>
  790. // <button real-toggle @click="show = ! show">Toggle</button>
  791. // <ul x-combobox:options x-show="show" static>
  792. // <template x-for="person in people" :key="person.id">
  793. // <li
  794. // :option="person.id"
  795. // x-combobox:option
  796. // :value="person"
  797. // :disabled="person.disabled"
  798. // >
  799. // <span x-text="person.name"></span>
  800. // </li>
  801. // </template>
  802. // </ul>
  803. // </div>
  804. // `],
  805. // ({ get }) => {
  806. // get('ul').should(notBeVisible())
  807. // get('[normal-toggle]')
  808. // .should(haveText('Select Person'))
  809. // .click()
  810. // get('ul').should(notBeVisible())
  811. // get('[real-toggle]').click()
  812. // get('ul').should(beVisible())
  813. // get('[option="2"]').click()
  814. // get('ul').should(beVisible())
  815. // get('[normal-toggle]').should(haveText('Arlene Mccoy'))
  816. // },
  817. // )